summaryrefslogtreecommitdiff
path: root/cms/views.py
blob: fc1439aadf3e533df7283eb7d8e4310e133f93e4 (plain)
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
# Create your views here.
from django.forms import model_to_dict
from django.http import Http404
from django.shortcuts import render

from cms.models import Page, Nav, SubNav


def home(request, permalink=''):
    if permalink == '':
        permalink = 'home'
    page = Page.objects.filter(permalink=permalink, active=True)
    if page.exists():
        page = page.first()
    else:
        raise Http404("The requested page does not exists")
    nav_objs = Nav.objects.filter(active=True).order_by('-position')

    navs = []

    for nav in nav_objs:
        nav_obj = model_to_dict(nav)
        nav_obj['subnavs'] = nav.subnav_set.filter(
            active=True).order_by('position')
        navs.insert(-1, nav_obj)

    return render(
        request, 'cms_base.html', {'page': page, 'navs': navs}
    )