Esempio 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)

    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 h in REGULAR_HOURS[None]),
        )
        end = datetime(
            day.year,
            day.month,
            day.day,
            max(h.close.hour for h in REGULAR_HOURS[None]),
        )

    return start, end
Esempio n. 2
0
def lab(doc, request):
    return render_to_response(
        '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': REGULAR_HOURS,
            'holidays': list(get_holidays()),
            'SUNDAY': Day.SUNDAY,
            'MONDAY': Day.MONDAY,
            'TUESDAY': Day.TUESDAY,
            'WEDNESDAY': Day.WEDNESDAY,
            'THURSDAY': Day.THURSDAY,
            'FRIDAY': Day.FRIDAY,
            'SATURDAY': Day.SATURDAY,
        },
        context_instance=RequestContext(request),
    )
Esempio n. 3
0
def home(request):
    hours = [Day.from_date(date.today() + timedelta(days=i)) for i in range(3)]
    return render(
        request,
        'main/home.html',
        {
            'fulltitle':
            'Open Computing Facility at UC Berkeley',
            'description':
            ('The Open Computing Facility is an all-volunteer student '
             'organization dedicated to free and open-source computing for all UC '
             'Berkeley students.'),
            'staff_hours':
            get_staff_hours(),
            'hours':
            hours,
            'announcements':
            sorted(
                get_blog_posts() + list(announcements),
                key=attrgetter('datetime'),
                reverse=True,
            )[:2],
            'today':
            hours[0],
            'lab_status':
            get_lab_status(),
        },
    )
Esempio n. 4
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':
            REGULAR_HOURS,
            'holidays':
            list(get_holidays()),
            'SUNDAY':
            Day.SUNDAY,
            'MONDAY':
            Day.MONDAY,
            'TUESDAY':
            Day.TUESDAY,
            'WEDNESDAY':
            Day.WEDNESDAY,
            'THURSDAY':
            Day.THURSDAY,
            'FRIDAY':
            Day.FRIDAY,
            'SATURDAY':
            Day.SATURDAY,
        },
    )
Esempio n. 5
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)

    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
Esempio n. 6
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
Esempio n. 7
0
def home(request):
    try:
        # fetching blog posts is hella flaky, we don't want to 500 if it fails
        # TODO: do in a background job to avoid this
        blog_posts = get_blog_posts()[:2]
    except RequestException:
        blog_posts = []

    hours = [Day.from_date(date.today() + timedelta(days=i)) for i in range(3)]
    return render_to_response(
        'home.html',
        {
            'fulltitle': 'Open Computing Facility at UC Berkeley',
            'description': (
                'The Open Computing Facility is an all-volunteer student '
                'organization dedicated to free and open-source computing for all UC '
                'Berkeley students.'
            ),
            'staff_hours': get_staff_hours(),
            'hours': hours,
            'today': hours[0],
            'blog_posts': blog_posts,
            'lab_status': get_lab_status(),
        },
        context_instance=RequestContext(request),
    )
Esempio n. 8
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,
        },
    )
Esempio n. 9
0
def tv_main(request):
    return render(
        request,
        'tv/tv.html',
        {
            'hours': Day.from_date(),
        },
    )
Esempio n. 10
0
def tv_hours(request):
    return render(
        request,
        'tv/hours.html',
        {
            'hours': Day.from_date(),
        },
    )
Esempio n. 11
0
def tv_labmap(request):
    return render(
        request,
        'tv/labmap.html',
        {
            'hours': [[h.open.hour, h.close.hour]
                      for h in Day.from_date().hours],
        },
    )
Esempio n. 12
0
def ocf_template_processor(request):
    hours = Day.from_date(date.today())
    real_ip = get_real_ip(request)
    return {
        'lab_is_open': hours.is_open(),
        'current_lab_hours': hours,
        'lab_status': get_lab_status(),
        'base_css_classes': ' '.join(get_base_css_classes(request)),
        'is_ocf_ip': is_ocf_ip(real_ip) if real_ip else True,
        'join_staff_url': request.build_absolute_uri(reverse('about-staff')),
    }
Esempio n. 13
0
def ocf_template_processor(request):
    hours = Day.from_date(date.today())
    real_ip = get_real_ip(request)
    return {
        'lab_is_open': hours.is_open(),
        'current_lab_hours': hours,
        'lab_status': get_lab_status(),
        'base_css_classes': ' '.join(get_base_css_classes(request)),
        'is_ocf_ip': is_ocf_ip(ip_address(real_ip)) if real_ip else True,
        'join_staff_url': request.build_absolute_uri(reverse('about-staff')),
        'ocfweb_version': ocfweb_version(),
    }
