diff --git a/core/views/backend/generic.py b/core/views/backend/generic.py index 10e04b1..9104b06 100644 --- a/core/views/backend/generic.py +++ b/core/views/backend/generic.py @@ -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 \ No newline at end of file diff --git a/core/views/backend/invoices.py b/core/views/backend/invoices.py index 80b35d9..b986b31 100644 --- a/core/views/backend/invoices.py +++ b/core/views/backend/invoices.py @@ -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"