Statistics
| Branch: | Tag: | Revision:

root / cloudcmsblog / views.py @ c1468bcc

History | View | Annotate | Download (1.3 kB)

1
from django.conf import settings
2
from django.views.generic.simple import direct_to_template
3
from django.http import HttpResponseRedirect, Http404
4

    
5
from cloudcms.models import Application
6
from cloudcmsblog.models import Entry, Category, CategoryTranslation
7

    
8
def index(request):
9
    """
10
    Redirecto to first category found entries archive
11
    """
12
    categories = Category.objects.filter(display_on_menu=True)
13
    if categories.exists() == 0:
14
        raise Http404
15

    
16
    return HttpResponseRedirect(categories[0].get_absolute_url())
17

    
18
def archive(request, category):
19
    """
20
    Display entries list
21
    """
22
    app = Application.current()
23
    category = CategoryTranslation.objects.get(slug=category).parent
24
    entries = category.blogentries.all()
25
    return direct_to_template(request,
26
            "cloudcmsblog/archive.html", {'entries': entries,
27
                'ENTRIES_PER_PAGE': getattr(settings,
28
                    'CLOUDCMSBLOG_ENTRIES_PER_PAGE', 2)})
29

    
30
def detail(request, year, month, day, slug):
31
    """
32
    Display detailed blog entry.
33
    """
34
    entry = Entry.objects.get(published_on__year=year,
35
            published_on__month=month, published_on__day=day,
36
            slug=slug, is_active=True)
37
    return direct_to_template(request,
38
            "cloudcmsblog/detail.html", {'entry': entry})