Source

django-basic-events / events / views.py

Full commit
from django.db import transaction
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext

from events import models


def list_events_for_category(request, category_slug):
    current_category = get_object_or_404(models.EventCategory, slug=category_slug)
    categories = models.EventCategory.objects.all()
    upcoming_events = models.Event.published.upcoming()
    upcoming_events = upcoming_events.filter(categories=current_category)
    upcoming_events = upcoming_events.order_by('-begin_date')
    previous_events = models.Event.published.previous().all()
    previous_events = previous_events.filter(categories=current_category)
    previous_events = previous_events.order_by('-begin_date')
    
    return render_to_response('events/category.html',
        {
            'upcoming_events': upcoming_events,
            'previous_events': previous_events,
            'category': current_category,
            'categories' : categories,
        },
        context_instance=RequestContext(request),
    )


def list_events(request):
    upcoming_events = \
        models.Event.published.upcoming().order_by('-begin_date')
    previous_events = \
        models.Event.published.previous().order_by('-begin_date')
    return render_to_response('events/list.html',  
        {
            'upcoming_events': upcoming_events,
            'previous_events': previous_events,
            'event_categories': models.EventCategory.objects.all(),
        },
        context_instance=RequestContext(request),
    )
    
    
def view_event(request, year, month, event_slug):
    event = get_object_or_404(
        models.Event,
        begin_date__year=year,
        begin_date__month=month,
        slug=event_slug,
        is_published=True,
    )

    return render_to_response('events/view.html',
        {
            'event': event,
            'ordered_attachments': event.attachments.order_by('order'),
        },
        context_instance=RequestContext(request),
    )