You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.2 KiB

# -*- coding: utf-8 -*-
from collections import OrderedDict
from django.shortcuts import get_object_or_404, render
from project.teasers.models import get_teasers_for_path
from .models import Fond
def npfs_all(request):
"""Âñå ôîíäû."""
_fond_list = Fond.objects.all().order_by('name')
fonds = OrderedDict() # ãðóïïèðîâêà ôîíäîâ ïî ïåðâîìó ñèìâîëó íàçâàíèÿ
_fonds_digit = OrderedDict() # íàçâàíèÿ, íà÷èíàþùèåñÿ ñ öèôð, ÷òîáû âûâîäèòü èõ â ñàìîì êîíöå
for _fond in _fond_list:
_char = _fond.name.strip()[0]
if _char.isdigit():
try:
_fonds_digit[_char].append(_fond)
except KeyError:
_fonds_digit[_char] = [_fond]
else:
try:
fonds[_char].append(_fond)
except KeyError:
fonds[_char] = [_fond]
fonds.update(_fonds_digit)
teasers = get_teasers_for_path(request.path)
return render(request, 'npfs/npfs_all.html', {'fonds': fonds, 'teasers': teasers})
def npfs_fond(request, slug):
"""Ñòðàíèöà ôîíäà."""
fond = get_object_or_404(Fond, slug__iexact=slug)
teasers = get_teasers_for_path(request.path)
return render(request, 'npfs/npfs_fond.html', {'fond': fond, 'teasers': teasers})