示例#1
0
    def get_redirect_url(self, *args, **kwargs):
        token = kwargs["token"]
        try:
            event, user = _load_token(token, "absent")
        except Exception:
            logger.exception(f"Error loading token {token} during asbent")
            messages.error(self.request,
                           "Une erreur est survenue lors de votre requête")
            return reverse("event:list")

        event.registered.add(user)
        participation = event.participations.filter(user=user).first()
        if participation and participation.saved:
            contribution = Membership.objects.filter(
                user=participation.user,
                organization=event.organization).first()
            if contribution:
                contribution.amount -= participation.amount
                fee = Fee.objects.filter(
                    organization=event.organization,
                    user=participation.user,
                    date=event.date,
                    amount=participation.amount,
                )
                fee.delete()
                contribution.save()
        event.presents.remove(user)
        messages.success(self.request, f"{user} a été marqué comme absent !")

        next_url = self.request.GET.get("redirect")
        if utils.is_valid_path(next_url):
            return next_url
        return reverse("event:detail", args=[event.id, event.slug]) + "#manage"
示例#2
0
 def get_success_url(self, *args, **kwargs):
     next_url = self.request.GET.get("redirect")
     if utils.is_valid_path(next_url):
         return next_url
     return (
         reverse("event:detail", args=[self.event.id, self.event.slug]) +
         "#manage")
示例#3
0
 def get_redirect_url(self, *args, **kwargs):
     event = get_object_or_404(Event, pk=kwargs.get("pk"))
     user = CustomUser.objects.filter(
         email=self.request.POST["email"]).first()
     if user:
         form = MoreInfoCustomUserForm(self.request.POST, instance=user)
     else:
         form = MoreInfoCustomUserForm(self.request.POST)
     user = form.save()
     add_present(event, user, form.cleaned_data["amount_paid"])
     next_url = self.request.GET.get("redirect")
     if utils.is_valid_path(next_url):
         return next_url
     return reverse("event:detail", args=[event.id, event.slug]) + "#manage"
示例#4
0
    def get_redirect_url(self, *args, **kwargs):
        token = kwargs["token"]
        try:
            event, user = _load_token(token, "cancel")
        except Exception:
            logger.exception(f"Error loading token {token} during unbook")
            messages.error(self.request,
                           "Une erreur est survenue lors de votre requête")
            return reverse("event:list")

        event.registered.remove(user)

        event_url = reverse("event:detail", args=[event.id, event.slug])
        event_url = self.request.build_absolute_uri(event_url)

        if user.first_name == "":
            # This is a temporary user created only for this event, we can
            # delete it
            user.delete()
        else:
            book_token = tokenize(user, event, "book")
            book_url = reverse("event:book", args=[book_token])
            book_url = self.request.build_absolute_uri(book_url)

        msg_plain = render_to_string("event/mail/unbook.txt", context=locals())
        msg_html = render_to_string("event/mail/unbook.html", context=locals())

        date = event.date.strftime("%d %B")
        subject = (f"Confirmation d'annulation pour le "
                   f"{date} à {event.location.name}")

        send_mail(
            subject,
            msg_plain,
            f"{event.organization}",
            [user.email],
            html_message=msg_html,
        )

        messages.success(self.request,
                         "Vous n'êtes plus inscrit à cet évènement")

        next_url = self.request.GET.get("redirect")
        if utils.is_valid_path(next_url):
            return next_url
        return reverse("event:detail", args=[event.id, event.slug])
示例#5
0
    def get_redirect_url(self, *args, **kwargs):
        token = kwargs["token"]
        is_authorized = False
        try:
            event, user = _load_token(token, "book")
        except Exception:
            logger.exception(f"Error loading token {token} during book")
            messages.error(self.request,
                           "Une erreur est survenue lors de votre requête")
            return reverse("event:list")

        try:
            id_current_user = self.request.user.id
            current_user = CustomUser.objects.get(id=id_current_user)
            if current_user in (event.organization.actives.all().union(
                    event.organization.volunteers.all(),
                    event.organization.admins.all())):
                is_authorized = True
        except Exception:
            pass

        next_url = self.request.GET.get("redirect")
        if not utils.is_valid_path(next_url):
            next_url = reverse("event:detail", args=[event.id, event.slug])

        if event.remaining_seats <= 0 and not is_authorized:
            messages.error(
                self.request,
                "Désolé, il n'y a plus de place "
                "disponibles pour cet évènement",
            )
            return next_url

        if user in event.presents.all().union(event.registered.all()):
            messages.success(
                self.request,
                "Vous êtes déjà inscrit à cet évènement, à bientôt !",
            )
            return next_url

        event.registered.add(user)

        conditions = event.conditions.all()
        unbook_token = tokenize(user, event, "cancel")
        cancel_url = reverse("event:cancel_reservation", args=[unbook_token])
        cancel_url = self.request.build_absolute_uri(cancel_url)
        register_url = reverse("password_reset")
        register_url = self.request.build_absolute_uri(register_url)

        event_url = reverse("event:detail", args=[event.id, event.slug])
        event_url = self.request.build_absolute_uri(event_url)

        msg_plain = render_to_string("event/mail/book.txt", context=locals())
        msg_html = render_to_string("event/mail/book.html", context=locals())

        date = event.date.strftime("%d %B")
        subject = f"Votre réservation du {date} pour {event.activity.name} à {event.location.name}"

        send_mail(
            subject,
            msg_plain,
            f"{event.organization}",
            [user.email],
            html_message=msg_html,
        )

        messages.success(self.request,
                         f"'{user}' bien inscrit à l'évènement !")

        return next_url