Repository: pretix/pretix

Issue:
listing of event with subevents on organizer page irritating
When creating an event with subevents you need to provide a `date_from` date. Since there are multiple dates, this can be used for the timespan the workshops take place in. For example, an art club does 4 painting workshops every February, it could set the event date from Feb 1st to Feb 28th and have the individual workshops as subevents with the actual start times. 

On the organizer page, events can be publicly listed. The issue is, that if you look at that page after the event `date_from` date, this event does not get listed as a future event, even though there might be subevents still in the future you want to sell tickets for. 

Similarly, this page does not list the event in "past events" when loading the page before `date_to`, even though there might be subevents in the past.

In this screenshot, the conference does not have subevents, but the workshop has multiple subevents in February.

![screenshot from 2018-01-03 18-08-13](https://user-images.githubusercontent.com/5970076/34530986-15af82d2-f0b1-11e7-950b-f986e948f426.png)

To fix this issue, the conditions when to show events with subevents in the future and past events lists need to be changed. Also there should be a way for a customer to see that there are multiple dates available. 

listing of event with subevents on organizer page irritating
When creating an event with subevents you need to provide a `date_from` date. Since there are multiple dates, this can be used for the timespan the workshops take place in. For example, an art club does 4 painting workshops every February, it could set the event date from Feb 1st to Feb 28th and have the individual workshops as subevents with the actual start times. 

On the organizer page, events can be publicly listed. The issue is, that if you look at that page after the event `date_from` date, this event does not get listed as a future event, even though there might be subevents still in the future you want to sell tickets for. 

Similarly, this page does not list the event in "past events" when loading the page before `date_to`, even though there might be subevents in the past.

In this screenshot, the conference does not have subevents, but the workshop has multiple subevents in February.

![screenshot from 2018-01-03 18-08-13](https://user-images.githubusercontent.com/5970076/34530986-15af82d2-f0b1-11e7-950b-f986e948f426.png)

To fix this issue, the conditions when to show events with subevents in the future and past events lists need to be changed. Also there should be a way for a customer to see that there are multiple dates available. 



Discussion:
Yeah, this is one of the issues with event series. In principle, the ``date_from`` and ``date_to`` attributes of an event series are rarely ever useful. That's why

* in the calendar view, we flatten the hierarchy and display subevents along with regular events. This is hard to do in a list, because it breaks pagination
* in the backend list view, we discard date_from and date_to and instead use the earliest and last contained subevent for filtering/ordering

While the first approach is obviously a bit more user-friendly, we could at least port the second one for now. This should be really easy to contribute, because one can just copy a lot from https://github.com/pretix/pretix/blob/master/src/pretix/control/views/main.py#L38
Hi, I want to solve this issue. Can you please help me how to make sub-events of an event. I know how to create an event, but I did not find out any option to make sub-events.
You need to select "event series" during event creation, subevents are named "dates" in the interface. You can read more here: https://docs.pretix.eu/en/latest/user/events/subevents.html
![screenshot-2018-1-15 create a new event pretix de](https://user-images.githubusercontent.com/5970076/34958732-6bdb250e-fa33-11e7-9fdf-5c3f96fb5796.png)

Make sure you tick "This is an event series". You will then be able to define multiple dates for a series of events who share most of the attributes, meaning that from a user's perspective, a normal event does not have subevents.
On the organizer page, all the events are not shown. Can you please tell me where is the problem:
![screenshot from 2018-01-16 19-08-37](https://user-images.githubusercontent.com/16673210/34991724-a1b55f10-faf0-11e7-9f3f-e5253e1cbcae.png)
![screenshot from 2018-01-16 19-08-53](https://user-images.githubusercontent.com/16673210/34991726-a422d994-faf0-11e7-9d8b-fd1b4656a3d0.png)


Do you have the `public` option enabled for all of them?

![screenshot-2018-1-16 painting workshop pretix de](https://user-images.githubusercontent.com/5970076/34992749-70133e0e-face-11e7-975c-6f93c9357f48.png)

I have done the changes in [https://github.com/pretix/pretix/blob/master/src/pretix/presale/views/organizer.py](url).

Output:
![screenshot from 2018-01-18 15-59-32](https://user-images.githubusercontent.com/16673210/35093456-71226a9a-fc68-11e7-9314-18382840a33c.png)
![screenshot from 2018-01-18 15-59-45](https://user-images.githubusercontent.com/16673210/35093461-7510845c-fc68-11e7-8a61-c0ea41180073.png)

Here workshop is a series event. Some sub-events are in past and some are upcoming, so it is showing workshop event in both upcoming and past events. Is this approach fine or something else is required.
Yeah, this is one of the issues with event series. In principle, the ``date_from`` and ``date_to`` attributes of an event series are rarely ever useful. That's why

* in the calendar view, we flatten the hierarchy and display subevents along with regular events. This is hard to do in a list, because it breaks pagination
* in the backend list view, we discard date_from and date_to and instead use the earliest and last contained subevent for filtering/ordering

While the first approach is obviously a bit more user-friendly, we could at least port the second one for now. This should be really easy to contribute, because one can just copy a lot from https://github.com/pretix/pretix/blob/master/src/pretix/control/views/main.py#L38
Hi, I want to solve this issue. Can you please help me how to make sub-events of an event. I know how to create an event, but I did not find out any option to make sub-events.
You need to select "event series" during event creation, subevents are named "dates" in the interface. You can read more here: https://docs.pretix.eu/en/latest/user/events/subevents.html
![screenshot-2018-1-15 create a new event pretix de](https://user-images.githubusercontent.com/5970076/34958732-6bdb250e-fa33-11e7-9fdf-5c3f96fb5796.png)

Make sure you tick "This is an event series". You will then be able to define multiple dates for a series of events who share most of the attributes, meaning that from a user's perspective, a normal event does not have subevents.
On the organizer page, all the events are not shown. Can you please tell me where is the problem:
![screenshot from 2018-01-16 19-08-37](https://user-images.githubusercontent.com/16673210/34991724-a1b55f10-faf0-11e7-9f3f-e5253e1cbcae.png)
![screenshot from 2018-01-16 19-08-53](https://user-images.githubusercontent.com/16673210/34991726-a422d994-faf0-11e7-9d8b-fd1b4656a3d0.png)


Do you have the `public` option enabled for all of them?

![screenshot-2018-1-16 painting workshop pretix de](https://user-images.githubusercontent.com/5970076/34992749-70133e0e-face-11e7-975c-6f93c9357f48.png)

I have done the changes in [https://github.com/pretix/pretix/blob/master/src/pretix/presale/views/organizer.py](url).

Output:
![screenshot from 2018-01-18 15-59-32](https://user-images.githubusercontent.com/16673210/35093456-71226a9a-fc68-11e7-9314-18382840a33c.png)
![screenshot from 2018-01-18 15-59-45](https://user-images.githubusercontent.com/16673210/35093461-7510845c-fc68-11e7-8a61-c0ea41180073.png)

Here workshop is a series event. Some sub-events are in past and some are upcoming, so it is showing workshop event in both upcoming and past events. Is this approach fine or something else is required.

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
@@ -100,7 +100,7 @@ def get_date_to_display(self, tz=None) -> str:
 
     def get_date_range_display(self, tz=None) -> str:
         """
-        Returns a formatted string containing the start date and the event date
+        Returns a formatted string containing the start date and the end date
         of the event with respect to the current locale and to the ``show_times`` and
         ``show_date_to`` settings.
         """
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
@@ -4,7 +4,8 @@
 
 import pytz
 from django.conf import settings
-from django.db.models import Exists, OuterRef, Q
+from django.db.models import Exists, Max, Min, OuterRef, Q
+from django.db.models.functions import Coalesce, Greatest
 from django.http import HttpResponse
 from django.utils.decorators import method_decorator
 from django.utils.timezone import now
@@ -98,17 +99,36 @@ def get(self, request, *args, **kwargs):
 
     def get_queryset(self):
         query = Q(is_public=True) & Q(live=True)
+        qs = self.request.organizer.events.filter(query)
+        qs = qs.annotate(
+            min_from=Min('subevents__date_from'),
+            min_to=Min('subevents__date_to'),
+            max_from=Max('subevents__date_from'),
+            max_to=Max('subevents__date_to'),
+            max_fromto=Greatest(Max('subevents__date_to'), Max('subevents__date_from')),
+        )
         if "old" in self.request.GET:
-            query &= Q(Q(date_from__lte=now()) & Q(date_to__lte=now()))
-            order = '-date_from'
+            qs = qs.filter(
+                Q(Q(has_subevents=False) & Q(
+                    Q(date_to__lt=now()) | Q(Q(date_to__isnull=True) & Q(date_from__lt=now()))
+                )) | Q(Q(has_subevents=True) & Q(
+                    Q(min_to__lt=now()) | Q(min_from__lt=now()))
+                )
+            ).annotate(
+                order_to=Coalesce('max_fromto', 'max_to', 'max_from', 'date_to', 'date_from'),
+            ).order_by('-order_to')
         else:
-            query &= Q(Q(date_from__gte=now()) | Q(date_to__gte=now()))
-            order = 'date_from'
-        qs = Event.objects.filter(
-            Q(organizer=self.request.organizer) & query
-        )
+            qs = qs.filter(
+                Q(Q(has_subevents=False) & Q(
+                    Q(date_to__gte=now()) | Q(Q(date_to__isnull=True) & Q(date_from__gte=now()))
+                )) | Q(Q(has_subevents=True) & Q(
+                    Q(max_to__gte=now()) | Q(max_from__gte=now()))
+                )
+            ).annotate(
+                order_from=Coalesce('min_from', 'date_from'),
+            ).order_by('order_from')
         qs = filter_qs_by_attr(qs, self.request)
-        return qs.order_by(order)
+        return qs
 
 
 def add_events_for_days(request, organizer, before, after, ebd, timezones):


Test patch: