diff --git a/bda/forms.py b/bda/forms.py index 94a52128..bb79932e 100644 --- a/bda/forms.py +++ b/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 @@ -38,142 +39,146 @@ class TokenForm(forms.Form): token = forms.CharField(widget=forms.widgets.Textarea()) -class AttributionModelMultipleChoiceField(forms.ModelMultipleChoiceField): - def label_from_instance(self, obj): - return str(obj.spectacle) +class TemplateLabelField(forms.ModelMultipleChoiceField): + """ + Extends ModelMultipleChoiceField to offer two more customization options : + - `label_from_instance` can be used with a template file + - the widget rendering template can be specified with `option_template_name` + """ - -class ReventeModelMultipleChoiceField(forms.ModelMultipleChoiceField): - def __init__(self, *args, own=True, **kwargs): + def __init__( + self, + label_template_name=None, + context_object_name="obj", + option_template_name=None, + *args, + **kwargs + ): super().__init__(*args, **kwargs) - self.own = own + self.label_template_name = label_template_name + self.context_object_name = context_object_name + if option_template_name is not None: + self.widget.option_template_name = option_template_name def label_from_instance(self, obj): - label = "{show}{suffix}" - suffix = "" - if self.own: - # C'est notre propre revente : informations sur le statut - if obj.soldTo is not None: - suffix = " -- Vendue à {firstname} {lastname}".format( - firstname=obj.soldTo.user.first_name, - lastname=obj.soldTo.user.last_name, - ) - elif obj.shotgun: - suffix = " -- Tirage infructueux" - elif obj.notif_sent: - suffix = " -- Inscriptions au tirage en cours" + if self.label_template_name is None: + return super().label_from_instance(obj) else: - # Ce n'est pas à nous : on ne voit jamais l'acheteur - suffix = " -- Vendue par {firstname} {lastname}".format( - firstname=obj.seller.user.first_name, lastname=obj.seller.user.last_name + return loader.render_to_string( + self.label_template_name, context={self.context_object_name: obj} ) - return label.format(show=str(obj.attribution.spectacle), suffix=suffix) + +# Formulaires pour revente_manage class ResellForm(forms.Form): - attributions = AttributionModelMultipleChoiceField( - label="", - queryset=Attribution.objects.none(), - widget=forms.CheckboxSelectMultiple, - required=False, - ) - def __init__(self, participant, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["attributions"].queryset = ( - participant.attribution_set.filter(spectacle__date__gte=timezone.now()) + self.fields["attributions"] = TemplateLabelField( + queryset=participant.attribution_set.filter( + spectacle__date__gte=timezone.now() + ) .exclude(revente__seller=participant) - .select_related("spectacle", "spectacle__location", "participant__user") + .select_related("spectacle", "spectacle__location", "participant__user"), + widget=forms.CheckboxSelectMultiple, + required=False, + label_template_name="bda/forms/attribution_label_table.html", + option_template_name="bda/forms/checkbox_table.html", + context_object_name="attribution", ) class AnnulForm(forms.Form): - reventes = ReventeModelMultipleChoiceField( - own=True, - label="", - queryset=Attribution.objects.none(), - widget=forms.CheckboxSelectMultiple, - required=False, - ) - def __init__(self, participant, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["reventes"].queryset = ( - participant.original_shows.filter( + self.fields["reventes"] = TemplateLabelField( + label="", + queryset=participant.original_shows.filter( attribution__spectacle__date__gte=timezone.now(), soldTo__isnull=True ) .select_related( "attribution__spectacle", "attribution__spectacle__location" ) - .order_by("-date") - ) - - -class InscriptionReventeForm(forms.Form): - spectacles = forms.ModelMultipleChoiceField( - queryset=Spectacle.objects.none(), - widget=forms.CheckboxSelectMultiple, - required=False, - ) - - def __init__(self, tirage, *args, **kwargs): - super().__init__(*args, **kwargs) - self.fields["spectacles"].queryset = tirage.spectacle_set.select_related( - "location" - ).filter(date__gte=timezone.now()) - - -class ReventeTirageAnnulForm(forms.Form): - reventes = ReventeModelMultipleChoiceField( - own=False, - label="", - queryset=SpectacleRevente.objects.none(), - widget=forms.CheckboxSelectMultiple, - required=False, - ) - - def __init__(self, participant, *args, **kwargs): - super().__init__(*args, **kwargs) - self.fields["reventes"].queryset = participant.entered.filter( - soldTo__isnull=True - ).select_related("attribution__spectacle", "seller__user") - - -class ReventeTirageForm(forms.Form): - reventes = ReventeModelMultipleChoiceField( - own=False, - label="", - queryset=SpectacleRevente.objects.none(), - widget=forms.CheckboxSelectMultiple, - required=False, - ) - - def __init__(self, participant, *args, **kwargs): - super().__init__(*args, **kwargs) - self.fields["reventes"].queryset = ( - SpectacleRevente.objects.filter( - notif_sent=True, shotgun=False, tirage_done=False - ) - .exclude(confirmed_entry=participant) - .select_related("attribution__spectacle") + .order_by("-date"), + widget=forms.CheckboxSelectMultiple, + required=False, + label_template_name="bda/forms/revente_self_label_table.html", + option_template_name="bda/forms/checkbox_table.html", + context_object_name="revente", ) class SoldForm(forms.Form): - reventes = ReventeModelMultipleChoiceField( - own=True, - label="", - queryset=Attribution.objects.none(), - widget=forms.CheckboxSelectMultiple, - ) - def __init__(self, participant, *args, **kwargs): super().__init__(*args, **kwargs) - self.fields["reventes"].queryset = ( - participant.original_shows.filter(soldTo__isnull=False) + self.fields["reventes"] = TemplateLabelField( + queryset=participant.original_shows.filter(soldTo__isnull=False) .exclude(soldTo=participant) .select_related( "attribution__spectacle", "attribution__spectacle__location" - ) + ), + widget=forms.CheckboxSelectMultiple, + label_template_name="bda/forms/revente_sold_label_table.html", + option_template_name="bda/forms/checkbox_table.html", + context_object_name="revente", + ) + + +# Formulaire pour revente_subscribe + + +class InscriptionReventeForm(forms.Form): + def __init__(self, tirage, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["spectacles"] = TemplateLabelField( + queryset=tirage.spectacle_set.select_related("location").filter( + date__gte=timezone.now() + ), + widget=forms.CheckboxSelectMultiple, + required=False, + label_template_name="bda/forms/spectacle_label_table.html", + option_template_name="bda/forms/checkbox_table.html", + context_object_name="spectacle", + ) + + +# Formulaires pour revente_tirages + + +class ReventeTirageAnnulForm(forms.Form): + def __init__(self, participant, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["reventes"] = TemplateLabelField( + queryset=participant.entered.filter(soldTo__isnull=True).select_related( + "attribution__spectacle", "seller__user" + ), + widget=forms.CheckboxSelectMultiple, + required=False, + label_template_name="bda/forms/revente_other_label_table.html", + option_template_name="bda/forms/checkbox_table.html", + context_object_name="revente", + ) + + +class ReventeTirageForm(forms.Form): + def __init__(self, participant, *args, **kwargs): + super().__init__(*args, **kwargs) + + self.fields["reventes"] = TemplateLabelField( + queryset=( + SpectacleRevente.objects.filter( + notif_sent=True, + shotgun=False, + tirage_done=False, + attribution__spectacle__tirage=participant.tirage, + ) + .exclude(confirmed_entry=participant) + .select_related("attribution__spectacle") + ), + widget=forms.CheckboxSelectMultiple, + required=False, + label_template_name="bda/forms/revente_other_label_table.html", + option_template_name="bda/forms/checkbox_table.html", + context_object_name="revente", ) diff --git a/bda/templates/bda/forms/attribution_label_table.html b/bda/templates/bda/forms/attribution_label_table.html new file mode 100644 index 00000000..b50b8290 --- /dev/null +++ b/bda/templates/bda/forms/attribution_label_table.html @@ -0,0 +1 @@ +{% include 'bda/forms/spectacle_label_table.html' with spectacle=attribution.spectacle %} \ No newline at end of file diff --git a/bda/templates/bda/forms/checkbox_table.html b/bda/templates/bda/forms/checkbox_table.html new file mode 100644 index 00000000..e13a9c9d --- /dev/null +++ b/bda/templates/bda/forms/checkbox_table.html @@ -0,0 +1,4 @@ + + + {{ widget.label }} + \ No newline at end of file diff --git a/bda/templates/bda/forms/date_tirage.html b/bda/templates/bda/forms/date_tirage.html new file mode 100644 index 00000000..98b1c5e1 --- /dev/null +++ b/bda/templates/bda/forms/date_tirage.html @@ -0,0 +1 @@ +{{ revente.date_tirage }} diff --git a/bda/templates/bda/forms/revente_other_label_table.html b/bda/templates/bda/forms/revente_other_label_table.html new file mode 100644 index 00000000..99c82a08 --- /dev/null +++ b/bda/templates/bda/forms/revente_other_label_table.html @@ -0,0 +1,3 @@ +{% include 'bda/forms/spectacle_label_table.html' with spectacle=revente.attribution.spectacle %} +{% with user=revente.seller.user %} {{user.first_name}} {{user.last_name}} {% endwith%} +{% include 'bda/forms/date_tirage.html' %} \ No newline at end of file diff --git a/bda/templates/bda/forms/revente_self_label_table.html b/bda/templates/bda/forms/revente_self_label_table.html new file mode 100644 index 00000000..3f32b114 --- /dev/null +++ b/bda/templates/bda/forms/revente_self_label_table.html @@ -0,0 +1,2 @@ +{% include 'bda/forms/spectacle_label_table.html' with spectacle=revente.attribution.spectacle %} +{% include 'bda/forms/date_tirage.html' %} \ No newline at end of file diff --git a/bda/templates/bda/forms/revente_sold_label_table.html b/bda/templates/bda/forms/revente_sold_label_table.html new file mode 100644 index 00000000..31777648 --- /dev/null +++ b/bda/templates/bda/forms/revente_sold_label_table.html @@ -0,0 +1,4 @@ +{% include 'bda/forms/spectacle_label_table.html' with spectacle=revente.attribution.spectacle %} +{% with user=revente.soldTo.user %} +{{user.first_name}} {{user.last_name}} +{% endwith %} \ No newline at end of file diff --git a/bda/templates/bda/forms/spectacle_label_table.html b/bda/templates/bda/forms/spectacle_label_table.html new file mode 100644 index 00000000..a2c4181f --- /dev/null +++ b/bda/templates/bda/forms/spectacle_label_table.html @@ -0,0 +1,4 @@ +{{ spectacle.title }} +{{ spectacle.date }} +{{ spectacle.location }} +{{ spectacle.price |floatformat }}€ \ No newline at end of file diff --git a/bda/templates/bda/revente/manage.html b/bda/templates/bda/revente/manage.html index 5147ff16..afd3a40f 100644 --- a/bda/templates/bda/revente/manage.html +++ b/bda/templates/bda/revente/manage.html @@ -1,35 +1,45 @@ {% extends "base_title.html" %} -{% load bootstrap %} +{% load staticfiles %} {% block realcontent %}

