internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: pretix/pretix

Issue:
External authentication without second login backend enabled not possible
When using multiple authentication backends, `nav-pills` are shown shown to select the authentication method. These buttons will replace the `backend` parameter for form based authentication methods. For `authentication_url`-based backends clicking the button will redirect to an external webpage.

We exclusively use an `authentication_url`-based backend, which results in the following login screen:

![image](https://user-images.githubusercontent.com/904824/70807661-495c5100-1dbe-11ea-87b8-609770c85497.png)

Since the `nav-pills` are not rendered, we are unable to redirect to the login page.

My suggestion would be to:
1. Hide the `Log In` button when no backends are used which are submitted using form fields.
2. Always show the `nav-pills` when the only available backend uses `authentication_url` based authentication.

External authentication without second login backend enabled not possible
When using multiple authentication backends, `nav-pills` are shown shown to select the authentication method. These buttons will replace the `backend` parameter for form based authentication methods. For `authentication_url`-based backends clicking the button will redirect to an external webpage.

We exclusively use an `authentication_url`-based backend, which results in the following login screen:

![image](https://user-images.githubusercontent.com/904824/70807661-495c5100-1dbe-11ea-87b8-609770c85497.png)

Since the `nav-pills` are not rendered, we are unable to redirect to the login page.

My suggestion would be to:
1. Hide the `Log In` button when no backends are used which are submitted using form fields.
2. Always show the `nav-pills` when the only available backend uses `authentication_url` based authentication.



Discussion:
> Hide the Log In button when no backends are used which are submitted using form fields.
> Always show the nav-pills when the only available backend uses authentication_url based authentication.

Agreed! Happy for a PR! ;)
> Hide the Log In button when no backends are used which are submitted using form fields.
> Always show the nav-pills when the only available backend uses authentication_url based authentication.

Agreed! Happy for a PR! ;)

Resolving patch:
diff --git a/src/pretix/base/forms/auth.py b/src/pretix/base/forms/auth.py
--- a/src/pretix/base/forms/auth.py
+++ b/src/pretix/base/forms/auth.py
@@ -32,7 +32,8 @@ def __init__(self, backend, request=None, *args, **kwargs):
         for k, f in backend.login_form_fields.items():
             self.fields[k] = f
 
-        if not settings.PRETIX_LONG_SESSIONS:
+        # Authentication backends which use urls cannot have long sessions.
+        if not settings.PRETIX_LONG_SESSIONS or backend.url:
             del self.fields['keep_logged_in']
         else:
             self.fields.move_to_end('keep_logged_in')


Test patch:
Repository: pretix/pretix

Issue:
Change text positioning in PDF layout editor
Currently, everything is positioned by its bottom-left corner. This makes it quite hard to align text with an unknown number of lines appropriately. We should to change this behaviour, but will need to somehow deal with backwards compatibility.


Discussion:

