From fbb764615d9bfdf19b51a99dac01f0c70a3f89f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felix=20Sch=C3=A4fer?= <felix@thegcat.net>
Date: Sat, 12 Feb 2022 20:59:53 +0100
Subject: [PATCH] Apply black, isort

---
 pretix_public_registrations/__init__.py |  16 +-
 pretix_public_registrations/forms.py    |  16 +-
 pretix_public_registrations/signals.py  | 200 ++++++++++++++----------
 pretix_public_registrations/urls.py     |   6 +-
 pretix_public_registrations/views.py    |  16 +-
 setup.py                                |  33 ++--
 6 files changed, 167 insertions(+), 120 deletions(-)

diff --git a/pretix_public_registrations/__init__.py b/pretix_public_registrations/__init__.py
index 0ea0b8f..bb61b3f 100644
--- a/pretix_public_registrations/__init__.py
+++ b/pretix_public_registrations/__init__.py
@@ -1,4 +1,5 @@
 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"
diff --git a/pretix_public_registrations/forms.py b/pretix_public_registrations/forms.py
index 3d3ac83..68b496e 100644
--- a/pretix_public_registrations/forms.py
+++ b/pretix_public_registrations/forms.py
@@ -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()
         ]
diff --git a/pretix_public_registrations/signals.py b/pretix_public_registrations/signals.py
index 78399d6..35f9a4a 100644
--- a/pretix_public_registrations/signals.py
+++ b/pretix_public_registrations/signals.py
@@ -1,148 +1,184 @@
 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'),
-        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)},
-    )}
+        (
+            [_("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)},
+        )
+    }
 
 
 @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(
-        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')
+        (
+            [_("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")
+    )
     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")
+        ],
     )
diff --git a/pretix_public_registrations/urls.py b/pretix_public_registrations/urls.py
index 74daa86..bfefc96 100644
--- a/pretix_public_registrations/urls.py
+++ b/pretix_public_registrations/urls.py
@@ -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",
+    )
 ]
diff --git a/pretix_public_registrations/views.py b/pretix_public_registrations/views.py
index 05acfbd..18db1a6 100644
--- a/pretix_public_registrations/views.py
+++ b/pretix_public_registrations/views.py
@@ -1,16 +1,18 @@
 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,
+            },
+        )
diff --git a/setup.py b/setup.py
index 03ca060..b8901e5 100644
--- a/setup.py
+++ b/setup.py
@@ -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="""
-- 
GitLab