Esempio n. 14
0
    def test_creation(self, mock_hours, mock_today, when, weekday, holiday, hours):
        day_hours = Day.from_date(when)
        if when:
            if isinstance(when, datetime):
                day = when.date()
            else:
                day = when
        else:
            day = date.today()

        assert day_hours.date == day
        assert day_hours.weekday == weekday
        assert day_hours.hours == hours
        assert day_hours.holiday == holiday
Esempio n. 15
0
File: api.py Progetto: wilswu/ocfweb
def hours(request):
    today = Day.from_date()
    dic = {
        'date': today.date,
        'day': today.weekday,
        'holiday': today.holiday,
        'hours': today.hours,
    }

    return JsonResponse(
        dic,
        json_dumps_params={'default': lambda x: x.isoformat()},
        content_type='application/json',
    )
Esempio n. 16
0
    def test_creation(self, mock_hours, mock_today, when, weekday, holiday,
                      hours):
        day_hours = Day.from_date(when)
        if when:
            if isinstance(when, datetime):
                day = when.date()
            else:
                day = when
        else:
            day = date.today()

        assert day_hours.date == day
        assert day_hours.weekday == weekday
        assert day_hours.hours == hours
        assert day_hours.holiday == holiday
Esempio n. 17
0
def ocf_template_processor(request):
    hours = Day.from_date(date.today())
    real_ip = get_real_ip(request)
    user = logged_in_user(request)
    return {
        'base_css_classes': ' '.join(get_base_css_classes(request)),
        'current_lab_hours': hours,
        'is_ocf_ip': is_ocf_ip(ip_address(real_ip)) if real_ip else True,
        'join_staff_url': request.build_absolute_uri(reverse('about-staff')),
        'lab_is_open': hours.is_open(),
        'lab_status': get_lab_status(),
        'ocfweb_version': ocfweb_version(),
        'request_full_path': request.get_full_path(),
        'user': user,
        'user_is_group': user is not None and user_is_group(user),
    }
Esempio n. 18
0
def ocf_template_processor(request):
    hours = Day.from_date(date.today())
    real_ip = get_real_ip(request)
    user = logged_in_user(request)
    return {
        'base_css_classes': ' '.join(get_base_css_classes(request)),
        'current_lab_hours': hours,
        'is_ocf_ip': is_ocf_ip(ip_address(real_ip)) if real_ip else True,
        'join_staff_url': request.build_absolute_uri(reverse('about-staff')),
        'lab_is_open': hours.is_open(),
        'lab_status': get_lab_status(),
        'ocfweb_version': ocfweb_version(),
        'request_full_path': request.get_full_path(),
        'user': user,
        'user_is_group': user is not None and user_is_group(user),
    }
Esempio n. 19
0
def home(request):
    hours = [Day.from_date(date.today() + timedelta(days=i)) for i in range(3)]
    return render(
        request,
        "main/home.html",
        {
            "fulltitle": "Open Computing Facility at UC Berkeley",
            "description": (
                "The Open Computing Facility is an all-volunteer student "
                "organization dedicated to free and open-source computing for all UC "
                "Berkeley students."
            ),
            "staff_hours": get_staff_hours(),
            "hours": hours,
            "today": hours[0],
            "blog_posts": get_blog_posts()[:2],
            "lab_status": get_lab_status(),
        },
    )
Esempio n. 20
0
def home(request):
    hours = [Day.from_date(date.today() + timedelta(days=i)) for i in range(3)]
    return render(
        request,
        'main/home.html',
        {
            'fulltitle': 'Open Computing Facility at UC Berkeley',
            'description': (
                'The Open Computing Facility is an all-volunteer student '
                'organization dedicated to free and open-source computing for all UC '
                'Berkeley students.'
            ),
            'staff_hours': get_staff_hours(),
            'hours': hours,
            'announcements': sorted(
                get_blog_posts() + list(announcements), key=attrgetter('datetime'),
                reverse=True,
            )[:2],
            'today': hours[0],
            'lab_status': get_lab_status(),
        },
    )
Esempio n. 21
0
def test_is_open(now, expected_open, mock_hours, mock_today):
    assert Day.from_date(now).is_open(now) == expected_open
Esempio n. 22
0
def test_is_open(now, expected_open, mock_hours, mock_today):
    assert Day.from_date(now).is_open(now) == expected_open
Esempio n. 23
0
def test_is_open_fails_with_just_date():
    with pytest.raises(ValueError):
        Day.from_date().is_open(date(2015, 3, 14))
Esempio n. 24
0
def test_is_open_fails_with_just_date():
    with pytest.raises(ValueError):
        Day.from_date().is_open(date(2015, 3, 14))