Resolving patch:
diff --git a/src/pretix/base/pdf.py b/src/pretix/base/pdf.py
--- a/src/pretix/base/pdf.py
+++ b/src/pretix/base/pdf.py
@@ -472,10 +472,21 @@ def _draw_textarea(self, canvas: Canvas, op: OrderPosition, order: Order, o: dic
         text = "<br/>".join(get_display(reshaper.reshape(l)) for l in text.split("<br/>"))
 
         p = Paragraph(text, style=style)
-        p.wrapOn(canvas, float(o['width']) * mm, 1000 * mm)
+        w, h = p.wrapOn(canvas, float(o['width']) * mm, 1000 * mm)
         # p_size = p.wrap(float(o['width']) * mm, 1000 * mm)
         ad = getAscentDescent(font, float(o['fontsize']))
-        p.drawOn(canvas, float(o['left']) * mm, float(o['bottom']) * mm - ad[1])
+        canvas.saveState()
+        # The ascent/descent offsets here are not really proven to be correct, they're just empirical values to get
+        # reportlab render similarly to browser canvas.
+        if o.get('downward', False):
+            canvas.translate(float(o['left']) * mm, float(o['bottom']) * mm)
+            canvas.rotate(o.get('rotation', 0) * -1)
+            p.drawOn(canvas, 0, -h - ad[1] / 2)
+        else:
+            canvas.translate(float(o['left']) * mm, float(o['bottom']) * mm + h)
+            canvas.rotate(o.get('rotation', 0) * -1)
+            p.drawOn(canvas, 0, -h - ad[1])
+        canvas.restoreState()
 
     def draw_page(self, canvas: Canvas, order: Order, op: OrderPosition):
         for o in self.layout:


Test patch:
Repository: pretix/pretix

Issue:
question type number should accept 0
when you make a question with the type number a reqired question it should accept the number 0. Currently it refuses:
![Selection_501](https://user-images.githubusercontent.com/111600/81524538-d85f9c00-9351-11ea-8d50-dc4a1c5c1e45.png)



Discussion:

Resolving patch:
diff --git a/src/pretix/base/forms/questions.py b/src/pretix/base/forms/questions.py
--- a/src/pretix/base/forms/questions.py
+++ b/src/pretix/base/forms/questions.py
@@ -550,7 +550,8 @@ def question_is_required(q):
 
         if not self.all_optional:
             for q in question_cache.values():
-                if question_is_required(q) and not d.get('question_%d' % q.pk):
+                answer = d.get('question_%d' % q.pk)
+                if question_is_required(q) and not answer and answer != 0:
                     raise ValidationError({'question_%d' % q.pk: [_('This field is required')]})
 
         return d
diff --git a/src/pretix/presale/checkoutflow.py b/src/pretix/presale/checkoutflow.py
--- a/src/pretix/presale/checkoutflow.py
+++ b/src/pretix/presale/checkoutflow.py
@@ -570,7 +570,7 @@ def question_is_required(q):
                 )
 
             for q in cp.item.questions_to_ask:
-                if question_is_required(q) and not answ.get(q.id):
+                if question_is_required(q) and q.id not in answ:
                     if warn:
                         messages.warning(request, _('Please fill in answers to all required questions.'))
                     return False


Test patch:
diff --git a/src/tests/presale/test_checkout.py b/src/tests/presale/test_checkout.py
--- a/src/tests/presale/test_checkout.py
+++ b/src/tests/presale/test_checkout.py
@@ -2660,7 +2660,7 @@ def test_questions(self):
         # Corrected request
         response = self.client.post('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), {
             '%s-question_%s' % (cr1.id, q1.id): '42',
-            '%s-question_%s' % (cr2.id, q1.id): '23',
+            '%s-question_%s' % (cr2.id, q1.id): '0',
             '%s-question_%s' % (cr1.id, q2.id): 'Internet',
             '%s-question_%s' % (cr2.id, q2.id): '',
             'email': 'admin@localhost'
@@ -2750,6 +2750,7 @@ def _setup_dependency_questions(self):
             event=self.event, question='Why not?', type=Question.TYPE_TEXT,
             required=True, dependency_question=self.q3, dependency_values=['False']
         )
+
         self.ticket.questions.add(self.q1)
         self.ticket.questions.add(self.q2a)
         self.ticket.questions.add(self.q2b)
Repository: pretix/pretix

Issue:
Wrong PositionId on imported Orders
When importing multiple OrderPositions into a single Order, the resulting OrderPositions will all have the same positionid `1`.
Wrong PositionId on imported Orders
When importing multiple OrderPositions into a single Order, the resulting OrderPositions will all have the same positionid `1`.


Discussion:

Resolving patch:
diff --git a/src/pretix/base/services/orderimport.py b/src/pretix/base/services/orderimport.py
--- a/src/pretix/base/services/orderimport.py
+++ b/src/pretix/base/services/orderimport.py
@@ -103,7 +103,7 @@ def import_orders(event: Event, fileid: str, settings: dict, locale: str, user)
                     order._address.name_parts = {'_scheme': event.settings.name_scheme}
                     orders.append(order)
 
-                position = OrderPosition()
+                position = OrderPosition(positionid=len(order._positions) + 1)
                 position.attendee_name_parts = {'_scheme': event.settings.name_scheme}
                 position.meta_info = {}
                 order._positions.append(position)


Test patch:
diff --git a/src/tests/base/test_orderimport.py b/src/tests/base/test_orderimport.py
--- a/src/tests/base/test_orderimport.py
+++ b/src/tests/base/test_orderimport.py
@@ -130,6 +130,7 @@ def test_import_as_one_order(user, event, item):
     assert event.orders.count() == 1
     o = event.orders.get()
     assert o.positions.count() == 3
+    assert set(pos.positionid for pos in o.positions.all()) == {1, 2, 3}
 
 
 @pytest.mark.django_db
Repository: pretix/pretix

Issue:
log level
I'm probably missing something, so please bear with me.

I followed the "small-scale manual" deployment guide.

`python -m pretix runperiodic` logs celery success messages at the info level:

`INFO 2019-01-03 20:49:47,479 celery.app.trace trace Task pretix.base.services.quotas.refresh_quota_caches[817c903c-ea12-491f-aa65-23b89e59075a] succeeded in 0.006468222010880709s: None
INFO 2019-01-03 20:49:47,606 celery.app.trace trace Task pretix.base.services.waitinglist.assign_automatically[db93ed55-5e42-4278-8647-3deefa0ea8dc] succeeded in 0.08206735923886299s: 0
`

This means I get a useless email from the cron job twice an hour, unless I set `loglevel` in `pretix/settings.py` to `WARNING`.

Is there a way to override the log level in pretix.cfg that I'm overlooking?
log level
I'm probably missing something, so please bear with me.

I followed the "small-scale manual" deployment guide.

`python -m pretix runperiodic` logs celery success messages at the info level:

`INFO 2019-01-03 20:49:47,479 celery.app.trace trace Task pretix.base.services.quotas.refresh_quota_caches[817c903c-ea12-491f-aa65-23b89e59075a] succeeded in 0.006468222010880709s: None
INFO 2019-01-03 20:49:47,606 celery.app.trace trace Task pretix.base.services.waitinglist.assign_automatically[db93ed55-5e42-4278-8647-3deefa0ea8dc] succeeded in 0.08206735923886299s: 0
`

This means I get a useless email from the cron job twice an hour, unless I set `loglevel` in `pretix/settings.py` to `WARNING`.

Is there a way to override the log level in pretix.cfg that I'm overlooking?


Discussion:
No, currently the log level is not configurable.
OK, thanks! I'm maintaining my local patch for now.

If you are interested in a PR, I would need to know in which direction logging configurability should go.
No, currently the log level is not configurable.
OK, thanks! I'm maintaining my local patch for now.

If you are interested in a PR, I would need to know in which direction logging configurability should go.

Resolving patch:
diff --git a/src/pretix/settings.py b/src/pretix/settings.py
--- a/src/pretix/settings.py
+++ b/src/pretix/settings.py
@@ -561,7 +561,7 @@
 }
 MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
 