Gestion des places que je revends

-{% with resell_attributions=resellform.attributions annul_reventes=annulform.reventes sold_reventes=soldform.reventes %} -{% if resell_attributions %} +{% if resell_exists %}

Places non revendues

-
- - Cochez les places que vous souhaitez revendre, et validez. Vous aurez - ensuite 1h pour changer d'avis avant que la revente soit confirmée et - que les notifications soient envoyées aux intéressé·e·s. -
-
- {% csrf_token %} - {{ resellform|bootstrap }} -
-
- -
+
+ + Cochez les places que vous souhaitez revendre, et validez. Vous aurez + ensuite 1h pour changer d'avis avant que la revente soit confirmée et + que les notifications soient envoyées aux intéressé·e·s. +
+ {% csrf_token %} + + + + + + + + + + + + {% for checkbox in resellform.attributions %}{{ checkbox }}{% endfor %} + +
TitreLieuDatePrix
+
+ +

{% endif %} -{% if annul_reventes %} +{% if annul_exists %}

Places en cours de revente

@@ -37,44 +47,76 @@ Vous pouvez annuler les reventes qui n'ont pas encore trouvé preneur·se.
{% csrf_token %} -
-
-
    - {% for revente in annul_reventes %} -
  • {{ revente.tag }} {{ revente.choice_label }}
  • - {% endfor %} -
