Beispiel #1
0
def event_change_attendees(request, event_id, active_tab="attendees"):
    if not has_access(request):
        raise PermissionDenied

    context = _create_details_context(request, event_id)
    context["active_tab"] = "attendees"

    event = context["event"]

    if not event.is_attendance_event():
        messages.error(request, _("Dette er ikke et påmeldingsarrangement."))
        return redirect("dashboard_event_details_active",
                        event_id=event.id,
                        active_tab="details")

    # AJAX
    if request.method == "POST":
        if request.is_ajax and "action" in request.POST:
            if not event.is_attendance_event:
                return HttpResponse(
                    _("Dette er ikke et påmeldingsarrangement."), status=400)

            return JsonResponse(event_ajax_handler(event, request))

    # NON AJAX
    context = get_base_context(request)

    context["event"] = event
    context["active_tab"] = active_tab

    extras = {}
    if event.is_attendance_event() and event.attendance_event.extras:
        for extra in event.attendance_event.extras.all():
            extras[extra] = {
                "type": extra,
                "attending": 0,
                "waits": 0,
                "allergics": []
            }

        count_extras(extras, "attending",
                     event.attendance_event.attending_attendees_qs)
        count_extras(extras, "waits", event.attendance_event.waitlist_qs)

    context["change_event_form"] = dashboard_forms.ChangeEventForm(
        instance=event)
    if event.is_attendance_event():
        context[
            "change_attendance_form"] = dashboard_forms.ChangeAttendanceEventForm(
                instance=event.attendance_event)
        prices = _payment_prices(event.attendance_event)
        context["payment_prices"] = prices[0]
        context["payment_price_summary"] = prices[1]

    context["extras"] = extras
    context["change_event_form"] = dashboard_forms.ChangeEventForm(
        instance=event)

    return render(request, "events/dashboard/details.html", context)
Beispiel #2
0
def _create_details_context(request, event_id):
    """
    Prepare a context to be shared for all detail views.
    """

    event = get_object_or_404(Event, pk=event_id)

    # Start with adding base context and the event itself
    context = get_base_context(request)
    context["event"] = event

    # Add forms
    context["change_event_form"] = dashboard_forms.ChangeEventForm(
        instance=event)
    if event.is_attendance_event():
        context[
            "change_attendance_form"] = dashboard_forms.ChangeAttendanceEventForm(
                instance=event.attendance_event)
        if event.attendance_event.has_reservation:
            context[
                "change_reservation_form"] = dashboard_forms.ChangeReservationForm(
                    instance=event.attendance_event.reserved_seats)
            seats = event.attendance_event.reserved_seats.seats
            ReserveeFormSet = modelformset_factory(
                Reservee,
                max_num=seats,
                extra=seats,
                fields=["name", "note", "allergies"],
            )
            context["change_reservees_formset"] = ReserveeFormSet(
                queryset=event.attendance_event.reserved_seats.reservees.all())

    return context
Beispiel #3
0
def create_event(request):
    if not has_access(request):
        raise PermissionDenied

    context = get_base_context(request)

    if request.method == 'POST':
        form = dashboard_forms.ChangeEventForm(request.POST)
        if form.is_valid():
            cleaned = form.cleaned_data

            if cleaned['event_type'] not in get_types_allowed(request.user):
                messages.error(
                    request,
                    _("Du har ikke tilgang til å lage arranngement av typen '%s'."
                      ) % cleaned['event_type'])
                context['change_event_form'] = form

            else:
                # Create object, but do not commit to db. We need to add stuff.
                event = form.save(commit=False)
                # Add author
                event.author = request.user
                event.save()

                messages.success(request, _("Arrangementet ble opprettet."))
                return redirect('dashboard_event_details', event_id=event.id)

        else:
            context['change_event_form'] = form

    if 'change_event_form' not in context.keys():
        context['change_event_form'] = dashboard_forms.ChangeEventForm()

    context['event'] = _('Nytt arrangement')
    context['active_tab'] = 'details'

    return render(request, 'events/dashboard/details.html', context)