-loglevel = 'DEBUG' if DEBUG else 'INFO'
+loglevel = 'DEBUG' if DEBUG else config.get('pretix', 'loglevel', fallback='INFO')
 
 LOGGING = {
     'version': 1,


Test patch:
Repository: pretix/pretix

Issue:
Control: list of products should list products with no category first
**Describe the bug**
In pretix-control under „Products“, products that belong to no category are listed last.

**Expected behavior**
As with the listing-behaviour in presale, products with no category should be listed first.

As discussed, `ORDER BY` with `NULLS FIRST` should do the trick.
Control: list of products should list products with no category first
**Describe the bug**
In pretix-control under „Products“, products that belong to no category are listed last.

**Expected behavior**
As with the listing-behaviour in presale, products with no category should be listed first.

As discussed, `ORDER BY` with `NULLS FIRST` should do the trick.


Discussion:

Resolving patch:
diff --git a/src/pretix/control/views/item.py b/src/pretix/control/views/item.py
--- a/src/pretix/control/views/item.py
+++ b/src/pretix/control/views/item.py
@@ -102,7 +102,8 @@ def get_queryset(self):
         ).annotate(
             var_count=Count('variations')
         ).prefetch_related("category").order_by(
-            'category__position', 'category', 'position'
+            F('category__position').desc(nulls_first=True),
+            'category', 'position'
         )
 
     def get_context_data(self, **kwargs):


