Source

Zenwalk-fr / modulo / actualite / views.py

# -*- coding: utf-8 -*-
from django.template import RequestContext
from django.shortcuts import render_to_response
from django.http import Http404
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from modulo.galerie.models import Photo

import multilingual
from django.utils.translation import ugettext_lazy as _

def actualite(request):
    actus = request.rubrique.actu.exclude(slug__exact='').exclude(active=False).order_by('dateModification').reverse()

    paginator = Paginator(actus, 5) # Show 5 actus per page

    # Make sure page request is an int. If not, deliver first page.
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    # If page request (9999) is out of range, deliver last page of results.
    try:
        actus = paginator.page(page)
    except (EmptyPage, InvalidPage):
        actus = paginator.page(paginator.num_pages)

    photos = Photo.objects.all()
        
    return render_to_response("actualite/actualite.html",
                              {'actus': actus,
                               'photos': photos,
                               'rubrique': request.rubrique},
                              context_instance=RequestContext(request))

def afficherUneNews(request):
    actu = request.rubrique.actu.filter(pk=request.object_id)

    if not actu:
        raise Http404
    else:
        return render_to_response('actualite/affichageActualite.html',
                                  {'actu': actu[0],
                                   'rubrique': request.rubrique},
                                  context_instance=RequestContext(request))