forked from DGNum/gestioCOF
Prettify revente/subscribe
This commit is contained in:
parent
ba21de683b
commit
dbd017f680
5 changed files with 63 additions and 19 deletions
27
bda/forms.py
27
bda/forms.py
|
@ -1,5 +1,6 @@
|
|||
from django import forms
|
||||
from django.forms.models import BaseInlineFormSet
|
||||
from django.template import loader
|
||||
from django.utils import timezone
|
||||
|
||||
from bda.models import Attribution, Spectacle, SpectacleRevente
|
||||
|
@ -110,11 +111,32 @@ class AnnulForm(forms.Form):
|
|||
)
|
||||
|
||||
|
||||
class TemplateLabelField(forms.ModelMultipleChoiceField):
|
||||
"""
|
||||
Offers an option to render a label with Django template rendering
|
||||
"""
|
||||
|
||||
def __init__(self, template_name=None, context_object_name="obj", *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.template_name = template_name
|
||||
self.context_object_name = context_object_name
|
||||
|
||||
def label_from_instance(self, obj):
|
||||
if self.template_name is None:
|
||||
return super().label_from_instance(obj)
|
||||
else:
|
||||
return loader.render_to_string(
|
||||
self.template_name, context={self.context_object_name: obj}
|
||||
)
|
||||
|
||||
|
||||
class InscriptionReventeForm(forms.Form):
|
||||
spectacles = forms.ModelMultipleChoiceField(
|
||||
spectacles = TemplateLabelField(
|
||||
queryset=Spectacle.objects.none(),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
required=False,
|
||||
template_name="bda/forms/spectacle_label_table.html",
|
||||
context_object_name="spectacle",
|
||||
)
|
||||
|
||||
def __init__(self, tirage, *args, **kwargs):
|
||||
|
@ -122,6 +144,9 @@ class InscriptionReventeForm(forms.Form):
|
|||
self.fields["spectacles"].queryset = tirage.spectacle_set.select_related(
|
||||
"location"
|
||||
).filter(date__gte=timezone.now())
|
||||
self.fields[
|
||||
"spectacles"
|
||||
].widget.option_template_name = "bda/forms/spectacle_checkbox_table.html"
|
||||
|
||||
|
||||
class ReventeTirageAnnulForm(forms.Form):
|
||||
|
|
4
bda/templates/bda/forms/spectacle_checkbox_table.html
Normal file
4
bda/templates/bda/forms/spectacle_checkbox_table.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
<tr>
|
||||
<td><input type="{{ widget.type }}" name="{{ widget.name }}" {% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %}></td>
|
||||
{{ widget.label }}
|
||||
</tr>
|
4
bda/templates/bda/forms/spectacle_label_table.html
Normal file
4
bda/templates/bda/forms/spectacle_label_table.html
Normal file
|
@ -0,0 +1,4 @@
|
|||
<td>{{ spectacle.title }}</td>
|
||||
<td data-sort-value="{{ spectacle.timestamp }}">{{ spectacle.date }}</td>
|
||||
<td data-sort-value="{{ spectacle.location }}">{{ spectacle.location }}</td>
|
||||
<td data-sort-value="{{ spectacle.price |stringformat:".3f" }}">{{ spectacle.price |floatformat }}€</td>
|
|
@ -1,12 +1,12 @@
|
|||
{% extends "base_title.html" %}
|
||||
{% load bootstrap %}
|
||||
{% load staticfiles%}
|
||||
|
||||
{% block realcontent %}
|
||||
<h2>Inscriptions pour BdA-Revente</h2>
|
||||
<form action="" class="form-horizontal" method="post">
|
||||
<div class="bg-info text-info center-block">
|
||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
|
||||
Cochez les spectacles pour lesquels vous souhaitez recevoir un
|
||||
Cochez les spectacles pour lesquels vous souhaitez recevoir une
|
||||
notification quand une place est disponible en revente. <br />
|
||||
Lorsque vous validez vos choix, si un tirage au sort est en cours pour
|
||||
un des spectacles que vous avez sélectionné, vous serez automatiquement
|
||||
|
@ -21,26 +21,37 @@
|
|||
<button type="button"
|
||||
class="btn btn-primary"
|
||||
onClick="select(false)">Tout désélectionner</button>
|
||||
<table class="table table-striped stupidtable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th data-sort="string">Titre</th>
|
||||
<th data-sort="int">Date</th>
|
||||
<th data-sort="string">Lieu</th>
|
||||
<th data-sort="int">Prix</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for checkbox in form.spectacles %}{{ checkbox }}{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="multiple-checkbox">
|
||||
<ul>
|
||||
{% for checkbox in form.spectacles %}
|
||||
<li>{{ checkbox }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit"
|
||||
class="btn btn-primary"
|
||||
value="S'inscrire pour les places sélectionnées">
|
||||
</form>
|
||||
|
||||
<script type="text/javascript" src="{% static "js/joequery-Stupid-Table-Plugin/stupidtable.js" %}"></script>
|
||||
<script language="JavaScript">
|
||||
function select(check) {
|
||||
checkboxes = document.getElementsByName("spectacles");
|
||||
for(var i=0, n=checkboxes.length; i < n; i++) {
|
||||
checkboxes[i].checked = check;
|
||||
}
|
||||
}
|
||||
function select(check) {
|
||||
checkboxes = document.getElementsByName("spectacles");
|
||||
for(var i=0, n=checkboxes.length; i < n; i++) {
|
||||
checkboxes[i].checked = check;
|
||||
}
|
||||
}
|
||||
$(function(){
|
||||
$("table.stupidtable").stupidtable();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -569,18 +569,18 @@ def revente_subscribe(request, tirage_id):
|
|||
)
|
||||
# Messages
|
||||
if success:
|
||||
messages.success(request, "Ton inscription a bien été prise en compte")
|
||||
messages.success(request, "Votre inscription a bien été prise en compte")
|
||||
if deja_revente:
|
||||
messages.info(
|
||||
request,
|
||||
"Des reventes existent déjà pour certains de "
|
||||
"ces spectacles, vérifie les places "
|
||||
"ces spectacles, vérifiez les places "
|
||||
"disponibles sans tirage !",
|
||||
)
|
||||
if inscrit_revente:
|
||||
shows = map("<li>{!s}</li>".format, inscrit_revente)
|
||||
msg = (
|
||||
"Tu as été inscrit à des reventes en cours pour les spectacles "
|
||||
"Vous avez été inscrit·e à des reventes en cours pour les spectacles "
|
||||
"<ul>{:s}</ul>".format("\n".join(shows))
|
||||
)
|
||||
messages.info(request, msg, extra_tags="safe")
|
||||
|
|
Loading…
Reference in a new issue