Skip to content

Commit

Permalink
Add timerecord hours summary view.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterJohnson committed Mar 9, 2013
1 parent 258bf06 commit 797602b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
18 changes: 18 additions & 0 deletions forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ class ContactListForm(TeamReportForm):
class TshirtListForm(TeamReportForm):
pass

class HoursListForm(forms.Form):
who = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
choices=(
('Mentor', "Mentor"),
('Student', "Student"),
),
initial=['Mentor', 'Student'])

team = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
choices=[(x.id, x.name) for x in Team.objects.all()])

from_date = forms.DateField(required=False)
to_date = forms.DateField(required=False)

include_hours = forms.BooleanField(required=False, initial=True)

class EventEmailListForm(forms.Form):
who = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
Expand Down
1 change: 1 addition & 0 deletions templates/roster/front.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<li><a href="{% url phone_list %}">Team Phone List</a></li>
<li><a href="{% url contact_list %}">Team Contact List</a></li>
<li><a href="{% url tshirt_list %}">T-Shirt List</a></li>
<li><a href="{% url hours_list %}">Hours List</a></li>
<li><a href="{% url badges %}">Badge Generation</a></li>
</ul>

Expand Down
1 change: 1 addition & 0 deletions urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
url(r'^phone/$', 'phone_list', name="phone_list"),
url(r'^contact/$', 'contact_list', name="contact_list"),
url(r'^tshirt/$', 'tshirt_list', name="tshirt_list"),
url(r'^hours/$', 'hours_list', name="hours_list"),
url(r'^event_email/$', 'event_email_list', name="event_email_list"),
url(r'^team_reg_verify/$', 'team_reg_verify', name="team_reg_verify"),
url(r'^badges/$', 'badges', name="badges"),
Expand Down
36 changes: 35 additions & 1 deletion views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
from django.db.models import Q, Count
from django.db.models import Q, Count, Sum
from django.views.decorators.csrf import csrf_exempt
from django.db import transaction
from django.contrib.formtools.wizard.views import SessionWizardView
Expand Down Expand Up @@ -286,6 +286,40 @@ def tshirt_list(request):
return render_to_response("roster/tshirt_list.html", locals(),
context_instance=RequestContext(request))

@login_required(login_url='/roster/login/')
def hours_list(request):
"""Team hours list."""

if request.method == 'GET' and request.GET:
form = HoursListForm(request.GET)
if form.is_valid():
who = set(form.data.getlist('who'))

people = PersonTeam.objects.filter(role__in=who,
status='Active',
team__in=form.data.getlist('team')).values('person')

results = Person.objects.filter(id__in=people)

from_date = form.cleaned_data.get('from_date', None)
to_date = form.cleaned_data.get('to_date', None)
if from_date and to_date:
results = results.filter(timerecord__clock_in__range=(from_date, to_date))
elif from_date:
results = results.filter(timerecord__clock_in__gt=from_date)
elif to_date:
results = results.filter(timerecord__clock_in__lt=to_date)

results = results.annotate(total_hours=Sum('timerecord__hours')).order_by('-total_hours')

total = sum(x.total_hours for x in results)
show_hours = 'include_hours' in form.data
else:
form = HoursListForm()

return render_to_response("roster/hours_list.html", locals(),
context_instance=RequestContext(request))

@login_required(login_url='/roster/login/')
def event_email_list(request):
"""Event email list."""
Expand Down

0 comments on commit 797602b

Please sign in to comment.