Exemplo n.º 1
0
def shirt_sizes(request, semester_pk=None):
    semesters = Semester.objects.all()
    try:
        semester = (
            Semester.objects.get(pk=semester_pk) if semester_pk is not None
            else Semester.most_recent()
        )
    except Semester.DoesNotExist:
        semester = None
        enrollments = Enrollment.objects.none()
    else:
        enrollments = Enrollment.objects.filter(semester=semester)
    shirt_sizes = ShirtSize.objects.all()
    for shirt_size in shirt_sizes:
        #Can't reduce number of queries:
        # http://stackoverflow.com/questions/4620385/django-annotation-with-nested-filter
        shirt_size.all__count = enrollments.filter(shirt_size=shirt_size).count()
        shirt_size.paid__count = enrollments.filter(shirt_size=shirt_size, paid_dues=True).count()
        shirt_size.paid_unreceived__count = enrollments.filter(
            shirt_size=shirt_size, paid_dues=True, received_shirt=False
        ).count()
    return render(request, 'dashboard/shirt_sizes.html', {
        'semesters': semesters,
        'semester': semester,
        'shirt_sizes': shirt_sizes,
    })
Exemplo n.º 2
0
def member_list(request, semester_pk=None):
    if semester_pk is None:
        return redirect('dashboard.views.member_list', semester_pk=Semester.most_recent().pk)
    semester = Semester.objects.get(pk=semester_pk)
    d = [
        {
            'first_name': enrollment.member.user.first_name,
            'last_name': enrollment.member.user.last_name,
            'website': clean_web_url(enrollment.member.website),
        } for enrollment in (
            Enrollment.objects
                .filter(semester=semester, paid_dues=True)
                .order_by('member__user__last_name', 'member__user__first_name')
        )
    ]
    response = HttpResponse(json.dumps(d), content_type='application/json')
    response['Access-Control-Allow-Origin'] = '*'
    return response