From 0af7bedae581a560ead2c3a4780d485c56e7ee1b Mon Sep 17 00:00:00 2001 From: James Polley Date: Sun, 21 Jan 2018 12:34:44 +1100 Subject: [PATCH] Add a management command to print badges --- .../regidesk/regidesk/management/__init__.py | 0 .../regidesk/management/commands/__init__.py | 0 .../management/commands/print_badges.py | 27 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 vendor/regidesk/regidesk/management/__init__.py create mode 100644 vendor/regidesk/regidesk/management/commands/__init__.py create mode 100644 vendor/regidesk/regidesk/management/commands/print_badges.py diff --git a/vendor/regidesk/regidesk/management/__init__.py b/vendor/regidesk/regidesk/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vendor/regidesk/regidesk/management/commands/__init__.py b/vendor/regidesk/regidesk/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/vendor/regidesk/regidesk/management/commands/print_badges.py b/vendor/regidesk/regidesk/management/commands/print_badges.py new file mode 100644 index 00000000..16960f27 --- /dev/null +++ b/vendor/regidesk/regidesk/management/commands/print_badges.py @@ -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