コード例 #1
0
def mail_participants(request, event_id):
    event = get_object_or_404(Event, pk=event_id)

    # If this is not an attendance event, redirect to event with error
    if not event.is_attendance_event():
        messages.error(request, _("Dette er ikke et påmeldingsarrangement."))
        return redirect(event)

    # Check access
    if not request.user.has_perm("events.change_event", obj=event):
        messages.error(request, _("Du har ikke tilgang til å vise denne siden."))
        return redirect(event)

    all_attendees = list(event.attendance_event.attending_attendees_qs)
    attendees_on_waitlist = list(event.attendance_event.waitlist_qs)
    attendees_not_paid = list(event.attendance_event.attendees_not_paid)

    if request.method == "POST":
        subject = request.POST.get("subject")
        message = request.POST.get("message")
        images = [
            (image.name, image.read(), image.content_type)
            for image in request.FILES.getlist("image")
        ]
        mail_sent = handle_mail_participants(
            event,
            request.POST.get("to_email"),
            subject,
            message,
            images,
            all_attendees,
            attendees_on_waitlist,
            attendees_not_paid,
        )

        if mail_sent:
            messages.success(request, _("Mailen ble sendt"))
        else:
            messages.error(
                request, _("Vi klarte ikke å sende mailene dine. Prøv igjen")
            )

    return render(
        request,
        "events/mail_participants.html",
        {
            "all_attendees": all_attendees,
            "attendees_on_waitlist": attendees_on_waitlist,
            "attendees_not_paid": attendees_not_paid,
            "event": event,
        },
    )
コード例 #2
0
ファイル: views.py プロジェクト: emilps/onlineweb4
def mail_participants(request, event_id):
    event = get_object_or_404(Event, pk=event_id)

    # If this is not an attendance event, redirect to event with error
    if not event.is_attendance_event():
        messages.error(request, _("Dette er ikke et påmeldingsarrangement."))
        return redirect(event)

    # Check access
    if not request.user.has_perm('events.change_event', obj=event):
        messages.error(request,
                       _('Du har ikke tilgang til å vise denne siden.'))
        return redirect(event)

    all_attendees = list(event.attendance_event.attending_attendees_qs)
    attendees_on_waitlist = list(event.attendance_event.waitlist_qs)
    attendees_not_paid = list(event.attendance_event.attendees_not_paid)

    if request.method == 'POST':
        subject = request.POST.get('subject')
        message = request.POST.get('message')
        images = [(image.name, image.read(), image.content_type)
                  for image in request.FILES.getlist('image')]
        mail_sent = handle_mail_participants(event,
                                             request.POST.get('from_email'),
                                             request.POST.get('to_email'),
                                             subject, message, images,
                                             all_attendees,
                                             attendees_on_waitlist,
                                             attendees_not_paid)

        if mail_sent:
            messages.success(request, _('Mailen ble sendt'))
        else:
            messages.error(
                request, _('Vi klarte ikke å sende mailene dine. Prøv igjen'))

    return render(
        request, 'events/mail_participants.html', {
            'all_attendees': all_attendees,
            'attendees_on_waitlist': attendees_on_waitlist,
            'attendees_not_paid': attendees_not_paid,
            'event': event
        })
コード例 #3
0
def mail_participants(request, event_id):
    event = get_object_or_404(Event, pk=event_id)

    # If this is not an attendance event, redirect to event with error
    if not event.attendance_event:
        messages.error(request, _("Dette er ikke et påmeldingsarrangement."))
        return redirect(event)

    # Check access
    if event not in get_group_restricted_events(request.user):
        messages.error(request,
                       _('Du har ikke tilgang til å vise denne siden.'))
        return redirect(event)

    all_attendees = list(event.attendance_event.attendees_qs)
    attendees_on_waitlist = list(event.attendance_event.waitlist_qs)
    attendees_not_paid = list(event.attendance_event.attendees_not_paid)

    if request.method == 'POST':
        subject = request.POST.get('subject')
        message = request.POST.get('message')

        mail_sent = handle_mail_participants(event,
                                             request.POST.get('from_email'),
                                             request.POST.get('to_email'),
                                             subject, message, all_attendees,
                                             attendees_on_waitlist,
                                             attendees_not_paid)

        if mail_sent:
            messages.success(request, _('Mailen ble sendt'))
        else:
            messages.error(
                request, _('Vi klarte ikke å sende mailene dine. Prøv igjen'))

    return render(
        request, 'events/mail_participants.html', {
            'all_attendees': all_attendees,
            'attendees_on_waitlist': attendees_on_waitlist,
            'attendees_not_paid': attendees_not_paid,
            'event': event
        })