Example #1
0
def index(request):

    current_assignment = Assignment.objects.current_assignment()

    today = date.today()
    today_weekday = calendar.weekday(today.year, today.month, today.day)
    today_range = (datetime(today.year, today.month, today.day, 0, 0, 0),
                   datetime(today.year, today.month, today.day, 23, 59, 59))
    monday = date.today() - timedelta(days=today_weekday)
    friday = monday + timedelta(days=12)
    two_weeks = list(weekdays(date_range(monday, friday)))

    assignments = Assignment.objects.filter(date__gte=monday).order_by('date')[:10]
    assignments_by_date = dict(((a.date, a) for a in assignments))
    week1_assignments = [assignments_by_date.get(dt) for dt in two_weeks[0:5]]
    week2_assignments = [assignments_by_date.get(dt) for dt in two_weeks[5:10]]

    bone_count = Bone.objects.filter(timestamp__range=today_range).count()
    nudge_count = Nudge.objects.filter(timestamp__range=today_range).count()

    context = {
        'today': str(today),
        'today_date': today,
        'monday': str(monday),
        'assignments': assignments,
        'week1_assignments': week1_assignments,
        'week2_assignments': week2_assignments,
        'bone_count': bone_count,
        'nudge_count': nudge_count,
        'current_assignment': current_assignment,
    }

    return render(request, "index.html", context)
Example #2
0
def current_schedule(request):
    # Get current and future assignments
    assignment = Assignment.objects.current_assignment()
    today = date.today()
    today_weekday = calendar.weekday(today.year, today.month, today.day)
    today_range = (datetime(today.year, today.month, today.day, 0, 0, 0),
                   datetime(today.year, today.month, today.day, 23, 59, 59))
    monday = date.today() - timedelta(days=today_weekday)
    def assignment_for_day(day):
        try:
            return Assignment.objects.get(date=day)
        except Assignment.DoesNotExist:
            return None
    def day_info(day):
        return { 'assignment': assignment_for_day(day),
                 'is_workday': 1 if is_workday(day) else 0 }
    days = map(day_info, list(weekdays(date_range(monday, monday + timedelta(days=12)))))
    weeks = [days[x:x+5] for x in range(0, len(days), 5)]
    bone_count = Bone.objects.filter(timestamp__range=today_range).count()
    nudge_count = Nudge.objects.filter(timestamp__range=today_range).count()

    return render_to_response('schedule.html', {
                                  'today': str(today),
                                  'monday': str(monday),
                                  'assignments': assignments,
                                  'weeks': weeks,
                                  'current_assignment': assignment,
                                  'bone_count': bone_count,
                                  'week1': range(0, 5),
                                  'week2': range(5, 10),
                                  'nudge_count': nudge_count
                              })