-
-
+ + + + + + + + + + + + + {% for checkbox in annulform.reventes %}{{ checkbox }}{% endfor %} + +
TitreDateLieuPrixTirage le

{% endif %} -{% if sold_reventes %} +{% if sold_exists %}

Places revendues

-
- - Pour chaque revente, vous devez soit l'annuler soit la confirmer pour - transférer la place la place à la personne tirée au sort. +
+ + Pour chaque revente, vous devez soit l'annuler soit la confirmer pour + transférer la place la place à la personne tirée au sort. - L'annulation sert par exemple à pouvoir remettre la place en jeu si - vous ne parvenez pas à entrer en contact avec la personne tirée au - sort. -
-
- {% csrf_token %} - {{ soldform|bootstrap }} -
+ L'annulation sert par exemple à pouvoir remettre la place en jeu si + vous ne parvenez pas à entrer en contact avec la personne tirée au + sort. +
+ {% csrf_token %} + + + + + + + + + + + + + {% for checkbox in soldform.reventes %}{{ checkbox }}{% endfor %} + +
TitreDateLieuPrixVendue à
{% endif %} -{% if not resell_attributions and not annul_reventes and not sold_reventes %} +{% if not resell_exists and not annul_exists and not sold_exists %}

Plus de reventes possibles !

{% endif %} -{% endwith %} + + + {% endblock %} diff --git a/bda/templates/bda/revente/shotgun.html b/bda/templates/bda/revente/shotgun.html index fae36c04..a724032e 100644 --- a/bda/templates/bda/revente/shotgun.html +++ b/bda/templates/bda/revente/shotgun.html @@ -2,11 +2,26 @@ {% block realcontent %}

Places disponibles immédiatement

- {% if shotgun %} -