Пример #1
0
def render_computers_view(request):
    """ Renders computer section. """

    data = {}

    brand = request.GET.get("brand", None)
    cond = request.GET.get("condition", None)
    price = request.GET.get("price", None)
    loc = request.COOKIES.get("ads_location", None)
    items = Computer.objects.filter(published=True).order_by("-pub_date")

    if brand:
        items = items.filter(brand=brand)
    if cond:
        items = items.filter(condition=cond)
    if price:
        minp, maxp = currency.process_price(price)
        items = items.filter(price__range=[minp, maxp])
    else:
        minp = 15000
        maxp = 30000

    if loc != "all" and loc is not None:
        items = items.filter(location=loc)

    data["sortform"] = forms.ComputerSortingForm(request.GET or None)

    for field in Computer._meta.get_all_field_names():
        data["sortform"].errors[field] = ""

    cache_key = "comps_feat_items_%s" % loc
    data["featured_items"] = cache.get(cache_key)

    if not data["featured_items"]:
        data["featured_items"] = Computer.get_featured(loc)
        cache.set(cache_key, data["featured_items"], 900)

    if brand or cond or price:
        data["items"] = list(chain(items.filter(featured=True), items.filter(featured=False)))
    else:
        data.update(
            {
                "cheap_items": Computer.get_cheap(minp, loc)[:6],
                "average_items": Computer.get_average(minp, maxp, loc)[:6],
                "expensive_items": Computer.get_expensive(maxp, loc)[:6],
            }
        )

    data.update(
        {
            "min_price": minp,
            "max_price": maxp,
            "sortid": "comps",
            "title": Computer._meta.verbose_name_plural,
            "cache_time": settings.CACHE_TIME,
            "url": request.get_full_path(),
        }
    )

    return render(request, TMPL, data)
Пример #2
0
def render_automobiles_view(request):
    """ Renders automobile section. """

    data = {}

    brand = request.GET.get('brand', None)
    cond  = request.GET.get('condition', None)
    body  = request.GET.get('body_type', None)
    trans = request.GET.get('transmission', None)
    year  = request.GET.get('year', None)
    price = request.GET.get('price', None)
    loc   = request.COOKIES.get('ads_location', None)
    items = Automobile.objects.filter(published=True).order_by('-pub_date')

    if brand:
        items = items.filter(brand=brand)
    if cond:
        items = items.filter(condition=cond)
    if body:
        items = items.filter(body_type=body)
    if trans:
        items = items.filter(transmission=trans)
    if year:
        miny, maxy = year.split(' - ')[0], year.split(' - ')[1]
        items = items.filter(year__range=[miny, maxy])
    if price:
        minp, maxp = currency.process_price(price, 'USD')
        items = items.filter(price__range=[minp, maxp])
        data['min_price'] = currency.convert_currency(minp, 'USD')
        data['max_price'] = currency.convert_currency(maxp, 'USD')
    else:
        data['min_price'] = 15000
        data['max_price'] = 30000

    if loc != 'all' and loc is not None:
        items = items.filter(location=loc)

    data['sortform'] = forms.AutomobileSortingForm(request.GET or None)
    
    for field in Automobile._meta.get_all_field_names():
        data['sortform'].errors[field] = ''

    cache_key = 'autos_feat_items_%s' % loc
    data['featured_items'] = cache.get(cache_key)

    if not data['featured_items']:
        data['featured_items'] = Automobile.get_featured(loc)
        cache.set(cache_key, data['featured_items'], 900)
    
    data.update({
        'USD': True, 
        'sortid': 'autos',
        'title': Automobile._meta.verbose_name_plural,
        'cache_time': settings.CACHE_TIME,
        'url': request.get_full_path(),
        'items': list(chain(items.filter(featured=True), 
                            items.filter(featured=False)))
    })

    return render(request, TMPL, data)
