on affiche le status des événements aux utilisateurs connectés

This commit is contained in:
Jean-Marie Favreau 2023-11-10 00:21:11 +01:00
parent 5538562397
commit 6e80291df8
5 changed files with 33 additions and 6 deletions

View File

@ -135,6 +135,14 @@ class Event(models.Model):
uniq_tags = uniq_tags | set(t)
return list(uniq_tags)
def is_draft(self):
return self.status == Event.STATUS.DRAFT
def is_published(self):
return self.status == Event.STATUS.PUBLISHED
def is_trash(self):
return self.status == Event.STATUS.TRASH
class EventSubmissionForm(models.Model):

View File

@ -1,5 +1,6 @@
{% load cat_extra %}
{% load event_extra %}
{% load utils_extra %}
{% load static %}
@ -32,7 +33,7 @@
{% if event.single_day and event.start_time %}
{{ event.start_time }}
{% endif %}
<a href="{{ event.get_absolute_url }}">{{ event.title }}</a>
<a href="{{ event.get_absolute_url }}">{{ event|picto_status }} {{ event.title }}</a>
</li>
{% endfor %}
</ul>
@ -54,7 +55,7 @@
{% if event.single_day and event.start_time %}
{{ event.start_time }}
{% endif %}
<a href="{{ daytag }}" data-target="event-{{ event.id }}" onClick="toggleModal(event)">{{ event.title }}</a>
{{ event|picto_status }} <a href="{{ daytag }}" data-target="event-{{ event.id }}" onClick="toggleModal(event)">{{ event.title }}</a>
<dialog id="event-{{ event.id }}">
{% include "agenda_culturel/event-inc.html" with event=event display="modal" close_button=1 filter=filter %}
</dialog>

View File

@ -21,7 +21,7 @@
{{ event.category | small_cat }}
{% if event.location %}<hgroup>{% endif %}
{% if display == "in list" %}<h2>{% else %}<h3>{% endif %}
{{ event|picto_status }}
<a href="{{ event.get_absolute_url }}">{{ event.title }}</a>
{% if display == "in list" %}</h2>{% else %}</h3>{% endif %}
{% if event.location %}
@ -50,7 +50,7 @@
class="close"
data-target="event-{{ event.id }}"
onClick="toggleModal(event)"></a>
<h3>{{ event.category | small_cat }} {{ event.title }}</h3>
<h3>{{ event.category | small_cat }} {{ event|picto_status }} {{ event.title }}</h3>
<p>
<svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
@ -70,7 +70,7 @@
<header>
{% include "agenda_culturel/ephemeris-inc.html" with event=event filter=filter %}
{{ event.category | small_cat }}
<h1>{{ event.title }}</h1>
<h1>{{ event|picto_status }} {{ event.title }}</h1>
<p><svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<use href="{% static 'images/feather-sprite.svg' %}#calendar" />
</svg>

View File

@ -1,6 +1,7 @@
from django import template
from django.utils.safestring import mark_safe
from django.templatetags.static import static
from agenda_culturel.models import Event
from django.db.models import Q
@ -22,3 +23,20 @@ def can_show_start_time(event):
@register.filter
def need_complete_display(event, display):
return event.end_day and event.end_day != event.start_day and (event.start_time or event.end_time or display == "in list by day")
def picto_from_name(name, datatooltip=""):
return mark_safe('<span data-tooltip="' + datatooltip + '"><svg width="1em" height="1em" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' + \
'<use href="' + static("images/feather-sprite.svg") + '#' + name + '" />' + \
'</svg></span>')
@register.filter
def picto_status(event):
if event.is_draft():
return picto_from_name("eye-off", "Brouillon")
elif event.is_trash():
return picto_from_name("trash", "À la poubelle")
else:
return ""

View File

@ -27,7 +27,7 @@ import unicodedata
def get_event_qs(request):
if request.user.is_authenticated:
return Event.objects.all()
return Event.objects.filter(~Q(status=Event.STATUS.TRASH))
else:
return Event.objects.filter(status=Event.STATUS.PUBLISHED)