membershipworks: Add PDF preview for event invoices

This commit is contained in:
Adam Goldsmith 2024-04-27 10:53:37 -04:00
parent 175c3b2c5a
commit ae1116fea8
5 changed files with 50 additions and 2 deletions

View File

@ -0,0 +1,7 @@
@page {
background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='75' height='75' viewBox='0 0 75 75'><text style='font-size:13px;fill:lightgrey' x='-49' y='58' id='text1' transform='rotate(-45)'>PREVIEW</text></svg>");
}
body, table * {
background: transparent !important;
}

View File

@ -35,10 +35,20 @@
<form method="post" class="card-text"> <form method="post" class="card-text">
{% csrf_token %} {% csrf_token %}
{% bootstrap_form form %} {% bootstrap_form form %}
<div class="text-center">{% bootstrap_button button_type="submit" content="Submit Invoice" %}</div> <div class="text-center">
{% 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" %}
</div>
</form> </form>
{% else %} {% else %}
<p>No invoice has been created for this event, and you are not listed as the the instructor.</p> <p>
No invoice has been created for this event, and you are not listed as the the instructor.
<div class="text-center">
{% 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" %}
</div>
</p>
{% endif %} {% endif %}
</div> </div>
</div> </div>

View File

@ -9,6 +9,9 @@
<!-- Bootstrap CSS --> <!-- Bootstrap CSS -->
<link href="{% static 'bootstrap.min.css' %}" rel="stylesheet"> <link href="{% static 'bootstrap.min.css' %}" rel="stylesheet">
<link rel="stylesheet" href="{% static "membershipworks/css/event_invoice_pdf.css" %}" media="print"> <link rel="stylesheet" href="{% static "membershipworks/css/event_invoice_pdf.css" %}" media="print">
{% if preview %}
<link rel="stylesheet" href="{% static "membershipworks/css/event_invoice_pdf_preview.css" %}" media="print">
{% endif %}
<title>Event Invoice for {{ event.details.ttl|nh3 }}</title> <title>Event Invoice for {{ event.details.ttl|nh3 }}</title>
</head> </head>

View File

@ -35,6 +35,11 @@ urlpatterns = [
views.UserEventView.as_view(), views.UserEventView.as_view(),
name="user-events", name="user-events",
), ),
path(
"event/<eid>_preview.pdf",
views.EventInvoicePDFPreviewView.as_view(),
name="event-invoice-pdf-preview",
),
path( path(
"event/<eid>", "event/<eid>",
views.EventDetailView.as_view(), views.EventDetailView.as_view(),

View File

@ -36,6 +36,7 @@ from django_mysql.models import GroupConcat
from django_sendfile import sendfile from django_sendfile import sendfile
from django_tables2 import A, SingleTableMixin from django_tables2 import A, SingleTableMixin
from django_tables2.export.views import ExportMixin from django_tables2.export.views import ExportMixin
from django_weasyprint import WeasyTemplateResponseMixin
from django_weasyprint.utils import django_url_fetcher from django_weasyprint.utils import django_url_fetcher
from membershipworks.membershipworks_api import MembershipWorks from membershipworks.membershipworks_api import MembershipWorks
@ -382,6 +383,28 @@ class EventDetailView(
return super().form_valid(form) 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): class EventInvoicePDFView(AccessMixin, BaseDetailView):
model = EventInvoice model = EventInvoice
pk_url_kwarg = "uuid" pk_url_kwarg = "uuid"