-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gotenberg as option in addition to wkhtmltopdf (#336)
- Loading branch information
Showing
11 changed files
with
408 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 3.2.25 on 2024-11-09 20:43 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('registration', '0102_event_dealer_wifi_partner_price'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='BadgeTemplate', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=100)), | ||
('template', models.TextField()), | ||
('paperWidth', models.CharField(max_length=10, null=True)), | ||
('paperHeight', models.CharField(max_length=10, null=True)), | ||
('marginTop', models.CharField(max_length=10, null=True)), | ||
('marginBottom', models.CharField(max_length=10, null=True)), | ||
('marginLeft', models.CharField(max_length=10, null=True)), | ||
('marginRight', models.CharField(max_length=10, null=True)), | ||
('landscape', models.BooleanField(default=True)), | ||
('scale', models.FloatField(default=1.0)), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name='event', | ||
name='defaultBadgeTemplate', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='registration.badgetemplate'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from datetime import timedelta | ||
|
||
from django.conf import settings | ||
from django.contrib.auth.models import User | ||
from django.test import Client, TestCase | ||
from django.urls import reverse | ||
from django.utils import timezone | ||
|
||
from registration.models import ( | ||
Attendee, | ||
Badge, | ||
BadgeTemplate, | ||
Event, | ||
Order, | ||
OrderItem, | ||
PriceLevel, | ||
) | ||
from registration.tests.common import DEFAULT_EVENT_ARGS, TEST_ATTENDEE_ARGS | ||
|
||
now = timezone.now() | ||
ten_days = timedelta(days=10) | ||
|
||
|
||
class TestRegistrationPrinting(TestCase): | ||
def setUp(self): | ||
self.admin_user = User.objects.create_superuser("admin", "admin@host", "admin") | ||
self.admin_user.save() | ||
|
||
self.badge_template = BadgeTemplate( | ||
template="<script>window.badgeReady = true;</script>" | ||
) | ||
self.badge_template.save() | ||
|
||
self.event = Event( | ||
defaultBadgeTemplate=self.badge_template, **DEFAULT_EVENT_ARGS | ||
) | ||
self.event.save() | ||
|
||
self.priceLevel = PriceLevel( | ||
name="Attendee", | ||
description="Hello", | ||
basePrice=1.00, | ||
startDate=now - ten_days, | ||
endDate=now + ten_days, | ||
public=True, | ||
) | ||
self.priceLevel.save() | ||
|
||
self.order = Order( | ||
total=100, | ||
billingType=Order.CREDIT, | ||
status=Order.COMPLETED, | ||
reference="CREDIT_ORDER_1", | ||
) | ||
self.order.save() | ||
|
||
self.attendee = Attendee(**TEST_ATTENDEE_ARGS) | ||
self.attendee.save() | ||
|
||
self.badge = Badge(event=self.event, attendee=self.attendee) | ||
self.badge.save() | ||
|
||
self.order_item = OrderItem( | ||
order=self.order, | ||
badge=self.badge, | ||
priceLevel=self.priceLevel, | ||
) | ||
self.order_item.save() | ||
|
||
self.client = Client() | ||
|
||
def _badge_generates_pdf(self) -> dict: | ||
self.assertTrue(self.client.login(username="admin", password="admin")) | ||
|
||
response = self.client.get( | ||
reverse("registration:onsite_print_badges") + f"?id={self.badge.pk}" | ||
) | ||
self.assertEqual(response.status_code, 200) | ||
data = response.json() | ||
self.assertIsNotNone(data["file"]) | ||
|
||
self.client.logout() | ||
|
||
response = self.client.get(data["file"]) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.headers["content-type"], "application/pdf") | ||
|
||
return data | ||
|
||
def test_print_wkhtmltopdf(self): | ||
settings.PRINT_RENDERER = "wkhtmltopdf" | ||
data = self._badge_generates_pdf() | ||
# wkhtmltopdf responses return a direct path to the file | ||
self.assertIn("?file=", data["file"]) | ||
|
||
def test_print_gotenberg(self): | ||
settings.PRINT_RENDERER = "gotenberg" | ||
data = self._badge_generates_pdf() | ||
# gotenberg responses return a signed data parameter with badge IDs | ||
self.assertIn("?data=", data["file"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.