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):
</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 %}