]> err.no Git - peojumk/commitdiff
Poor man's single page alerts
authorTollef Fog Heen <tfheen@err.no>
Sat, 28 Jul 2012 09:11:21 +0000 (11:11 +0200)
committerTollef Fog Heen <tfheen@err.no>
Sat, 28 Jul 2012 09:11:21 +0000 (11:11 +0200)
invoice/views.py
templates/base.html

index 9b9805bcba5a5c9fae587e1dea2dfc03fa5cb8c9..64a0f55201e67f7ab2a65d354af1d8528492313b 100644 (file)
@@ -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):
index 1c28fe1973369da105229ef6117f82599d4a71de..367e2c9dcd1488ee79ee4ba76ff9e5e0d988725f 100644 (file)
              </div>
            {% endfor %}
          {% endif %}
+         {% if alert_error %}
+           <div class="alert alert-error">
+             {{ alert_error }}
+           </div>
+         {% endif %}
+         {% if alert_warning %}
+           <div class="alert alert-warning">
+             {{ alert_warning }}
+           </div>
+         {% endif %}
        {% endblock messages %}
 
          {% block pretitle %}{% endblock %}