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 import forms
|
||||||
from django.forms.models import BaseInlineFormSet
|
from django.forms.models import BaseInlineFormSet
|
||||||
|
from django.template import loader
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from bda.models import Attribution, Spectacle, SpectacleRevente
|
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):
|
class InscriptionReventeForm(forms.Form):
|
||||||
spectacles = forms.ModelMultipleChoiceField(
|
spectacles = TemplateLabelField(
|
||||||
queryset=Spectacle.objects.none(),
|
queryset=Spectacle.objects.none(),
|
||||||
widget=forms.CheckboxSelectMultiple,
|
widget=forms.CheckboxSelectMultiple,
|
||||||
required=False,
|
required=False,
|
||||||
|
template_name="bda/forms/spectacle_label_table.html",
|
||||||
|
context_object_name="spectacle",
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self, tirage, *args, **kwargs):
|
def __init__(self, tirage, *args, **kwargs):
|
||||||
|
@ -122,6 +144,9 @@ class InscriptionReventeForm(forms.Form):
|
||||||
self.fields["spectacles"].queryset = tirage.spectacle_set.select_related(
|
self.fields["spectacles"].queryset = tirage.spectacle_set.select_related(
|
||||||
"location"
|
"location"
|
||||||
).filter(date__gte=timezone.now())
|
).filter(date__gte=timezone.now())
|
||||||
|
self.fields[
|
||||||
|
"spectacles"
|
||||||
|
].widget.option_template_name = "bda/forms/spectacle_checkbox_table.html"
|
||||||
|
|
||||||
|
|
||||||
class ReventeTirageAnnulForm(forms.Form):
|
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" %}
|
{% extends "base_title.html" %}
|
||||||
{% load bootstrap %}
|
{% load staticfiles%}
|
||||||
|
|
||||||
{% block realcontent %}
|
{% block realcontent %}
|
||||||
<h2>Inscriptions pour BdA-Revente</h2>
|
<h2>Inscriptions pour BdA-Revente</h2>
|
||||||
<form action="" class="form-horizontal" method="post">
|
<form action="" class="form-horizontal" method="post">
|
||||||
<div class="bg-info text-info center-block">
|
<div class="bg-info text-info center-block">
|
||||||
<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
|
<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 />
|
notification quand une place est disponible en revente. <br />
|
||||||
Lorsque vous validez vos choix, si un tirage au sort est en cours pour
|
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
|
un des spectacles que vous avez sélectionné, vous serez automatiquement
|
||||||
|
@ -21,26 +21,37 @@
|
||||||
<button type="button"
|
<button type="button"
|
||||||
class="btn btn-primary"
|
class="btn btn-primary"
|
||||||
onClick="select(false)">Tout désélectionner</button>
|
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>
|
</div>
|
||||||
<input type="submit"
|
<input type="submit"
|
||||||
class="btn btn-primary"
|
class="btn btn-primary"
|
||||||
value="S'inscrire pour les places sélectionnées">
|
value="S'inscrire pour les places sélectionnées">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="{% static "js/joequery-Stupid-Table-Plugin/stupidtable.js" %}"></script>
|
||||||
<script language="JavaScript">
|
<script language="JavaScript">
|
||||||
function select(check) {
|
function select(check) {
|
||||||
checkboxes = document.getElementsByName("spectacles");
|
checkboxes = document.getElementsByName("spectacles");
|
||||||
for(var i=0, n=checkboxes.length; i < n; i++) {
|
for(var i=0, n=checkboxes.length; i < n; i++) {
|
||||||
checkboxes[i].checked = check;
|
checkboxes[i].checked = check;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$(function(){
|
||||||
|
$("table.stupidtable").stupidtable();
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -569,18 +569,18 @@ def revente_subscribe(request, tirage_id):
|
||||||
)
|
)
|
||||||
# Messages
|
# Messages
|
||||||
if success:
|
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:
|
if deja_revente:
|
||||||
messages.info(
|
messages.info(
|
||||||
request,
|
request,
|
||||||
"Des reventes existent déjà pour certains de "
|
"Des reventes existent déjà pour certains de "
|
||||||
"ces spectacles, vérifie les places "
|
"ces spectacles, vérifiez les places "
|
||||||
"disponibles sans tirage !",
|
"disponibles sans tirage !",
|
||||||
)
|
)
|
||||||
if inscrit_revente:
|
if inscrit_revente:
|
||||||
shows = map("<li>{!s}</li>".format, inscrit_revente)
|
shows = map("<li>{!s}</li>".format, inscrit_revente)
|
||||||
msg = (
|
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))
|
"<ul>{:s}</ul>".format("\n".join(shows))
|
||||||
)
|
)
|
||||||
messages.info(request, msg, extra_tags="safe")
|
messages.info(request, msg, extra_tags="safe")
|
||||||
|
|
Loading…
Reference in a new issue