Skip to content
Snippets Groups Projects
Commit a9c9c58e authored by Felix Schäfer's avatar Felix Schäfer :construction_worker:
Browse files

Show public registrations on event front page

Currently limited to Gravatar based on attendee email and attendee name.
parent a0c89455
No related branches found
No related tags found
No related merge requests found
from django import forms from django import forms
from django.dispatch import receiver 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 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") @receiver(question_form_fields, dispatch_uid="public_registration_question")
...@@ -13,3 +16,35 @@ def add_public_registration_question(sender, **kwargs): ...@@ -13,3 +16,35 @@ def add_public_registration_question(sender, **kwargs):
help_text=sender.settings.get('public_registration_field_help_text', as_type=LazyI18nString), help_text=sender.settings.get('public_registration_field_help_text', as_type=LazyI18nString),
widget=forms.CheckboxInput(), 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
{% 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>
...@@ -33,7 +33,7 @@ setup( ...@@ -33,7 +33,7 @@ setup(
author_email='felix@kif.rocks', author_email='felix@kif.rocks',
license='Apache Software License', license='Apache Software License',
install_requires=[], install_requires=['django-gravatar2'],
packages=find_packages(exclude=['tests', 'tests.*']), packages=find_packages(exclude=['tests', 'tests.*']),
include_package_data=True, include_package_data=True,
cmdclass=cmdclass, cmdclass=cmdclass,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment