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

Apply black, isort

parent f6ae368b
No related branches found
No related tags found
No related merge requests found
from django.utils.translation import gettext_lazy as _
try:
from pretix.base.plugins import PluginConfig
except ImportError:
......@@ -8,13 +9,16 @@ __version__ = "1.4.0"
class PluginApp(PluginConfig):
name = 'pretix_public_registrations'
verbose_name = 'Pretix public registrations'
name = "pretix_public_registrations"
verbose_name = "Pretix public registrations"
class PretixPluginMeta:
name = _('Pretix public registrations')
author = 'Felix Schäfer, Dominik Weitz'
description = _('This plugin will give the option to attendees of an event to mark their registration as public. Public registrations will be shown along their answers to questions marked as public by the organizers on a world-readable page.')
name = _("Pretix public registrations")
author = "Felix Schäfer, Dominik Weitz"
description = _(
"This plugin will give the option to attendees of an event to mark their registration as public. "
"Public registrations will be shown along their answers to questions marked as public by the organizers on a world-readable page."
)
visible = True
version = __version__
category = "FEATURE"
......@@ -24,4 +28,4 @@ class PluginApp(PluginConfig):
from . import signals # NOQA
default_app_config = 'pretix_public_registrations.PluginApp'
default_app_config = "pretix_public_registrations.PluginApp"
......@@ -6,34 +6,34 @@ from pretix.base.forms import SettingsForm
class PublicRegistrationsForm(SettingsForm):
public_registrations_items = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple(
attrs={'class': 'scrolling-multiple-choice'}
attrs={"class": "scrolling-multiple-choice"}
),
label=_('Show public registrations for'),
label=_("Show public registrations for"),
required=True,
choices=[],
)
public_registrations_questions = forms.MultipleChoiceField(
widget=forms.CheckboxSelectMultiple(
attrs={'class': 'scrolling-multiple-choice'}
attrs={"class": "scrolling-multiple-choice"}
),
label=_('Publicly show answers for'),
label=_("Publicly show answers for"),
required=True,
choices=[],
)
public_registrations_show_attendee_name = forms.BooleanField(
label=_('Show attendee name'),
label=_("Show attendee name"),
required=False,
)
public_registrations_show_item_name = forms.BooleanField(
label=_('Show product name'),
label=_("Show product name"),
required=False,
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['public_registrations_items'].choices = [
self.fields["public_registrations_items"].choices = [
(i.pk, i.name) for i in self.obj.items.all()
]
self.fields['public_registrations_questions'].choices = [
self.fields["public_registrations_questions"].choices = [
(q.pk, q.question) for q in self.obj.questions.all()
]
from django import forms
from django.dispatch import receiver
from django.template.loader import get_template
from django.utils.translation import gettext_lazy as _
from django.urls import resolve, reverse
from django.utils.translation import gettext_lazy as _
from django_gravatar.helpers import get_gravatar_url
from pretix.base.models import Order, OrderPosition, QuestionAnswer
from pretix.base.settings import settings_hierarkey
from pretix.base.signals import event_copy_data
from pretix.control.signals import nav_event_settings
from pretix.presale.signals import (
question_form_fields, front_page_bottom, process_response, html_head
front_page_bottom,
html_head,
process_response,
question_form_fields,
)
from pretix.control.signals import nav_event_settings
from pretix.base.models import Order, OrderPosition, QuestionAnswer
from pretix.base.settings import settings_hierarkey
settings_hierarkey.add_default('public_registrations_items', [], list)
settings_hierarkey.add_default('public_registrations_questions', [], list)
settings_hierarkey.add_default('public_registrations_show_attendee_name', False, bool)
settings_hierarkey.add_default('public_registrations_show_item_name', False, bool)
settings_hierarkey.add_default("public_registrations_items", [], list)
settings_hierarkey.add_default("public_registrations_questions", [], list)
settings_hierarkey.add_default("public_registrations_show_attendee_name", False, bool)
settings_hierarkey.add_default("public_registrations_show_item_name", False, bool)
@receiver(html_head, dispatch_uid="public_registrations_html_head")
def add_public_registrations_html_head(sender, request=None, **kwargs):
url = resolve(request.path_info)
if "event.index" not in url.url_name: return ""
cached = sender.cache.get('public_registrations_html_head')
if "event.index" not in url.url_name:
return ""
cached = sender.cache.get("public_registrations_html_head")
if cached is None:
cached = get_template("pretix_public_registrations/head.html").render()
sender.cache.set('public_registrations_html_head', cached)
sender.cache.set("public_registrations_html_head", cached)
return cached
@receiver(question_form_fields, dispatch_uid="public_registration_question")
def add_public_registration_question(sender, position, **kwargs):
if str(position.item.pk) not in sender.settings.get('public_registrations_items'):
if str(position.item.pk) not in sender.settings.get("public_registrations_items"):
return {}
public_questions = sender.questions.filter(
pk__in=sender.settings.get('public_registrations_questions')
pk__in=sender.settings.get("public_registrations_questions")
)
headers = (
[_("Product")] if sender.settings.get('public_registrations_show_item_name') else []
) + (
[_("Name")] if sender.settings.get('public_registrations_show_attendee_name') else []
) + [
q.question for q in public_questions
]
return {'public_registrations_public_registration': forms.BooleanField(
label=_('Public registration'),
(
[_("Product")]
if sender.settings.get("public_registrations_show_item_name")
else []
)
+ (
[_("Name")]
if sender.settings.get("public_registrations_show_attendee_name")
else []
)
+ [q.question for q in public_questions]
)
return {
"public_registrations_public_registration": forms.BooleanField(
label=_("Public registration"),
required=False,
help_text=_(
'A gravatar image based on a hash of your e-mail address as well as the answers to '
'the following questions will be publicly shown: %(qlist)s'
) % {'qlist': ", ".join(str(h) for h in headers)},
)}
"A gravatar image based on a hash of your e-mail address as well as the answers to "
"the following questions will be publicly shown: %(qlist)s"
)
% {"qlist": ", ".join(str(h) for h in headers)},
)
}
@receiver(signal=front_page_bottom, dispatch_uid="public_registrations_table")
def add_public_registrations_table(sender, **kwargs):
if not sender.settings.get('public_registrations_items') and not (
sender.settings.get('public_registrations_questions')
and sender.settings.get('public_registrations_show_item_name')
and sender.settings.get('public_registrations_show_attendee_name')
if not sender.settings.get("public_registrations_items") and not (
sender.settings.get("public_registrations_questions")
and sender.settings.get("public_registrations_show_item_name")
and sender.settings.get("public_registrations_show_attendee_name")
):
return ""
public_questions = sender.questions.filter(
pk__in=sender.settings.get('public_registrations_questions')
pk__in=sender.settings.get("public_registrations_questions")
)
headers = (
[_("Product")] if sender.settings.get('public_registrations_show_item_name') else []
) + (
[_("Name")] if sender.settings.get('public_registrations_show_attendee_name') else []
) + [
q.question for q in public_questions
]
order_positions = OrderPosition.objects.filter(
(
[_("Product")]
if sender.settings.get("public_registrations_show_item_name")
else []
)
+ (
[_("Name")]
if sender.settings.get("public_registrations_show_attendee_name")
else []
)
+ [q.question for q in public_questions]
)
order_positions = (
OrderPosition.objects.filter(
order__event=sender,
item__pk__in=sender.settings.get('public_registrations_items'),
order__testmode=(sender.testmode)
).exclude(
order__status=Order.STATUS_CANCELED
).order_by('order__datetime')
item__pk__in=sender.settings.get("public_registrations_items"),
order__testmode=(sender.testmode),
)
.exclude(order__status=Order.STATUS_CANCELED)
.order_by("order__datetime")
)
public_order_positions = [
op for op in order_positions
if op.meta_info_data.get('question_form_data', {}).get('public_registrations_public_registration')
op
for op in order_positions
if op.meta_info_data.get("question_form_data", {}).get(
"public_registrations_public_registration"
)
]
answers = QuestionAnswer.objects.filter(
orderposition__in=public_order_positions, question__in=public_questions
)
public_answers = {
(a.orderposition_id, a.question_id): a
for a in answers
}
public_answers = {(a.orderposition_id, a.question_id): a for a in answers}
public_registrations = [
{
'gr_url': get_gravatar_url(pop.attendee_email or pop.order.code, size=24, default="wavatar"),
'fields': (
[pop.item.name] if sender.settings.get('public_registrations_show_item_name') else []
) + (
[pop.attendee_name_cached] if sender.settings.get('public_registrations_show_attendee_name') else []
) + [
public_answers[(pop.pk, pq.pk)].answer if public_answers.get((pop.pk, pq.pk)) else ''
"gr_url": get_gravatar_url(
pop.attendee_email or pop.order.code, size=24, default="wavatar"
),
"fields": (
[pop.item.name]
if sender.settings.get("public_registrations_show_item_name")
else []
)
+ (
[pop.attendee_name_cached]
if sender.settings.get("public_registrations_show_attendee_name")
else []
)
+ [
public_answers[(pop.pk, pq.pk)].answer
if public_answers.get((pop.pk, pq.pk))
else ""
for pq in public_questions
],
}
for pop in public_order_positions
]
} for pop in public_order_positions
]
template = get_template('pretix_public_registrations/front_page.html')
return template.render({
'headers': headers,
'public_registrations': public_registrations
})
template = get_template("pretix_public_registrations/front_page.html")
return template.render(
{"headers": headers, "public_registrations": public_registrations}
)
@receiver(signal=process_response, dispatch_uid="public_registragions_csp_headers")
def add_public_registrations_csp_headers(sender, request=None, response=None, **kwargs):
if "event.index" in resolve(request.path_info).url_name:
response['Content-Security-Policy'] = "img-src https://secure.gravatar.com"
response["Content-Security-Policy"] = "img-src https://secure.gravatar.com"
return response
@receiver(signal=nav_event_settings, dispatch_uid="public_registrations_nav_settings")
def navbar_settings(sender, request=None, **kwargs):
url = resolve(request.path_info)
return [{
'label': _('Public registrations'),
'url': reverse('plugins:pretix_public_registrations:settings', kwargs={
'event': request.event.slug,
'organizer': request.organizer.slug,
}),
'active': url.namespace == 'plugins:pretix_public_registrations' and url.url_name == 'settings',
}]
return [
{
"label": _("Public registrations"),
"url": reverse(
"plugins:pretix_public_registrations:settings",
kwargs={
"event": request.event.slug,
"organizer": request.organizer.slug,
},
),
"active": url.namespace == "plugins:pretix_public_registrations"
and url.url_name == "settings",
}
]
@receiver(signal=event_copy_data, dispatch_uid="public_registrations_event_copy_data")
def event_copy_public_registrations_data(sender, other, item_map, question_map, **_):
sender.settings.set(
'public_registrations_items',
"public_registrations_items",
[
str(item_map[int(old_id)].pk)
for old_id in other.settings.get('public_registrations_items')
]
for old_id in other.settings.get("public_registrations_items")
],
)
sender.settings.set(
'public_registrations_questions',
"public_registrations_questions",
[
str(question_map[int(old_id)].pk)
for old_id in other.settings.get('public_registrations_questions')
]
for old_id in other.settings.get("public_registrations_questions")
],
)
......@@ -3,5 +3,9 @@ from django.conf.urls import url
from .views import PublicParticipationsView
urlpatterns = [
url(r'^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/public_participations/$', PublicParticipationsView.as_view(), name='settings')
url(
r"^control/event/(?P<organizer>[^/]+)/(?P<event>[^/]+)/public_participations/$",
PublicParticipationsView.as_view(),
name="settings",
)
]
from django.urls import reverse
from pretix.control.views.event import EventSettingsViewMixin, EventSettingsFormView
from pretix.base.models import Event
from pretix.control.views.event import EventSettingsFormView, EventSettingsViewMixin
from .forms import PublicRegistrationsForm
class PublicParticipationsView(EventSettingsViewMixin, EventSettingsFormView):
form_class = PublicRegistrationsForm
template_name = 'pretix_public_registrations/settings.html'
template_name = "pretix_public_registrations/settings.html"
def get_success_url(self, **kwargs):
return reverse('plugins:pretix_public_registrations:settings', kwargs={
'organizer': self.request.event.organizer.slug,
'event': self.request.event.slug,
})
return reverse(
"plugins:pretix_public_registrations:settings",
kwargs={
"organizer": self.request.event.organizer.slug,
"event": self.request.event.slug,
},
)
......@@ -7,46 +7,47 @@ from setuptools import setup, find_packages
from pretix_public_registrations import __version__
try:
with open(os.path.join(os.path.dirname(__file__), 'README.rst'), encoding='utf-8') as f:
with open(
os.path.join(os.path.dirname(__file__), "README.rst"), encoding="utf-8"
) as f:
long_description = f.read()
except Exception:
long_description = ''
long_description = ""
class CustomBuild(build):
def run(self):
management.call_command('compilemessages', verbosity=1)
management.call_command("compilemessages", verbosity=1)
build.run(self)
cmdclass = {
'build': CustomBuild
}
cmdclass = {"build": CustomBuild}
setup(
name='pretix-public-registrations',
name="pretix-public-registrations",
version=__version__,
description='This plugin will give the option to attendees of an event to mark their registration as public. Public registrations will be shown along their answers to questions marked as public by the organizers on a world-readable page.',
description="This plugin will give the option to attendees of an event to mark their registration as public. "
"Public registrations will be shown along their answers to questions marked as public by the organizers on a world-readable page.",
long_description=long_description,
keywords="pretix public registrations",
url="https://gitlab.fachschaften.org/kif/pretix-public-registrations",
project_urls={
"Bug Tracker": 'https://gitlab.fachschaften.org/kif/pretix-public-registrations/issues',
"Source Code": 'https://gitlab.fachschaften.org/kif/pretix-public-registrations/tree/master',
"Bug Tracker": "https://gitlab.fachschaften.org/kif/pretix-public-registrations/issues",
"Source Code": "https://gitlab.fachschaften.org/kif/pretix-public-registrations/tree/master",
},
author='Felix Schäfer, Dominik Weitz',
author_email='admin@kif.rocks',
license='MIT',
author="Felix Schäfer, Dominik Weitz",
author_email="admin@kif.rocks",
license="MIT",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Plugins",
"Framework :: Django",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3"
"Programming Language :: Python :: 3",
],
install_requires=['django-gravatar2'],
packages=find_packages(exclude=['tests', 'tests.*']),
install_requires=["django-gravatar2"],
packages=find_packages(exclude=["tests", "tests.*"]),
include_package_data=True,
cmdclass=cmdclass,
entry_points="""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment