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): ...@@ -14,7 +14,7 @@ def timesheets(request):
'form': form, 'form': form,
} }
if form.is_valid(): # if form.is_valid():
context['totals'] = form.get_totals() context['totals'] = form.get_totals()
return render(request, 'finance/timesheets.html', context) return render(request, 'finance/timesheets.html', context)
...@@ -53,11 +53,23 @@ class ProductionUserMonthlyActiveFilter(forms.Form): ...@@ -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))]) year = forms.ChoiceField(choices=[(y, y) for y in reversed(range(today.year-6, today.year+1))])
def __init__(self, *args, **kwargs): 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) super().__init__(*args, **kwargs)
self.fields['month'].initial = today.month
self.fields['year'].initial = today.year
def get_totals(self): 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, users = ProductionUser.objects.filter(events__duration__isnull=False,
events__noted_on__month=self.cleaned_data['month'], events__noted_on__month=self.cleaned_data['month'],
events__noted_on__year=self.cleaned_data['year'] events__noted_on__year=self.cleaned_data['year']
...@@ -72,13 +84,5 @@ class ProductionUserMonthlyActiveFilter(forms.Form): ...@@ -72,13 +84,5 @@ class ProductionUserMonthlyActiveFilter(forms.Form):
'duration': events.aggregate(total=Sum('duration')), 'duration': events.aggregate(total=Sum('duration')),
'user': user 'user': user
}) })
return output
def get_events(self, officer=None): return output
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')
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