def challenge_edit(request, challenge_id): user = request.user challenge = get_object_or_404(Challenge, pk=challenge_id) if challenge.status == CHALLENGE_STATUS.COMPLETED: raise Http501 form = EditChallengeForm( user, request.POST or None, request.FILES or None, instance=challenge) #save button clicked if request.method == "POST": if form.is_valid(): form.save() if "delete" in request.POST: challenge.is_deleted = True challenge.save() return redirect(challenge.get_absolute_url()) return render_to_response('challenge_edit.html', RequestContext(request, {'form': form}))
def challenge_edit(request, challenge_id): user = request.user challenge = get_object_or_404(Challenge, pk=challenge_id) if challenge.status == CHALLENGE_STATUS.COMPLETED: raise Http501 form = EditChallengeForm(user, request.POST or None, request.FILES or None, instance=challenge) if request.method == "POST": if form.is_valid(): form.save() participations = Participation.objects.all().filter( Q(challenge=challenge) & (Q(status=PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION) | Q(status=PARTICIPATION_STATE.CONFIRMED)) ) waited = Participation.objects.all().filter( Q(challenge=challenge) & Q(status=PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION) ) if "delete" in request.POST: challenge.is_deleted = True challenge.save() for participation in participations: send_templated_mail( template_name="challenge_deleted", from_email="*****@*****.**", recipient_list=[participation.user.email], context={"user": participation.user, "challenge": participation.challenge}, ) # is_date_time_changed: elif "start_date" in form.changed_data or "start_time" in form.changed_data: for participation in participations: send_templated_mail( template_name="challenge_changed", from_email="*****@*****.**", recipient_list=[participation.user.email], context={"user": participation.user, "challenge": participation.challenge}, ) # is_application_changed: if "application" in form.changed_data and challenge.application == CHALLENGE_MODE.FREE_FOR_ALL: for participation in waited: participation.status = PARTICIPATION_STATE.CONFIRMED participation.date_accepted = datetime.now() participation.save() send_templated_mail( template_name="challenge_application_changed", from_email="*****@*****.**", recipient_list=[participation.user.email], context={"user": participation.user, "challenge": participation.challenge}, ) return redirect(challenge.get_absolute_url()) return render_to_response("challenge_edit.html", RequestContext(request, {"form": form}))
def challenge_edit(request, challenge_id): user = request.user challenge = get_object_or_404(Challenge, pk=challenge_id) if challenge.status == CHALLENGE_STATUS.COMPLETED: raise Http501 form = EditChallengeForm( user, request.POST or None, request.FILES or None, instance=challenge) #save button clicked if request.method == "POST": if form.is_valid(): form.save() ctx = {} ctx.update({ "user": user, "challenge": challenge, "challenge_url": challenge.get_full_url(request), }) locale.setlocale(locale.LC_TIME, "de_CH.utf8") participations = Participation.objects.all().filter( Q(challenge=challenge) & ( Q(status=PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION) | Q(status=PARTICIPATION_STATE.CONFIRMED) ) ) waited = Participation.objects.all().filter( Q(challenge=challenge) & Q(status=PARTICIPATION_STATE.WAITING_FOR_CONFIRMATION) ) if "delete" in request.POST: challenge.is_deleted = True challenge.save() ctx.update({"subject": _("%(challenge_name)s was cancelled") % {"challenge_name": challenge.name}}) for participation in participations: send_templated_mail( template_name="challenge_deleted", from_email=settings.EMAIL_SENDER, recipient_list=[participation.user.email, ], context=ctx) #is_date_time_changed: elif "start_date" in form.changed_data or "start_time" in form.changed_data: ctx.update({"subject": _("%(challenge)s now starts at %(start_date)s at %(start_time)s") % { "challenge": challenge.name, "start_date": challenge.start_date.strftime("%A, %d. %B"), "start_time": challenge.start_time.strftime("%H:%M"), }}) for participation in participations: send_templated_mail( template_name="challenge_changed", from_email=settings.EMAIL_SENDER, recipient_list=[participation.user.email, ], context=ctx, ) if "application" in form.changed_data and challenge.application == CHALLENGE_MODE.FREE_FOR_ALL: ctx.update({"subject": _("You were accepted to '%(challenge)s on Participe!") % {"challenge": challenge.name}}) for participation in waited: #if we change a challenge state from confirmation required to free-for-all, #we automatically accept all people who are currently waiting for their #applications to be accepted. We also inform them by email about this. participation.status = PARTICIPATION_STATE.CONFIRMED participation.date_accepted = datetime.now() participation.save() send_templated_mail( template_name="challenge_application_changed", from_email=settings.EMAIL_SENDER, recipient_list=[participation.user.email, ], context=ctx, ) return redirect(challenge.get_absolute_url()) return render_to_response('challenge_edit.html', RequestContext(request, {'form': form}))