Пример #3
0
def render_plots_view(request):
    """ Renders plot section. """

    data = {}

    real  = request.GET.get('is_realtor', None)
    cond  = request.GET.get('condition', None)
    addr  = request.GET.get('address', None)
    area  = request.GET.get('area', None)
    price = request.GET.get('price', None)
    loc   = request.COOKIES.get('ads_location', None)
    items = Plot.objects.filter(published=True).order_by('-pub_date')

    if real:
        items = items.filter(is_realtor=real)
    if cond:
        items = items.filter(condition=cond)
    if addr:
        items = items.filter(address=addr)
    if area:
        items = items.filter(area=area)
    if price:
        minp, maxp = currency.process_price(price, 'USD')
        items = items.filter(price__range=[minp, maxp])
        data['min_price'] = currency.convert_currency(minp, 'USD')
        data['max_price'] = currency.convert_currency(maxp, 'USD')
    else:
        data['min_price'] = 5000
        data['max_price'] = 40000

    if loc != 'all' and loc is not None:
        items = items.filter(location=loc)

    data['sortform'] = forms.PlotSortingForm(request.GET or None)
    
    for field in Plot._meta.get_all_field_names():
        data['sortform'].errors[field] = ''

    cache_key = 'plots_feat_items_%s' % loc
    data['featured_items'] = cache.get(cache_key)

    if not data['featured_items']:
        data['featured_items'] = Plot.get_featured(loc)
        cache.set(cache_key, data['featured_items'], 900)
    
    data.update({
        'USD': True, 
        'no_rooms': True,
        'plot': True,
        'sortid': 'plots',
        'sortclass': 'scfilter-2rows',
        'title': Plot._meta.verbose_name_plural,
        'cache_time': settings.CACHE_TIME,
        'url': request.get_full_path(),
        'items': list(chain(items.filter(featured=True), 
                            items.filter(featured=False)))
    })

    return render(request, TMPL, data)
Пример #4
0
def render_medicines_view(request):
    """ Renders medicine section. """

    data = {}

    cond  = request.GET.get('condition', None)
    price = request.GET.get('price', None)
    loc   = request.COOKIES.get('ads_location', None)
    items = Medicine.objects.filter(published=True).order_by('-pub_date')

    if cond:
        items = items.filter(condition=cond)
    if price:
        minp, maxp = currency.process_price(price)
        items = items.filter(price__range=[minp, maxp])
    else:
        minp = 0
        maxp = 8000

    if loc != 'all' and loc is not None:
        items = items.filter(location=loc)

    data['sortform'] = forms.MedicineSortingForm(request.GET or None)
    
    for field in Medicine._meta.get_all_field_names():
        data['sortform'].errors[field] = ''

    cache_key = 'meds_feat_items_%s' % loc
    data['featured_items'] = cache.get(cache_key)

    if not data['featured_items']:
        data['featured_items'] = Medicine.get_featured(loc)
        cache.set(cache_key, data['featured_items'], 900)

    if cond or price:
        data['items'] = list(chain(items.filter(featured=True), 
                                   items.filter(featured=False)))
    else:
        data.update({
            'cheap_items': Medicine.get_cheap(minp, loc)[:6],
            'average_items': Medicine.get_average(minp, maxp, loc)[:6],
            'expensive_items': Medicine.get_expensive(maxp, loc)[:6]
        })
    
    data.update({
        'min_price': minp,
        'max_price': maxp,
        'sortid': 'meds',
        'sortclass': 'scfilter-2rows',
        'title': Medicine._meta.verbose_name_plural,
        'cache_time': settings.CACHE_TIME,
        'url': request.get_full_path()
    })

    return render(request, TMPL, data)
