SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 4e0a9929 authored by Jorran de Wit's avatar Jorran de Wit
Browse files

Auto open time sheet even if not explicity filtered

parent 412d32e2
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ def timesheets(request):
'form': form,
}
if form.is_valid():
context['totals'] = form.get_totals()
# if form.is_valid():
context['totals'] = form.get_totals()
return render(request, 'finance/timesheets.html', context)
......@@ -53,11 +53,23 @@ class ProductionUserMonthlyActiveFilter(forms.Form):
year = forms.ChoiceField(choices=[(y, y) for y in reversed(range(today.year-6, today.year+1))])
def __init__(self, *args, **kwargs):
if not kwargs.get('data', False) and not args[0]:
args = list(args)
args[0] = {
'month': today.month,
'year': today.year
}
args = tuple(args)
kwargs['initial'] = {
'month': today.month,
'year': today.year
}
super().__init__(*args, **kwargs)
self.fields['month'].initial = today.month
self.fields['year'].initial = today.year
def get_totals(self):
# Make accessible without need to explicitly check validity of form.
self.is_valid()
users = ProductionUser.objects.filter(events__duration__isnull=False,
events__noted_on__month=self.cleaned_data['month'],
events__noted_on__year=self.cleaned_data['year']
......@@ -72,13 +84,5 @@ class ProductionUserMonthlyActiveFilter(forms.Form):
'duration': events.aggregate(total=Sum('duration')),
'user': user
})
return output
def get_events(self, officer=None):
qs = ProductionEvent.objects.filter(duration__isnull=False,
noted_on__month=self.cleaned_data['month'],
noted_on__year=self.cleaned_data['year'])
if officer:
qs.filter(noted_by=officer)
return qs.order_by('noted_by')
return output
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment