Esempio n. 1
0
File: views.py Progetto: hmpf/nav
def calendar(request, year=None, month=None):
    # If the form was used to get here, redirect to the appropriate page
    if "year" in request.GET and "month" in request.GET:
        return redirect(
            "maintenance-calendar",
            year=request.GET.get("year"),
            month=request.GET.get("month"),
        )

    heading = "Maintenance schedule"
    try:
        year = int(year)
        month = int(month)
        this_month_start = date(year, month, 1)
    except (TypeError, ValueError):
        year = date.today().year
        month = date.today().month
        this_month_start = date(year, month, 1)

    next_month = month + 1
    next_year = year
    if next_month > 12:
        next_year = year + 1
        next_month = 1

    prev_month = month - 1
    prev_year = year
    if prev_month < 1:
        prev_year = year - 1
        prev_month = 12

    prev_month_start = date(prev_year, prev_month, 1)
    next_month_start = date(next_year, next_month, 1)
    tasks = (MaintenanceTask.objects.filter(
        start_time__lt=next_month_start,
        end_time__gt=this_month_start).exclude(
            state=MaintenanceTask.STATE_CANCELED).order_by('start_time'))
    cal = MaintenanceCalendar(tasks).formatmonth(year, month)
    return render(
        request,
        'maintenance/calendar.html',
        {
            'active': {
                'calendar': True
            },
            'navpath': NAVPATH,
            'title': TITLE,
            'heading': heading,
            'calendar': mark_safe(cal),
            'prev_month': prev_month_start,
            'this_month': this_month_start,
            'next_month': next_month_start,
            'curr_month': datetime.today(),
        },
    )
Esempio n. 2
0
def calendar(request, year=None, month=None):
    heading = "Maintenance schedule"
    try:
        year = int(request.GET.get('year'))
        month = int(request.GET.get('month'))
        this_month_start = date(year, month, 1)
    except (TypeError, ValueError):
        year = date.today().year
        month = date.today().month
        this_month_start = date(year, month, 1)

    next_month = month + 1
    next_year = year
    if next_month > 12:
        next_year = year + 1
        next_month = 1

    prev_month = month - 1
    prev_year = year
    if prev_month < 1:
        prev_year = year - 1
        prev_month = 12

    prev_month_start = date(prev_year, prev_month, 1)
    next_month_start = date(next_year, next_month, 1)
    tasks = MaintenanceTask.objects.filter(
        start_time__lt=next_month_start,
        end_time__gt=this_month_start
    ).exclude(state=MaintenanceTask.STATE_CANCELED).order_by('start_time')
    cal = MaintenanceCalendar(tasks).formatmonth(year, month)
    return render_to_response(
        'maintenance/calendar.html',
        {
            'active': {'calendar': True},
            'navpath': NAVPATH,
            'title': TITLE,
            'heading': heading,
            'calendar': mark_safe(cal),
            'prev_month': prev_month_start,
            'this_month': this_month_start,
            'next_month': next_month_start,
            'curr_month': datetime.today(),
        },
        RequestContext(request)
    )