示例#1
0
def week_view(request, response_format='html'):
    "Week view - each slot represents an hour"

    events = Object.filter_by_request(request, Event.objects)

    date_current = now = datetime.now()
    istoday = True

    gotoform = GoToDateForm(now, request.GET)
    if request.GET:
        if 'date_year' in request.GET and 'date_month' in request.GET and 'date_day' in request.GET:
            try:
                day = int(request.GET['date_day'])
                year = int(request.GET['date_year'])
                month = int(request.GET['date_month'])
                if year >= 1900 and 1 <= month <= 12 and 1 <= day <= 31:
                    date_current = datetime(year, month, day)
                    istoday = date_current == now
            except Exception:
                pass
        if gotoform.is_valid() and gotoform.cleaned_data['goto']:
            date_current = gotoform.cleaned_data['goto']
            istoday = date_current == now
            date_current = now = datetime(date_current.year,
                                          date_current.month, date_current.day)

    date_previous = date_current - relativedelta(weeks=+1)
    date_next = date_current + relativedelta(weeks=+1)

    weeks = calendar.Calendar().monthdatescalendar(date_current.year,
                                                   date_current.month)
    current_week = []
    for week in weeks:
        if date_current.date() in week:
            current_week = week
            break

    wrapped_events = EventCollection(events, START_HOUR, END_HOUR)
    wrapped_events.collect_events(request)

    hours = range(START_HOUR, END_HOUR + 1)

    return render_to_response('events/week_view', {
        'events': wrapped_events,
        'week': current_week,
        'start_date': current_week[0],
        'end_date': current_week[6],
        'date_previous': date_previous,
        'date_next': date_next,
        'date_current': date_current,
        'gotoform': gotoform.as_ul(),
        'istoday': istoday,
        'hours': hours,
        'now': now
    },
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#2
0
def month_view(request, response_format='html'):
    "Month view - each cell represents a day"

    events = Object.filter_by_request(request, Event.objects)

    date_current = now = datetime.now()
    istoday = True

    gotoform = GoToDateForm(now, request.GET)
    if request.GET:
        if 'date_year' in request.GET and 'date_month' in request.GET:
            try:
                year = int(request.GET['date_year'])
                month = int(request.GET['date_month'])
                if year >= 1900 and 1 <= month <= 12:
                    date_current = datetime(year, month, 1)
                    istoday = date_current == now
            except Exception:
                pass
        if gotoform.is_valid() and gotoform.cleaned_data['goto']:
            date_current = gotoform.cleaned_data['goto']
            istoday = date_current == now
            now = datetime(date_current.year, date_current.month,
                           date_current.day)

    dates = calendar.Calendar().monthdatescalendar(date_current.year,
                                                   date_current.month)
    date_previous = date_current - relativedelta(months=+1)
    date_next = date_current + relativedelta(months=+1)

    wrapped_events = EventCollection(events)
    wrapped_events.collect_events(request)

    return render_to_response('events/month_view', {
        'events': wrapped_events,
        'dates': dates,
        'date_previous': date_previous,
        'date_next': date_next,
        'date_current': date_current,
        'gotoform': gotoform.as_ul(),
        'istoday': istoday,
        'now': now
    },
                              context_instance=RequestContext(request),
                              response_format=response_format)