Exemplo n.º 1
0
def get_open_close(day):
    """Return datetime objects representing open and close for a day rounded
    down to the hour.

    If the lab is closed all day (e.g. holiday), just return our weekday hours.
    """
    d = Day.from_date(day)
    regular_hours = display_hours()

    if not d.closed_all_day:
        start = datetime(day.year, day.month, day.day, min(h.open.hour for h in d.hours))
        end = datetime(day.year, day.month, day.day, max(h.close.hour for h in d.hours))
    else:
        start = datetime(
            day.year,
            day.month,
            day.day,
            min(h.open.hour for hour_list in regular_hours.values() for h in hour_list),
        )
        end = datetime(
            day.year,
            day.month,
            day.day,
            max(h.close.hour for hour_list in regular_hours.values() for h in hour_list),
        )

    return start, end
Exemplo n.º 2
0
def lab(doc, request):
    return render(
        request,
        'docs/lab.html',
        {
            'title': doc.title,
            'description': (
                'The Open Computing Facility computer lab is a '
                'free and open-source computer lab located on the '
                'UC Berkeley campus, maintained by OCF volunteers.'
            ),
            'hours_this_week': [
                Day.from_date(date.today() + timedelta(days=i))
                for i in range(7)
            ],
            'regular_hours': display_hours(),
            # Format dates to look like "month day, year" but with non-breaking
            # spaces (\xa0) instead of spaces so that the date does not get
            # broken up across lines:
            # https://docs.djangoproject.com/en/2.0/ref/templates/builtins/#date
            'holiday_format': 'M\xa0j,\xa0o',
            # Only select current and future holidays (any that have not finished fully)
            'holidays': [holiday for holiday in HOLIDAYS if holiday[1] >= date.today()],
            'SUNDAY': Day.SUNDAY,
            'MONDAY': Day.MONDAY,
            'TUESDAY': Day.TUESDAY,
            'WEDNESDAY': Day.WEDNESDAY,
            'THURSDAY': Day.THURSDAY,
            'FRIDAY': Day.FRIDAY,
            'SATURDAY': Day.SATURDAY,
        },
    )
Exemplo n.º 3
0
Arquivo: lab.py Projeto: wilswu/ocfweb
def lab(doc, request):
    return render(
        request,
        'docs/lab.html',
        {
            'title':
            doc.title,
            'description':
            ('The Open Computing Facility computer lab is a '
             'free and open-source computer lab located on the '
             'UC Berkeley campus, maintained by OCF volunteers.'),
            'hours_this_week': [
                Day.from_date(date.today() + timedelta(days=i))
                for i in range(7)
            ],
            'regular_hours':
            display_hours(),
            'holidays':
            list(get_holidays()),
            'semester':
            get_semester(),
            'SUNDAY':
            Day.SUNDAY,
            'MONDAY':
            Day.MONDAY,
            'TUESDAY':
            Day.TUESDAY,
            'WEDNESDAY':
            Day.WEDNESDAY,
            'THURSDAY':
            Day.THURSDAY,
            'FRIDAY':
            Day.FRIDAY,
            'SATURDAY':
            Day.SATURDAY,
        },
    )