diff --git a/membershipworks/static/membershipworks/css/event_invoice_pdf_preview.css b/membershipworks/static/membershipworks/css/event_invoice_pdf_preview.css new file mode 100644 index 0000000..8fcfd01 --- /dev/null +++ b/membershipworks/static/membershipworks/css/event_invoice_pdf_preview.css @@ -0,0 +1,7 @@ +@page { + background-image:url("data:image/svg+xml;utf8,PREVIEW"); +} + +body, table * { + background: transparent !important; +} diff --git a/membershipworks/templates/membershipworks/event_detail.dj.html b/membershipworks/templates/membershipworks/event_detail.dj.html index 98b04be..78d247f 100644 --- a/membershipworks/templates/membershipworks/event_detail.dj.html +++ b/membershipworks/templates/membershipworks/event_detail.dj.html @@ -35,10 +35,20 @@
{% csrf_token %} {% bootstrap_form form %} -
{% bootstrap_button button_type="submit" content="Submit Invoice" %}
+
+ {% url "membershipworks:event-invoice-pdf-preview" event.eid as pdf_preview_link %} + {% bootstrap_button button_class="btn-warning" href=pdf_preview_link content="Preview PDF" %} + {% bootstrap_button button_type="submit" content="Submit Invoice" %} +
{% else %} -

No invoice has been created for this event, and you are not listed as the the instructor.

+

+ No invoice has been created for this event, and you are not listed as the the instructor. +

+ {% url "membershipworks:event-invoice-pdf-preview" event.eid as pdf_preview_link %} + {% bootstrap_button button_class="btn-warning" href=pdf_preview_link content="Preview PDF" %} +
+

{% endif %} diff --git a/membershipworks/templates/membershipworks/event_invoice_pdf.dj.html b/membershipworks/templates/membershipworks/event_invoice_pdf.dj.html index 53dce4b..235e8dd 100644 --- a/membershipworks/templates/membershipworks/event_invoice_pdf.dj.html +++ b/membershipworks/templates/membershipworks/event_invoice_pdf.dj.html @@ -9,6 +9,9 @@ + {% if preview %} + + {% endif %} Event Invoice for {{ event.details.ttl|nh3 }} diff --git a/membershipworks/urls.py b/membershipworks/urls.py index 1d2af01..2ad8fd4 100644 --- a/membershipworks/urls.py +++ b/membershipworks/urls.py @@ -35,6 +35,11 @@ urlpatterns = [ views.UserEventView.as_view(), name="user-events", ), + path( + "event/_preview.pdf", + views.EventInvoicePDFPreviewView.as_view(), + name="event-invoice-pdf-preview", + ), path( "event/", views.EventDetailView.as_view(), diff --git a/membershipworks/views.py b/membershipworks/views.py index 8612ee0..a90f382 100644 --- a/membershipworks/views.py +++ b/membershipworks/views.py @@ -36,6 +36,7 @@ from django_mysql.models import GroupConcat from django_sendfile import sendfile from django_tables2 import A, SingleTableMixin from django_tables2.export.views import ExportMixin +from django_weasyprint import WeasyTemplateResponseMixin from django_weasyprint.utils import django_url_fetcher from membershipworks.membershipworks_api import MembershipWorks @@ -382,6 +383,28 @@ class EventDetailView( return super().form_valid(form) +class EventInvoicePDFPreviewView(WeasyTemplateResponseMixin, EventDetailView): + template_name = "membershipworks/event_invoice_pdf.dj.html" + pdf_attachment = False + + def display_instructor_version(self): + return True + + def get_pdf_filename(self): + return f"event-invoice_{self.object.pk}.pdf" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context.update( + { + "now": timezone.now(), + "invoice_uuid": "00000000-0000-0000-0000-000000000000", + "preview": True, + } + ) + return context + + class EventInvoicePDFView(AccessMixin, BaseDetailView): model = EventInvoice pk_url_kwarg = "uuid"