diff --git a/pretix_public_registrations/signals.py b/pretix_public_registrations/signals.py index f284225d64583d346746eef19f97ae78a1100693..fcd6042043db9da9782e246d27fc964cd3395b74 100644 --- a/pretix_public_registrations/signals.py +++ b/pretix_public_registrations/signals.py @@ -1,8 +1,11 @@ from django import forms from django.dispatch import receiver -from django.utils.translation import ugettext_lazy as _ +from django.template.loader import get_template +from django.utils.translation import ugettext_lazy as _, get_language +from django_gravatar.helpers import get_gravatar_url from i18nfield.strings import LazyI18nString -from pretix.presale.signals import question_form_fields +from pretix.presale.signals import question_form_fields, front_page_bottom, process_response +from pretix.base.models import OrderPosition @receiver(question_form_fields, dispatch_uid="public_registration_question") @@ -13,3 +16,35 @@ def add_public_registration_question(sender, **kwargs): help_text=sender.settings.get('public_registration_field_help_text', as_type=LazyI18nString), widget=forms.CheckboxInput(), )} + + +@receiver(signal=front_page_bottom, dispatch_uid="public_registrations_table") +def add_public_registrations_table(sender, **kwargs): + cached = sender.cache.get('public_registrations_table_' + get_language()) + if cached is None: + cached = "" + headers = ["", "Name"] + order_positions = OrderPosition.all.filter(order__event=sender) + public_order_positions = [ + op for op in order_positions + if op.meta_info_data.get('question_form_data', {}).get('public_registration') == "True" + ] + public_registrations = [ + { + 'gr_url': get_gravatar_url(pop.attendee_email, size=24, default="wavatar"), + 'fields': [pop.attendee_name_cached] + } for pop in public_order_positions + ] + template = get_template('pretix_public_registrations/front_page.html') + cached = template.render({ + 'headers': headers, + 'public_registrations': public_registrations + }) + return cached + + +@receiver(signal=process_response, dispatch_uid="public_registragions_csp_headers") +def add_public_registrations_csp_headers(sender, **kwargs): + response = kwargs['response'] + response['Content-Security-Policy'] = "img-src https://secure.gravatar.com" + return response diff --git a/pretix_public_registrations/templates/pretix_public_registrations/front_page.html b/pretix_public_registrations/templates/pretix_public_registrations/front_page.html new file mode 100644 index 0000000000000000000000000000000000000000..9f6c551ab3a567be538464b3d48453c9ce67bd93 --- /dev/null +++ b/pretix_public_registrations/templates/pretix_public_registrations/front_page.html @@ -0,0 +1,25 @@ +{% load i18n %} +<section class="front-page"> + <h3>{% trans "Public registrations" %}</h3> + <div class="table-responsive product-row"> + <table class="table table-striped"> + <thead> + <tr> + {% for h in headers %} + <th scope="col">{% trans h %}</th> + {% endfor %} + </tr> + </thead> + <tbody> + {% for pr in public_registrations %} + <tr> + <td><img class="gravatar" src="{{ pr.gr_url }}" /></td> + {% for f in pr.fields %} + <td>{{ f }}</td> + {% endfor %} + </tr> + {% endfor %} + </tbody> + </table> + </div> +</section> diff --git a/setup.py b/setup.py index 92a1a0b41b2d245bdbe10e39800fd05f1c8c801c..516ccce0768ac214394e3160afb43fb026b6ec41 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ setup( author_email='felix@kif.rocks', license='Apache Software License', - install_requires=[], + install_requires=['django-gravatar2'], packages=find_packages(exclude=['tests', 'tests.*']), include_package_data=True, cmdclass=cmdclass,