Simplified title display in backend views

This commit is contained in:
Kumi 2020-06-09 06:20:14 +02:00
parent 07389acb5a
commit e7feba94ae
2 changed files with 20 additions and 27 deletions

View file

@ -2,20 +2,29 @@ from django.views.generic import TemplateView, ListView, CreateView, FormView, D
from core.mixins.auth import AdminMixin
class BackendTemplateView(AdminMixin, TemplateView):
class BackendViewMixin(AdminMixin):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
try:
context["title"] = self.title
except AttributeError:
pass
return context
class BackendTemplateView(BackendViewMixin, TemplateView):
pass
class BackendListView(AdminMixin, ListView):
class BackendListView(BackendViewMixin, ListView):
pass
class BackendCreateView(AdminMixin, CreateView):
class BackendCreateView(BackendViewMixin, CreateView):
pass
class BackendFormView(AdminMixin, FormView):
class BackendFormView(BackendViewMixin, FormView):
pass
class BackendDeleteView(AdminMixin, DeleteView):
class BackendDeleteView(BackendViewMixin, DeleteView):
pass
class BackendUpdateView(AdminMixin, UpdateView):
class BackendUpdateView(BackendViewMixin, UpdateView):
pass

View file

@ -7,40 +7,24 @@ from core.views.backend.generic import BackendListView, BackendUpdateView, Backe
class InvoiceListView(BackendListView):
template_name = f"{settings.EXPEPHALON_BACKEND}/invoices/index.html"
model = Invoice
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = "Invoice Settings"
return context
title = "Invoices"
class InvoiceEditView(BackendUpdateView):
template_name = f"{settings.EXPEPHALON_BACKEND}/invoices/update.html"
model = Invoice
success_url = reverse_lazy("invoices")
fields = ["name", "logo", "address1", "address2", "zip", "city", "state", "country", "vat_id", "company_id"]
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = "Edit Invoice"
return context
title = "Edit Invoice"
class InvoiceDeleteView(BackendDeleteView):
template_name = f"{settings.EXPEPHALON_BACKEND}/invoices/delete.html"
model = Invoice
success_url = reverse_lazy("invoices")
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = "Delete Invoice"
return context
title = "Delete Invoice"
class InvoiceCreateView(BackendCreateView):
template_name = f"{settings.EXPEPHALON_BACKEND}/invoices/create.html"
model = Invoice
success_url = reverse_lazy("invoices")
fields = ["name", "logo", "address1", "address2", "zip", "city", "state", "country", "vat_id", "company_id"]
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = "Create Invoice"
return context
fields = ["client", "brand", "number", "created", "due", "payment_method", "currency"]
title = "Create Invoice"