Source

django-swingcms / swingcms / agenda / views.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import datetime

from django.template import RequestContext
from django.shortcuts import render_to_response
from django.utils.translation import ugettext as _

import settings
from custodian.code import get_user
from cms.models import Event
from cms.views import LAYOUTS
from agenda.code import WEEK_DAYS, get_agenda_as_calendar, get_agenda_as_list



def agenda(request, mode='as_calendar'):
    """
    Build two type of calendar structures.
    """
    current_path = request.get_full_path()
    events = Event.objects.filter(status='public')
    now = datetime.datetime.now()

    if mode == 'as_calendar':
        agenda_as_calendar = get_agenda_as_calendar(events, now)
        obj_template_path = "agenda/agenda_as_calendar.html"
    elif mode == 'as_list':
        agenda_as_list = get_agenda_as_list(events, now)
        obj_template_path = "agenda/agenda_as_list.html"

    days = WEEK_DAYS
    specific_js_files = ("cms/js/tipTipv13/jquery.tipTip.minified.js",)
    specific_css_files = ("cms/js/tipTipv13/tipTip.css",)

    # prepare layout
    user = get_user(request)
    layout = LAYOUTS['clean']
    layout.actualize(request=request,
                     user=user,
                     language=request.LANGUAGE_CODE,
                     caching=user.is_anonymous() and settings.CACHE_ACTIVE,
                     check_view_perms=True,
                     current_path=current_path,
                     here=_('agenda'))

    return render_to_response(layout.template_path, locals(), context_instance=RequestContext(request))