Skip to content
Snippets Groups Projects
views.py 1.73 KiB
Newer Older
Tom Teichler's avatar
Tom Teichler committed
from django.views.generic import View
from django.shortcuts import render

Tom Teichler's avatar
Tom Teichler committed
from rules.contrib.views import PermissionRequiredMixin
Tom Teichler's avatar
Tom Teichler committed
from aleksis.core.views import RenderPDFView

from .tables import ClientsTable
from .forms import EditClientForm
from .models.base import Client
Tom Teichler's avatar
Tom Teichler committed
from .models.invoice import Invoice


Tom Teichler's avatar
Tom Teichler committed
class GetInvoicePDF(PermissionRequiredMixin, RenderPDFView):
Tom Teichler's avatar
Tom Teichler committed

    permission_required = "tezor.can_print_invoice"

Tom Teichler's avatar
Tom Teichler committed
    def get_context_data(self, *args, **kwargs):
        context = super().get_context_data(*args, **kwargs)
Tom Teichler's avatar
Tom Teichler committed
        invoice = Invoice.objects.get(id=self.kwargs["pk"])
Tom Teichler's avatar
Tom Teichler committed
        self.template_name = invoice.group.template_name
Tom Teichler's avatar
Tom Teichler committed
        context["invoice"] = invoice

Tom Teichler's avatar
Tom Teichler committed
        print(invoice.group.__dict__)
        return context

class ClientListView(PermissionRequiredMixin, SingleTableView):
    """Table of all clients."""

    model = Client
    table_class = ClientsTable
    permission_required = "teor.view_clients"
    template_name = "teor/client/list.html"


@method_decorator(never_cache, name="dispatch")
class ClientCreateView(PermissionRequiredMixin, AdvancedCreateView):
    """Create view for clients."""

    model = Client
    form_class = EditClientForm
    permission_required = "teor.add_clients"
    template_name = "teor/client/create.html"
    success_url = reverse_lazy("clients")
    success_message = _("The client has been created.")


@method_decorator(never_cache, name="dispatch")
class ClientEditView(PermissionRequiredMixin, AdvancedEditView):
    """Edit view for clients."""

    model = Client
    form_class = EditClientForm
    permission_required = "teor.edit_clients"
    template_name = "teor/client/edit.html"
    success_url = reverse_lazy("clients")
    success_message = _("The client has been saved.")