forked from DGNum/gestioCOF
Add unsubscribe option + list of current draws
This commit is contained in:
parent
fccad5edee
commit
732e47707e
5 changed files with 126 additions and 11 deletions
50
bda/views.py
50
bda/views.py
|
@ -30,7 +30,7 @@ from bda.models import (
|
|||
from bda.algorithm import Algorithm
|
||||
from bda.forms import (
|
||||
TokenForm, ResellForm, AnnulForm, InscriptionReventeForm, SoldForm,
|
||||
InscriptionInlineFormSet,
|
||||
InscriptionInlineFormSet, ReventeTirageForm, ReventeTirageAnnulForm
|
||||
)
|
||||
|
||||
|
||||
|
@ -377,6 +377,7 @@ def revente(request, tirage_id):
|
|||
if not created:
|
||||
revente.seller = participant
|
||||
revente.date = timezone.now()
|
||||
revente.wanted = Participant.objects.none()
|
||||
revente.soldTo = None
|
||||
revente.notif_sent = False
|
||||
revente.tirage_done = False
|
||||
|
@ -442,6 +443,53 @@ def revente(request, tirage_id):
|
|||
"annulform": annulform, "resellform": resellform})
|
||||
|
||||
|
||||
@login_required
|
||||
def revente_tirages(request, tirage_id):
|
||||
tirage = get_object_or_404(Tirage, id=tirage_id)
|
||||
participant, _ = Participant.objects.get_or_create(
|
||||
user=request.user, tirage=tirage)
|
||||
unsub = 0
|
||||
subform = ReventeTirageForm(participant, prefix="subscribe")
|
||||
annulform = ReventeTirageAnnulForm(participant, prefix="annul")
|
||||
|
||||
if request.method == 'POST':
|
||||
if "subscribe" in request.POST:
|
||||
subform = ReventeTirageForm(participant, request.POST,
|
||||
prefix="subscribe")
|
||||
if subform.is_valid():
|
||||
sub = 0
|
||||
reventes = subform.cleaned_data['reventes']
|
||||
for revente in reventes:
|
||||
revente.answered_mail.add(participant)
|
||||
sub += 1
|
||||
if sub > 0:
|
||||
plural = "s" if sub > 1 else ""
|
||||
messages.success(
|
||||
request,
|
||||
"Tu as bien été inscrit à {} revente{}"
|
||||
.format(sub, plural)
|
||||
)
|
||||
elif "annul" in request.POST:
|
||||
annulform = ReventeTirageAnnulForm(participant, request.POST,
|
||||
prefix="annul")
|
||||
if annulform.is_valid():
|
||||
unsub = 0
|
||||
reventes = annulform.cleaned_data['reventes']
|
||||
for revente in reventes:
|
||||
revente.answered_mail.remove(participant)
|
||||
unsub += 1
|
||||
if unsub > 0:
|
||||
plural = "s" if unsub > 1 else ""
|
||||
messages.success(
|
||||
request,
|
||||
"Tu as bien été désinscrit de {} revente{}"
|
||||
.format(unsub, plural)
|
||||
)
|
||||
|
||||
return render(request, "bda/revente-tirages.html",
|
||||
{"annulform": annulform, "subform": subform})
|
||||
|
||||
|
||||
@login_required
|
||||
def revente_interested(request, revente_id):
|
||||
revente = get_object_or_404(SpectacleRevente, id=revente_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue