diff --git a/frappe/desk/doctype/event/event.py b/frappe/desk/doctype/event/event.py index 79442c4bdb5f043697140648e51f2b6d8a8fe310..8d11bf727ca6f479ec6f27a84337683a39037c2a 100644 --- a/frappe/desk/doctype/event/event.py +++ b/frappe/desk/doctype/event/event.py @@ -308,13 +308,34 @@ def get_list_context(context=None): def get_events_list(doctype, txt, filters, limit_start, limit_page_length=20, order_by="starts_on"): - return get_prepared_events( - "1900-01-01", - add_days(nowdate(), 365), + events = get_prepared_events( + "0001-01-01", + "9999-01-0", limit_start, limit_page_length, merge_recurrences=True, ) + # First, split the events into past and future + past_events = [] + future_events = [] + for event in events: + if event.get("event_status") == "past": + past_events.append(event) + else: + future_events.append(event) + + # Then, sort the past events in descending order + past_events = sorted(past_events, key=lambda x: x["starts_on"], reverse=True) + + # And the future events in ascending order + future_events = sorted(future_events, key=lambda x: x["starts_on"]) + + # Finally, return the past events first, then the future events + if not past_events: + return future_events + + title_past = frappe._dict(list_split=True, title=_("Past Event")) + return future_events + [title_past] + past_events @frappe.whitelist() @@ -468,13 +489,14 @@ def get_events( ) ) {additional_condition} - ORDER BY `tabEvent`.starts_on + ORDER BY {order_by} {limit_condition}""".format( additional_fields=additional_fields, tables=", ".join(tables), filter_condition=filter_condition, reminder_condition="AND coalesce(`tabEvent`.send_reminder, 0)=1" if for_reminder else "", limit_condition=f"LIMIT {limit_page_length} OFFSET {limit_start}" if limit_page_length else "", + order_by="`tabEvent`.starts_on desc" if limit_page_length else "`tabEvent`.starts_on", additional_condition=additional_condition or "", ), { diff --git a/frappe/desk/doctype/event/templates/event_row.html b/frappe/desk/doctype/event/templates/event_row.html index a69fb053de11b17ccd9344a1ca6bb879022ca7a8..afae2cc05d909e05f75ac85415fe5aab96160578 100644 --- a/frappe/desk/doctype/event/templates/event_row.html +++ b/frappe/desk/doctype/event/templates/event_row.html @@ -1,48 +1,51 @@ +{% if doc.list_split %} +

+ {{ doc.title }} +

+{% else %}
-
-
-
-
-
{{ doc.title or doc.name }} - {% if doc.event_status == 'past' %} - - {{ _("Past Event") }} - - {% else %} - - {{ _(doc.status) }} - - {% endif %} -
-
- {% if doc.ends_on and frappe.utils.getdate(doc.starts_on) != frappe.utils.getdate(doc.ends_on) %} - {{ frappe.utils.global_date_format(doc.starts_on) }} - – - {{ frappe.utils.global_date_format(doc.ends_on) }} - {% else %} - {{ frappe.utils.global_date_format(doc.starts_on) }} - {% endif %} -
-
- {% if doc.all_day %} - {{ _("All Day") }} - {% elif doc.ends_on %} - {{ frappe.utils.get_time(doc.starts_on).strftime("%H:%M") }} - – - {{ frappe.utils.get_time(doc.ends_on).strftime("%H:%M") }} - {% else %} - {{ frappe.utils.get_time(doc.starts_on).strftime("%H:%M") }} - {% endif %} - {% if doc.repeat %} - {{ doc.repeat }} - {% endif %} -
+ {% if doc.image %} + + {% endif %} +
+
+ {{ doc.title or doc.name }} + + {% if doc.event_status == 'past' %} + {# + {{ _("Past Event") }} + #} + {% else %} + + {{ _(doc.status) }} + + {% endif %} +
+
+ {% if doc.ends_on and frappe.utils.getdate(doc.starts_on) != frappe.utils.getdate(doc.ends_on) %} + {{ frappe.utils.global_date_format(doc.starts_on) }} + – + {{ frappe.utils.global_date_format(doc.ends_on) }} + {% else %} + {{ frappe.utils.global_date_format(doc.starts_on) }} + {% endif %} +
+
+ {% if doc.all_day %} + {{ _("All Day") }} + {% elif doc.ends_on %} + {{ frappe.utils.get_time(doc.starts_on).strftime("%H:%M") }} + – + {{ frappe.utils.get_time(doc.ends_on).strftime("%H:%M") }} + {% else %} + {{ frappe.utils.get_time(doc.starts_on).strftime("%H:%M") }} + {% endif %} + {% if doc.repeat %} + {{ doc.repeat }} + {% endif %}
@@ -61,9 +64,9 @@ {% endif %}
- \ No newline at end of file + +{% endif %}