From 5e5ac3bf31a9a719d991fd633ac2f55fe00fe3ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Thu, 9 Jul 2020 10:13:17 +0200
Subject: [PATCH 2/5] manager: factorize event template part (#44457)

---
 .../chrono/manager_agenda_event_fragment.html | 38 +++++++++++++++++++
 .../manager_events_agenda_month_view.html     | 36 +++---------------
 .../manager_events_agenda_settings.html       | 38 ++-----------------
 3 files changed, 47 insertions(+), 65 deletions(-)
 create mode 100644 chrono/manager/templates/chrono/manager_agenda_event_fragment.html

diff --git a/chrono/manager/templates/chrono/manager_agenda_event_fragment.html b/chrono/manager/templates/chrono/manager_agenda_event_fragment.html
new file mode 100644
index 0000000..5df240a
--- /dev/null
+++ b/chrono/manager/templates/chrono/manager_agenda_event_fragment.html
@@ -0,0 +1,38 @@
+{% load i18n %}
+<li class="{% if event.booked_places_count > event.places %}overbooking{% endif %}
+           {% if event.main_list_full %}full{% endif %}
+           {% if not event.in_bookable_period %}not-{% endif %}bookable"
+    {% if event.places %}
+      data-total="{{ event.places }}" data-booked="{{ event.booked_places_count }}"
+    {% elif event.waiting_list_places %}
+      data-total="{{ event.waiting_list_places }}" data-booked="{{ event.waiting_list_count }}"
+    {% endif %}
+    ><a href="{% if settings_view %}{% url 'chrono-manager-event-edit' pk=agenda.pk event_pk=event.pk %}?next=settings{% else %}{% url 'chrono-manager-event-view' pk=agenda.pk event_pk=event.pk %}{% endif %}">
+    {% if event.main_list_full %}<span class="full tag">{% trans "Full" %}</span>{% endif %}
+    {% if settings_view %}
+      {% if event.label %}{{ event.label }} {% endif %}[{% trans "identifier:" %} {{ event.slug }}]
+    {% else %}
+      {% if event.label %}{{ event.label }} / {% endif %}
+    {% endif %}
+    {{ event.start_datetime }}
+    (
+    {% if event.places %}
+    {% blocktrans with places=event.places booked_places=event.booked_places_count %}{{ places }} places, {{ booked_places }} booked places{% endblocktrans %}
+    {% endif %}
+    {% if event.places and event.waiting_list_places %} / {% endif %}
+    {% if event.waiting_list_places %}
+    {% blocktrans with places=event.waiting_list_places waiting_places=event.waiting_list_count %}
+    {{waiting_places}} on {{ places }} in waiting list
+    {% endblocktrans %}
+    {% endif %}
+    )
+    {% if settings_view and event.publication_date %}
+    ({% trans "publication date:" %} {{ event.publication_date }})
+    {% endif %}
+    {% if not event.in_bookable_period %}
+    ({% trans "out of bookable period" %})
+    {% endif %}
+        </a>
+    {% if settings_view %}<a rel="popup" class="delete" href="{% url 'chrono-manager-event-delete' pk=agenda.pk event_pk=event.pk %}?next=settings">{% trans "remove" %}</a>{% endif %}
+    <span class="occupation-bar"></span>
+</li>
diff --git a/chrono/manager/templates/chrono/manager_events_agenda_month_view.html b/chrono/manager/templates/chrono/manager_events_agenda_month_view.html
index a063ebc..15865c9 100644
--- a/chrono/manager/templates/chrono/manager_events_agenda_month_view.html
+++ b/chrono/manager/templates/chrono/manager_events_agenda_month_view.html
@@ -1,6 +1,10 @@
 {% extends "chrono/manager_agenda_month_view.html" %}
 {% load i18n %}
 
+{% block extra-actions %}
+<a href="{% url 'chrono-manager-agenda-opened-events-view' pk=agenda.pk %}">{% trans 'Opened events view' %}</a>
+{% endblock %}
+
 {% block content %}
 <div class="section">
 <h3>{% trans "Events" %}</h3>
@@ -8,36 +12,8 @@
 {% if object_list %}
   <ul class="objects-list single-links">
   {% for event in object_list %}
-    <li class="{% if event.booked_places_count > event.places %}overbooking{% endif %}
-               {% if event.main_list_full %}full{% endif %}
-               {% if not event.in_bookable_period %}not-{% endif %}bookable"
-        {% if event.places %}
-          data-total="{{event.places}}" data-booked="{{event.booked_places_count}}"
-        {% elif event.waiting_list_places %}
-          data-total="{{event.waiting_list_places}}" data-booked="{{event.waiting_list_count}}"
-        {% endif %}
-        ><a href="{% url 'chrono-manager-event-view' pk=agenda.id event_pk=event.id %}">
-        {% if event.main_list_full %}<span class="full tag">{% trans "Full" %}</span>{% endif %}
-        {% if event.label %}{{event.label}} / {% endif %}
-        {{ event.start_datetime }}
-        (
-        {% if event.places %}
-        {% blocktrans with places=event.places booked_places=event.booked_places_count %}{{ places }} places, {{ booked_places }} booked places{% endblocktrans %}
-        {% endif %}
-        {% if event.places and event.waiting_list_places %} / {% endif %}
-        {% if event.waiting_list_places %}
-        {% blocktrans with places=event.waiting_list_places waiting_places=event.waiting_list_count %}
-        {{waiting_places}} on {{ places }} in waiting list
-        {% endblocktrans %}
-        {% endif %}
-        )
-        {% if not event.in_bookable_period %}
-        ({% trans "out of bookable period" %})
-        {% endif %}
-            </a>
-        <span class="occupation-bar"></span>
-    </li>
-    {% endfor %}
+    {% include 'chrono/manager_agenda_event_fragment.html' %}
+  {% endfor %}
   </ul>
   {% include "gadjo/pagination.html" %}
 {% else %}
diff --git a/chrono/manager/templates/chrono/manager_events_agenda_settings.html b/chrono/manager/templates/chrono/manager_events_agenda_settings.html
index de72ffb..e9567aa 100644
--- a/chrono/manager/templates/chrono/manager_events_agenda_settings.html
+++ b/chrono/manager/templates/chrono/manager_events_agenda_settings.html
@@ -14,41 +14,9 @@
 {% with view.get_events as events %}
 {% if events %}
   <ul class="objects-list single-links">
-    {% for event in events %}
-    <li class="{% if event.booked_places_count > event.places %}overbooking{% endif %}
-               {% if event.main_list_full %}full{% endif %}
-               {% if not event.in_bookable_period %}not-{% endif %}bookable"
-        {% if event.places %}
-          data-total="{{event.places}}" data-booked="{{event.booked_places_count}}"
-        {% elif event.waiting_list_places %}
-          data-total="{{event.waiting_list_places}}" data-booked="{{event.waiting_list_count}}"
-        {% endif %}
-        ><a rel="popup" href="{% url 'chrono-manager-event-edit' pk=agenda.id event_pk=event.id %}?next=settings">
-        {% if event.main_list_full %}<span class="full tag">{% trans "Full" %}</span>{% endif %}
-        {% if event.label %}{{event.label}} {% endif %}[{% trans "identifier:" %} {{ event.slug }}]
-        {{ event.start_datetime }}
-        (
-        {% if event.places %}
-        {% blocktrans with places=event.places booked_places=event.booked_places_count %}{{ places }} places, {{ booked_places }} booked places{% endblocktrans %}
-        {% endif %}
-        {% if event.places and event.waiting_list_places %} / {% endif %}
-        {% if event.waiting_list_places %}
-        {% blocktrans with places=event.waiting_list_places waiting_places=event.waiting_list_count %}
-        {{waiting_places}} on {{ places }} in waiting list
-        {% endblocktrans %}
-        {% endif %}
-        )
-        {% if event.publication_date %}
-        ({% trans "publication date:" %} {{ event.publication_date }})
-        {% endif %}
-        {% if not event.in_bookable_period %}
-        ({% trans "out of bookable period" %})
-        {% endif %}
-            </a>
-        <a rel="popup" class="delete" href="{% url 'chrono-manager-event-delete' pk=agenda.id event_pk=event.id %}?next=settings">{% trans "remove" %}</a>
-        <span class="occupation-bar"></span>
-    </li>
-    {% endfor %}
+  {% for event in events %}
+    {% with settings_view=True %}{% include 'chrono/manager_agenda_event_fragment.html' %}{% endwith %}
+  {% endfor %}
   </ul>
 {% else %}
 <div class="big-msg-info">
-- 
2.20.1

