06/15 Phase 4 + 5 codes
This commit is contained in:
@@ -53,29 +53,41 @@ def browse():
|
||||
condition=condition)
|
||||
base = svc.order_default(base)
|
||||
|
||||
# promoted listings pinned to top when keyword searched
|
||||
from app.services.ads import promoted_listings as get_promoted
|
||||
promoted = get_promoted(q) if q else []
|
||||
|
||||
near = None
|
||||
if zip_code and radius:
|
||||
geo = geocode_zip(zip_code)
|
||||
if geo:
|
||||
lat, lng = geo[0], geo[1]
|
||||
results = svc.search_with_radius(base, lat, lng, radius)
|
||||
# paginate manually for radius results
|
||||
total = len(results)
|
||||
start = (page - 1) * PER_PAGE
|
||||
items = results[start:start + PER_PAGE]
|
||||
near = {"zip": zip_code, "radius": radius, "total": total}
|
||||
# prepend promoted (no distance)
|
||||
promoted_pairs = [(l, None) for l in promoted]
|
||||
promoted_ids = {l.id for l in promoted}
|
||||
items = promoted_pairs + [(l, d) for l, d in items
|
||||
if l.id not in promoted_ids]
|
||||
return render_template("listings/browse.html",
|
||||
results=items, near=near,
|
||||
categories=_category_choices(),
|
||||
filters=request.args, page=page,
|
||||
has_next=start + PER_PAGE < total)
|
||||
has_next=start + PER_PAGE < total,
|
||||
promoted_ids={l.id for l in promoted})
|
||||
flash(_("ZIP not found; showing all results."), "warning")
|
||||
|
||||
pagination = base.paginate(page=page, per_page=PER_PAGE, error_out=False)
|
||||
results = [(l, None) for l in pagination.items]
|
||||
promoted_ids = {l.id for l in promoted}
|
||||
organic = [(l, None) for l in pagination.items if l.id not in promoted_ids]
|
||||
results = [(l, None) for l in promoted] + organic
|
||||
return render_template("listings/browse.html", results=results, near=None,
|
||||
categories=_category_choices(), filters=request.args,
|
||||
page=page, has_next=pagination.has_next)
|
||||
page=page, has_next=pagination.has_next,
|
||||
promoted_ids={l.id for l in promoted})
|
||||
|
||||
|
||||
# --- detail ---
|
||||
|
||||
Reference in New Issue
Block a user