diff options
author | Filipp Lepalaan <filipp@mac.com> | 2015-08-18 23:37:05 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2015-08-18 23:37:05 +0300 |
commit | 09731610e0c037a3c6a6068d71f4dca887389f26 (patch) | |
tree | a62710dc46138189d4c7f8e7a7d8363f9fdb8baf | |
parent | 12a991f475e38cb7e2a32ef3afb4b733aeae4771 (diff) | |
download | Servo-09731610e0c037a3c6a6068d71f4dca887389f26.tar.gz Servo-09731610e0c037a3c6a6068d71f4dca887389f26.tar.bz2 Servo-09731610e0c037a3c6a6068d71f4dca887389f26.zip |
Fixed session problems in stats
-rw-r--r-- | servo/stats/forms.py | 13 | ||||
-rw-r--r-- | servo/views/stats.py | 21 |
2 files changed, 24 insertions, 10 deletions
diff --git a/servo/stats/forms.py b/servo/stats/forms.py index d1ec2aa..918695f 100644 --- a/servo/stats/forms.py +++ b/servo/stats/forms.py @@ -55,6 +55,19 @@ class BasicStatsForm(forms.Form): widget=DatepickerInput(attrs={'class': "input-small"}) ) + def serialize(self): + import datetime + from django.db.models import Model + cd = self.cleaned_data + + for k, v in cd.iteritems(): + if isinstance(v, datetime.datetime): + cd[k] = str(v) + if isinstance(v, Model): + cd[k] = v.pk + + return cd + class OrderStatsForm(BasicStatsForm): location = forms.ModelChoiceField( diff --git a/servo/views/stats.py b/servo/views/stats.py index 5ca66f8..0822373 100644 --- a/servo/views/stats.py +++ b/servo/views/stats.py @@ -98,7 +98,7 @@ def index(request): if request.method == 'POST': form = TechieStatsForm(request.POST, initial=data['initial']) if form.is_valid(): - request.session['stats_filter'] = form.cleaned_data + request.session['stats_filter'] = form.serialize() data['form'] = form return render(request, "stats/index.html", data) @@ -207,11 +207,7 @@ def data(request, query): result.append({'label': i.title, 'data': data}) if report == "status": - try: - status = params.get('status').title - except AttributeError: - return HttpResponse(json.dumps(result)) - + status = params.get('status') if what == "location": for i in locations.all(): data = stats.statuses_per_location( @@ -298,7 +294,7 @@ def sales(request): if request.method == 'POST': form = InvoiceStatsForm(request.POST, initial=data['initial']) if form.is_valid(): - request.session['stats_filter'] = form.cleaned_data + request.session['stats_filter'] = form.serialize() data['form'] = form return render(request, "stats/sales.html", data) @@ -310,7 +306,7 @@ def queues(request): if request.method == 'POST': form = OrderStatsForm(request.POST, initial=data['initial']) if form.is_valid(): - request.session['stats_filter'] = form.cleaned_data + request.session['stats_filter'] = form.serialize() data['form'] = form return render(request, "stats/queues.html", data) @@ -322,7 +318,7 @@ def locations(request): if request.method == 'POST': form = BasicStatsForm(request.POST, initial=data['initial']) if form.is_valid(): - request.session['stats_filter'] = form.cleaned_data + request.session['stats_filter'] = form.serialize() data['form'] = form return render(request, "stats/locations.html", data) @@ -333,7 +329,12 @@ def statuses(request): if request.method == 'POST': form = StatusStatsForm(request.POST, initial=data['initial']) if form.is_valid(): - request.session['stats_filter'] = form.cleaned_data + # Store the name of the status since we don't have + # IDs in events, yet + status = form.cleaned_data['status'].title + f = form.serialize() + f['status'] = status + request.session['stats_filter'] = f data['form'] = form return render(request, "stats/statuses.html", data) |