def category_view request slug on_page page_divisor page try type just

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def category_view(request, slug, on_page=page_divisor, page=1):
try:
#: :type : just_main.models.Menu
selected_category = Menu.objects.defer('date_created', 'date_updated').get(slug=slug)
except Menu.DoesNotExist:
raise Http404
if selected_category.get_level() == 2:
vertical_menu_tree = selected_category.get_siblings(include_self=True)
else:
vertical_menu_tree = selected_category.get_descendants(include_self=False)
wares_list = selected_category.get_wares().order_by('-' + get_sort_by_choices('ware').values()[0])
try:
max_price = max(w.price for w in wares_list)
min_price = min(w.price for w in wares_list)
except ValueError:
max_price = 0
min_price = 0
paginator = Paginator(wares_list, on_page)
wares_list = paginator.page(page)
template = loader.get_template('public_html/category.html')
context = RequestContext(request, {
'this_menu': selected_category,
'this_tree': vertical_menu_tree,
'wares_list': wares_list,
'min_price': min_price,
'max_price': max_price,
'per_page_variants': per_page_iterator(wares_list.paginator.count)
})
return HttpResponse(template.render(context))