def details(request, event_id, event_slug): event = get_object_or_404(Event, pk=event_id) # Restricts access to the event if it is group restricted if not event.can_display(request.user): messages.error(request, "Du har ikke tilgang til dette arrangementet.") return index(request) if request.method == 'POST': if request.is_ajax and 'action' in request.POST and 'extras_id' in request.POST: return JsonResponse(handle_event_ajax(event, request.user, request.POST['action'], request.POST['extras_id'])) form = CaptchaForm(user=request.user) context = { 'captcha_form': form, 'event': event, 'ics_path': request.build_absolute_uri(reverse('event_ics', args=(event.id,))), } if event.is_attendance_event(): try: payment = Payment.objects.get(content_type=ContentType.objects.get_for_model(AttendanceEvent), object_id=event_id) except Payment.DoesNotExist: payment = None context = handle_attendance_event_detail(event, request.user, context) if payment: request.session['payment_id'] = payment.id context = handle_event_payment(event, request.user, payment, context) return render(request, 'events/details.html', context)
def attend_event(request, event_id): event = get_object_or_404(Event, pk=event_id) if not event.is_attendance_event(): messages.error(request, _("Dette er ikke et påmeldingsarrangement.")) return redirect(event) if not request.POST: messages.error(request, _("Vennligst fyll ut skjemaet.")) return redirect(event) form = CaptchaForm(request.POST, user=request.user) if not form.is_valid(): for field, errors in form.errors.items(): for error in errors: messages.error(request, error) return redirect(event) # Check if the user is eligible to attend this event. # If not, an error message will be present in the returned dict attendance_event = event.attendance_event response = event.attendance_event.is_eligible_for_signup(request.user) if response.status: attendee = Attendee(event=attendance_event, user=request.user) if "note" in form.cleaned_data: attendee.note = form.cleaned_data["note"] attendee.show_as_attending_event = ( request.user.get_visible_as_attending_events() ) attendee.save() messages.success(request, _("Du er nå meldt på arrangementet.")) if attendance_event.payment(): handle_attend_event_payment(event, request.user) return redirect(event) else: messages.error(request, response.message) return redirect(event)