From 78470ec6e3df7eb23ce2366d5f6003f6ff5950d2 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Sat, 28 Jul 2012 11:11:21 +0200 Subject: [PATCH] Poor man's single page alerts --- invoice/views.py | 14 +++++++------- templates/base.html | 10 ++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/invoice/views.py b/invoice/views.py index 9b9805b..64a0f55 100644 --- a/invoice/views.py +++ b/invoice/views.py @@ -64,13 +64,13 @@ class InvoiceLineInline(InlineFormSet): class DetailInvoice(DetailView): model = Invoice - def get(self, request, *args, **kwargs): - i = get_object_or_404(Invoice, pk=kwargs["pk"]) - if i.due_days < 0: - messages.error(request, "This invoice is overdue") - elif i.due_days < 3: - messages.warning(request, "This invoice is soon due") - return super(DetailInvoice, self).get(request, *args, **kwargs) + def get_context_data(self, *args, **kwargs): + context_data = super(DetailInvoice, self).get_context_data(*args, **kwargs) + if self.object.due_days < 0: + context_data.update({'alert_error': "This invoice is overdue" }) + elif self.object.due_days < 3: + context_data.update({'alert_warning': "This invoice is soon due"}) + return context_data @method_decorator(login_required) def dispatch(self, *args, **kwargs): diff --git a/templates/base.html b/templates/base.html index 1c28fe1..367e2c9 100644 --- a/templates/base.html +++ b/templates/base.html @@ -84,6 +84,16 @@ {% endfor %} {% endif %} + {% if alert_error %} +
+ {{ alert_error }} +
+ {% endif %} + {% if alert_warning %} +
+ {{ alert_warning }} +
+ {% endif %} {% endblock messages %} {% block pretitle %}{% endblock %} -- 2.39.5