Add a management command to print badges

This commit is contained in:
James Polley 2018-01-21 12:34:44 +11:00
parent 3b0d9bf23a
commit 0af7bedae5
3 changed files with 27 additions and 0 deletions

View file

View file

@ -0,0 +1,27 @@
#!/usr/bin/env python
from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from registrasion.views import _convert_img as convert_img
from registrasion.views import render_badge_svg
class Command(BaseCommand):
def handle(self, *args, **options):
users = User.objects.filter(
checkin__checked_in_bool=True).filter(
checkin__badge_printed=False
)
for user in users:
try:
svg = render_badge_svg(user, overlay=True)
rendered = convert_img(svg, outformat="pdf")
with open("/app/badge_out/{}.pdf".format(user.checkin.checkin_code), "wb") as outfile:
outfile.write(rendered)
user.checkin.mark_badge_printed()
except Exception:
pass