Пример #5
0
def render_scooters_view(request):
    """ Renders scooter section. """

    data = {}

    brand = request.GET.get('brand', None)
    cond  = request.GET.get('condition', None)
    year  = request.GET.get('year', None)
    price = request.GET.get('price', None)
    loc   = request.COOKIES.get('ads_location', None)
    items = Scooter.objects.filter(published=True).order_by('-pub_date')

    if brand:
        items = items.filter(brand=brand)
    if cond:
        items = items.filter(condition=cond)
    if year:
        miny, maxy = year.split(' - ')[0], year.split(' - ')[1]
        items = items.filter(year__range=[miny, maxy])
    if price:
        minp, maxp = currency.process_price(price)
        items = items.filter(price__range=[minp, maxp])
    else:
        minp = 9000
        maxp = 35000

    if loc != 'all' and loc is not None:
        items = items.filter(location=loc)

    data['sortform'] = forms.ScooterSortingForm(request.GET or None)
    
    for field in Scooter._meta.get_all_field_names():
        data['sortform'].errors[field] = ''

    cache_key = 'scooters_feat_items_%s' % loc
    data['featured_items'] = cache.get(cache_key)

    if not data['featured_items']:
        data['featured_items'] = Scooter.get_featured(loc)
        cache.set(cache_key, data['featured_items'], 900)
    
    data.update({
        'min_price': minp,
        'max_price': maxp,
        'sortid': 'scooters',
        'sortclass': 'scfilter-2rows',
        'title': Scooter._meta.verbose_name_plural,
        'cache_time': settings.CACHE_TIME,
        'url': request.get_full_path(),
        'items': list(chain(items.filter(featured=True), 
                            items.filter(featured=False)))
    })

    return render(request, TMPL, data)
Пример #6
0
def render_otheritems_view(request):
    """ Renders other item section. """
    
    data = {}

    price = request.GET.get('price', None)
    loc   = request.COOKIES.get('ads_location', None)
    items = OtherItem.objects.filter(published=True).order_by('-pub_date')

    if price:
        minp, maxp = currency.process_price(price)
        items = items.filter(price__range=[minp, maxp])
    else:
        minp = 0
        maxp = 7000

    if loc != 'all' and loc is not None:
        items = items.filter(location=loc)

    data['sortform'] = forms.OtherItemSortingForm(request.GET or None)
    
    for field in OtherItem._meta.get_all_field_names():
        data['sortform'].errors[field] = ''

    cache_key = 'otheritems_feat_items_%s' % loc
    data['featured_items'] = cache.get(cache_key)

    if not data['featured_items']:
        data['featured_items'] = OtherItem.get_featured(loc)
        cache.set(cache_key, data['featured_items'], 900)

    if price:
        data['items'] = list(chain(items.filter(featured=True), 
                                   items.filter(featured=False)))
    else:
        newest = OtherItem.get_newest()
        data['newest_items'] = list(chain(newest.filter(featured=True), 
                                          newest.filter(featured=False)))
    
    data.update({
        'max_price': maxp,
        'min_price': minp,
        'sortid': 'otheritems',
        'sortclass': 'scfilter-2rows',
        'title': OtherItem._meta.verbose_name_plural,
        'cache_time': settings.CACHE_TIME,
        'url': request.get_full_path()
    })

    return render(request, TMPL, data)
Пример #7
0
def render_lubricants_view(request):
    """ Renders lubricant section. """

    data = {}

    cond  = request.GET.get('condition', None)
    price = request.GET.get('price', None)
    loc   = request.COOKIES.get('ads_location', None)
    items = Lubricant.objects.filter(published=True).order_by('-pub_date')

    if cond:
        items = items.filter(condition=cond)
    if price:
        minp, maxp = currency.process_price(price)
        items = items.filter(price__range=[minp, maxp])
    else:
        minp = 0
        maxp = 10000

    if loc != 'all' and loc is not None:
        items = items.filter(location=loc)

    data['sortform'] = forms.LubricantSortingForm(request.GET or None)
    
    for field in Lubricant._meta.get_all_field_names():
        data['sortform'].errors[field] = ''

    cache_key = 'lubrics_feat_items_%s' % loc
    data['featured_items'] = cache.get(cache_key)

    if not data['featured_items']:
        data['featured_items'] = Lubricant.get_featured(loc)
        cache.set(cache_key, data['featured_items'], 900)
    
    data.update({
        'min_price': minp,
        'max_price': maxp,
        'sortid': 'lubrics',
        'sortclass': 'scfilter-1row',
        'title': Lubricant._meta.verbose_name_plural,
        'cache_time': settings.CACHE_TIME,
        'url': request.get_full_path(),
        'items': list(chain(items.filter(featured=True), 
                            items.filter(featured=False)))
    })

    return render(request, TMPL, data)