Test patch:
Repository: pretix/pretix

Issue:
Default badge layout may be duplicated with event clone
<!-- Please only create issues for bug reports. Feature requests or general questions should start as a "Discussion" on GitHub. -->

**Describe the bug**
Given that pretix.cfg has the core badge plugin in the defaults:
```cfg
plugins_default=pretix.plugins.badges
```

Create a new event with "Copy configuration from" from an event which has the default layout. This will result in two layouts in the new event, as the `pretix.plugins.badges.apps.BadgesApp.installed` is called before the `event_copy_data` signal has been sent.

This is caused by the cloning of the data, before activation of all the plugins.

**Expected behavior**
Perhaps do not call `installed` for cloned events and move the `event.set_active_plugins(settings.PRETIX_PLUGINS_DEFAULT.split(","), allow_restricted=True)` to the else branch of:
https://github.com/pretix/pretix/blob/19881dff443c5503afaaedc9b06b5504b6a4346e/src/pretix/control/views/main.py#L296-L306

That would align with the note placed here:
https://github.com/pretix/pretix/blob/19881dff443c5503afaaedc9b06b5504b6a4346e/src/pretix/base/models/event.py#L707-L712

**Additional context**
The badges plugin is the only plugin bundled with Pretix that suffers from this bug, but our custom plugin that creates organizer based event defaults is also affected.


Discussion:

Resolving patch:
diff --git a/src/pretix/control/views/main.py b/src/pretix/control/views/main.py
--- a/src/pretix/control/views/main.py
+++ b/src/pretix/control/views/main.py
@@ -265,8 +265,6 @@ def done(self, form_list, form_dict, **kwargs):
             event.has_subevents = foundation_data['has_subevents']
             event.testmode = True
             form_dict['basics'].save()
