diff --git a/finance/views.py b/finance/views.py index ddfeaadf53ab7444a50940ef5fe744fffe2dd885..1f46a444d76e1a96f2bba7fe2600243ac2b97a87 100644 --- a/finance/views.py +++ b/finance/views.py @@ -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) diff --git a/production/forms.py b/production/forms.py index bba5be4e7f563fb618e88c2eee1f31e03791327a..1fda9312f62b137f00184519a78e8b127e3d0dda 100644 --- a/production/forms.py +++ b/production/forms.py @@ -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