def prep_list_view(request, group='all'): """ Prepares the product list view """ title = _("Products") search_hint = "products" all_products = Product.objects.all() categories = ProductCategory.objects.all() if group == 'all': group = ProductCategory(title=_('All'), slug='all') elif group == 'None': group = ProductCategory(title=_('None'), slug='none') all_products = all_products.filter(categories=None) else: group = categories.get(slug=group) all_products = group.get_products() if request.method == 'POST': form = ProductSearchForm(request.POST) if form.is_valid(): fdata = form.cleaned_data description = fdata.get('description') if description: all_products = all_products.filter(description__icontains=description) title = fdata.get('title') if title: all_products = all_products.filter(title__icontains=title) code = fdata.get('code') if code: all_products = all_products.filter(code__icontains=code) tag = fdata.get('tag') if tag: tag = tag.tag title += u" / %s" % tag all_products = all_products.filter(tags__tag=tag) location = fdata.get('location') if location: all_products = all_products.filter(inventory__location=location) else: form = ProductSearchForm() title += u" / %s" % group.title page = request.GET.get("page") products = paginate(all_products.distinct(), page, 25) return locals()
def prep_list_view(request, group='all'): """ Prepares the product list view """ title = _("Products") all_products = Product.objects.all() categories = ProductCategory.objects.all() if group == 'all': group = ProductCategory(title=_('All'), slug='all') else: group = categories.get(slug=group) all_products = group.get_products() if request.method == 'POST': form = ProductSearchForm(request.POST) if form.is_valid(): fdata = form.cleaned_data description = fdata.get('description') if description: all_products = all_products.filter(description__icontains=description) title = fdata.get('title') if title: all_products = all_products.filter(title__icontains=title) code = fdata.get('code') if code: all_products = all_products.filter(code__icontains=code) tag = fdata.get('tag') if tag: tag = tag.tag title += u" / %s" % tag all_products = all_products.filter(tags__tag=tag) else: form = ProductSearchForm() title += u" / %s" % group.title page = request.GET.get("page") paginator = Paginator(all_products.distinct(), 25) try: products = paginator.page(page) except PageNotAnInteger: products = paginator.page(1) except EmptyPage: products = paginator.page(paginator.num_pages) return locals()