rewrite the event view in a much cleaner way
- Cleaner code, no locals - Indentation in the template makes it readable!
This commit is contained in:
parent
fe06636502
commit
1a935523c6
2 changed files with 73 additions and 60 deletions
|
@ -1,57 +1,70 @@
|
|||
{% extends "gestion/base.html" %}
|
||||
|
||||
{% block titre %}{{ nom }}{% endblock %}
|
||||
{% block titre %}{{ event.nom.capitalize }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="viewevent">
|
||||
<h1>{{ nom }}</h1>
|
||||
<h4>Le {{ev.date}}{% if fin %} de {{ ev.debut|time:"H:i"}} à {{ ev.fin|time:"H:i" }} {%else %} à {{ ev.debut|time:"H:i" }} {%endif %}{{ ev.lieu }}</h4>
|
||||
{% if desc %}
|
||||
<p>{{ev.description|safe }}</p>
|
||||
<h1>{{ event.nom.capitalize }}</h1>
|
||||
<h4>
|
||||
Le {{ event.date }}
|
||||
{% if event.fin %}
|
||||
de {{ event.debut|time:"H:i"}} à {{ event.fin|time:"H:i" }}
|
||||
{% else %}
|
||||
à {{ event.debut|time:"H:i" }}
|
||||
{% endif %}
|
||||
{% if user.is_authenticated and ev.desc_users %}
|
||||
<p>{{ ev.desc_users|safe }}</p>
|
||||
{{ event.lieu }}
|
||||
</h4>
|
||||
{% if event.desciption %}
|
||||
<p>{{ event.description|safe }}</p>
|
||||
{% endif %}
|
||||
{% if user.is_authenticated and event.desc_users %}
|
||||
<p>{{ event.desc_users|safe }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<div id="actions">
|
||||
{% if user.profile.is_chef %}
|
||||
<p><a href="{% url "calendrier:edit_event" ev.id %}">Modifier l'événement</a></p>
|
||||
<p><a href="{% url "calendrier:delete_event" ev.id %}">Supprimer l'événement</a></p>
|
||||
<p><a href="{% url "calendrier:resend" ev.id %}">Renvoyer les mails</a></p>
|
||||
<p><a href="{% url "calendrier:edit_event" event.id %}">Modifier l'événement</a></p>
|
||||
<p><a href="{% url "calendrier:delete_event" event.id %}">Supprimer l'événement</a></p>
|
||||
<p><a href="{% url "calendrier:resend" event.id %}">Renvoyer les mails</a></p>
|
||||
{% endif %}
|
||||
<p><a href="{% url "calendrier:change-doodle-name" %}">Changer mon nom pour le doodle</a></p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
<div id="doodle">
|
||||
<h4>Participants</h4>
|
||||
<p><b>{{ nboui }}</b> ont répondu oui, <b>{{ nbpe }}</b> peut-être, et <b>{{ nbnon }}</b> non</p>
|
||||
<table>
|
||||
{% if part %}<tr>
|
||||
{% if participants %}
|
||||
<tr>
|
||||
<th>Ernestophoniste</th>
|
||||
<th>Réponse</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% for p in part %}
|
||||
{% for p in participants %}
|
||||
<tr>
|
||||
{% if p.participant.doodlename %}
|
||||
<td>{{ p.participant.doodlename }}</td>
|
||||
{% else %}
|
||||
<td>{{ p.participant.user.username }}</td>
|
||||
{% endif %}
|
||||
{% if p.reponse == "oui" %}<td class="oui"></td><td class="details">{{ p.details }}</td>
|
||||
{% elif p.reponse == "pe" %}<td class="pe"></td><td class="details">{{ p.details }}</td>
|
||||
{% elif p.reponse == "non" %}<td class="non"></td><td class="details">{{ p.details }}</td>
|
||||
{% else %}
|
||||
{% if p.reponse == "oui" %}
|
||||
<td class="oui"></td><td class="details">{{ p.details }}</td>
|
||||
{% elif p.reponse == "pe" %}
|
||||
<td class="pe"></td><td class="details">{{ p.details }}</td>
|
||||
{% elif p.reponse == "non" %}
|
||||
<td class="non"></td><td class="details">{{ p.details }}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% empty %}
|
||||
Pas de réponse pour l'instant
|
||||
{% endfor %}
|
||||
</table>
|
||||
<p><a href="{% url 'calendrier:reponse' id %}">Répondre à l'événement</a></p>
|
||||
<p><a href="{% url 'calendrier:reponse' event.id %}">Répondre à l'événement</a></p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -70,21 +70,21 @@ def calendar(request, pYear, pMonth):
|
|||
|
||||
|
||||
def view_event(request, id):
|
||||
ev = get_object_or_404(Event, id=id)
|
||||
if not request.user.is_authenticated and not ev.calendrier:
|
||||
event = get_object_or_404(Event, id=id)
|
||||
|
||||
# Restricted event, only erneso users can see it
|
||||
if not request.user.is_authenticated and not event.calendrier:
|
||||
return redirect(reverse('calendrier:home'))
|
||||
part = ev.participants_set.all()
|
||||
nom = ev.nom.capitalize
|
||||
fin = False
|
||||
desc = False
|
||||
nboui = len(part.filter(reponse="oui"))
|
||||
nbpe = len(part.filter(reponse="pe"))
|
||||
nbnon = len(part.filter(reponse="non"))
|
||||
if ev.fin:
|
||||
fin = True
|
||||
if ev.description:
|
||||
desc = True
|
||||
return render(request, 'calendrier/view_event.html', locals())
|
||||
|
||||
participants = event.participants_set.all()
|
||||
context = {
|
||||
"event": event,
|
||||
"participants": participants,
|
||||
"nboui": len(participants.filter(reponse="oui")),
|
||||
"nbpe": len(participants.filter(reponse="pe")),
|
||||
"nbnon": len(participants.filter(reponse="non")),
|
||||
}
|
||||
return render(request, 'calendrier/view_event.html', context=context)
|
||||
|
||||
|
||||
# XXX: Horrible nasty code duplication. Go to hell RikM
|
||||
|
|
Loading…
Reference in a new issue