-            event.set_active_plugins(settings.PRETIX_PLUGINS_DEFAULT.split(","), allow_restricted=settings.PRETIX_PLUGINS_DEFAULT.split(","))
-            event.save(update_fields=['plugins'])
             event.log_action(
                 'pretix.event.added',
                 user=self.request.user,
@@ -299,6 +297,9 @@ def done(self, form_list, form_dict, **kwargs):
             elif self.clone_from:
                 event.copy_data_from(self.clone_from)
             else:
+                event.set_active_plugins(settings.PRETIX_PLUGINS_DEFAULT.split(","),
+                                         allow_restricted=settings.PRETIX_PLUGINS_DEFAULT.split(","))
+                event.save(update_fields=['plugins'])
                 event.checkin_lists.create(
                     name=_('Default'),
                     all_products=True


Test patch:
Repository: pretix/pretix

Issue:
Cannot change month in the widget
In the current version it is not possible to change the month in the widget. When you hit it, it reloads but does nothing. The cause seems to be because the call https://XXXXX/widget/product_list?lang=es&year=2022&month=03 always returns the same regardless of the value you put in the month parameter.


Discussion:
Which version of pretix are you using exactly? Is the widget embedded on a public page we might have a look at? Can you try to clear your browser cache?

Unless we missed an edge case, this should already be fixed by https://github.com/pretix/pretix/commit/c8a830ecde186e7fe8862bda1410852de50e571b
I have installed 4.6.0 version. I tried in Edge, Chrome and Firefox and in two different computers and phones. 
You can view a example in  https://www.coruna.gal/bibliotecas/gl/actividades/persoais/actividades-nas-bibliotecas/detalle-evento/merendas-con-contos-as-illas-do-tesouro/suceso/1453776890580

I can confirm this is due to an old version of widget.js here, which uses month/week-GET-params instead of the newly introduced, normalized single date-GET-param – see method `reload` here: https://ticketing.coruna.gal/widget/v1.es.js

Have you made sure to update styles and scripts when installing 4.6.0? Calling `python -m pretix updatestyles` should do the trick.
It's works! Thanks a lot
I have the same problem on https://freiburg.esn-germany.de/events. Can't seem to change months, but I am loading the scripts https://pretix.eu/widget/v1.en.js and https://pretix.eu/demo/democon/widget/v1.css
I am looking into this. There seems to be an issue with parsing the date.

Resolving patch:
diff --git a/src/pretix/presale/views/organizer.py b/src/pretix/presale/views/organizer.py
--- a/src/pretix/presale/views/organizer.py
+++ b/src/pretix/presale/views/organizer.py
@@ -225,7 +225,7 @@ def _set_month_to_next_event(self):
     def _set_month_year(self):
         if 'date' in self.request.GET:
             try:
-                date = dateutil.parser.parse(self.request.GET.get('date')).date()
+                date = dateutil.parser.isoparse(self.request.GET.get('date')).date()
             except ValueError:
                 date = now().date()
             self.year = date.year


Test patch:
diff --git a/src/tests/presale/test_event.py b/src/tests/presale/test_event.py
--- a/src/tests/presale/test_event.py
+++ b/src/tests/presale/test_event.py
@@ -314,7 +314,7 @@ def test_subevent_calendar(self):
         resp = self.client.get('/%s/%s/' % (self.orga.slug, self.event.slug))
         self.assertIn("Foo SE2", resp.rendered_content)
         self.assertNotIn("Foo SE1", resp.rendered_content)
-        resp = self.client.get('/%s/%s/?date=%d-%d' % (self.orga.slug, self.event.slug, se1.date_from.year, se1.date_from.month))
+        resp = self.client.get('/%s/%s/?date=%d-%02d' % (self.orga.slug, self.event.slug, se1.date_from.year, se1.date_from.month))
         self.assertIn("Foo SE1", resp.rendered_content)
         self.assertNotIn("Foo SE2", resp.rendered_content)
Repository: pretix/pretix

Issue:
Error in single exporter form collapses all exporters
**Describe the bug**
When submitting the "checkinlistpdf" exporter, without a check-in list present, an error is created on all of the available forms. Due to the presence of the error on all forms, all exporters are shown, making it very confusing to see the actual problem with the exporter in use.

I've located https://github.com/pretix/pretix/commit/488273d5f2abd91910e89f01eae15ccf96d325a6 to introduce the current behaviour, however I'm not sure why the forms which were not submitted also render with `.has-error` on it's fields. 


**Expected behavior**
To have all exporters be closed, except for the one submitted.

**Screenshots**
![scrot-2022-03-17T17:54:06+01:00](https://user-images.githubusercontent.com/904824/158856244-9e848a25-54d8-49e9-b7d4-356d3c257f18.png)

**Additional context**
-


Discussion:
This bug has multiple levels. First it fills all exporterForms with POST-data without looking which exporter was selected. This makes it so that all forms are validated and get marked as having errors. Second, the JavaScript to open the `<details>` with forms that have errors seems to have a problem as well. I will look into this.
The problem wasn’t in thte JS, but in the template. Fix is on the way.

Resolving patch:
diff --git a/src/pretix/control/views/orders.py b/src/pretix/control/views/orders.py
--- a/src/pretix/control/views/orders.py
+++ b/src/pretix/control/views/orders.py
@@ -2229,8 +2229,9 @@ class ExportMixin:
     def exporters(self):
         exporters = []
         responses = register_data_exporters.send(self.request.event)
+        id = self.request.GET.get("identifier") or self.request.POST.get("exporter")
         for ex in sorted([response(self.request.event, self.request.organizer) for r, response in responses if response], key=lambda ex: str(ex.verbose_name)):
-            if self.request.GET.get("identifier") and ex.identifier != self.request.GET.get("identifier"):
+            if id and ex.identifier != id:
                 continue
 
             # Use form parse cycle to generate useful defaults


Test patch:
Repository: pretix/pretix

Issue:
Cloning an event with a configured mail_attachment_new_order does change its name
**Describe the bug**
#2384 did introduce the option to add an email attachment to order confirmation emails. Greatly appreciated for attaching legally required documents.
The original filename is persisted by adding a random string while storing to filesystem and removing it again (https://github.com/pretix/pretix/blob/master/src/pretix/base/services/mail.py#L462) when attaching the file to the order confirmation.
But when creating a new event based on an existing one, the filename is lost due to the copied filename being generically generated in https://github.com/pretix/pretix/blob/9101b5b69dd87a34169cd8a9c689cb70651d2014/src/pretix/base/models/event.py#L923.

**Expected behavior**
It is expected that when an event is created based on an existing one, that the `mail_attachment_new_order` original filename is preserved.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
I'm happy to do a PR by e.g. calling `clean_filename` and adding a new random string if the key of the `other.settings._object` is `mail_attachment_new_order`, while copying files https://github.com/pretix/pretix/blob/9101b5b69dd87a34169cd8a9c689cb70651d2014/src/pretix/base/models/event.py#L923 in `copy_data_from` method.


Discussion:

Resolving patch:
diff --git a/src/pretix/base/models/event.py b/src/pretix/base/models/event.py
--- a/src/pretix/base/models/event.py
+++ b/src/pretix/base/models/event.py
@@ -69,6 +69,7 @@
 from pretix.base.validators import EventSlugBanlistValidator
 from pretix.helpers.database import GroupConcat
 from pretix.helpers.daterange import daterange
+from pretix.helpers.hierarkey import clean_filename
 from pretix.helpers.json import safe_string
 from pretix.helpers.thumb import get_thumbnail
 
@@ -917,11 +918,13 @@ def _walk_rules(rules):
             s.object = self
             s.pk = None
             if s.value.startswith('file://'):
-                fi = default_storage.open(s.value[7:], 'rb')
+                fi = default_storage.open(s.value[len('file://'):], 'rb')
                 nonce = get_random_string(length=8)
+                fname_base = clean_filename(os.path.basename(s.value))
+
                 # TODO: make sure pub is always correct
                 fname = 'pub/%s/%s/%s.%s.%s' % (
-                    self.organizer.slug, self.slug, s.key, nonce, s.value.split('.')[-1]
+                    self.organizer.slug, self.slug, fname_base, nonce, s.value.split('.')[-1]
                 )
                 newname = default_storage.save(fname, fi)
                 s.value = 'file://' + newname


Test patch:
Repository: pretix/pretix

Issue:
Migrate to celery 5
after #2056 


Discussion:

Resolving patch:
diff --git a/src/setup.py b/src/setup.py
--- a/src/setup.py
+++ b/src/setup.py
@@ -162,7 +162,7 @@ def run(self):
         'babel',
         'BeautifulSoup4==4.11.*',
         'bleach==5.0.*',
-        'celery==4.4.*',
+        'celery==5.2.*',
         'chardet==5.1.*',
         'cryptography>=3.4.2',
         'css-inline==0.8.*',
@@ -193,7 +193,7 @@ def run(self):
         'drf_ujson2==1.7.*',
         'isoweek',
         'jsonschema',
-        'kombu==4.6.*',
+        'kombu==5.2.*',
         'libsass==0.22.*',
         'lxml',
         'markdown==3.3.4',  # 3.3.5 requires importlib-metadata>=4.4, but django-bootstrap3 requires importlib-metadata<3.


Test patch: