コード例 #1
0
ファイル: utils.py プロジェクト: tokongs/onlineweb4
def handle_add_attendee(event: Event, user_id: int):
    resp = _get_event_context(event)
    if (
        event.attendance_event.number_of_seats_taken
        >= event.attendance_event.max_capacity
    ):
        if not event.attendance_event.waitlist:
            return {
                "message": f"Det er ingen ledige plasser på {event.title}.",
                "status": 400,
                **resp,
            }

    user = User.objects.filter(pk=user_id)
    if user.count() != 1:
        return {
            "message": f"Fant ingen bruker med oppgitt ID ({user_id}).",
            "status": 400,
            **resp,
        }
    user = user[0]
    if Attendee.objects.filter(user=user, event=event.attendance_event).count() != 0:
        return {
            "message": f"{user} er allerede påmeldt {event.title}.",
            "status": 400,
            **resp,
        }

    attendee = Attendee(user=user, event=event.attendance_event)
    attendee.save()

    resp = _get_event_context(event, resp)
    return {"message": f"{user} ble meldt på {event}", "status": 200, **resp}
コード例 #2
0
ファイル: utils.py プロジェクト: tokongs/onlineweb4
def handle_paid(attendee: Attendee):
    """
    Toggle paid status of an attendee between paid and not paid
    """
    attendee.paid = not attendee.paid
    attendee.save()

    return {"message": "OK", "status": 200}
コード例 #3
0
ファイル: utils.py プロジェクト: tokongs/onlineweb4
def handle_attended(attendee: Attendee):
    """
    Toggle attending-status of an attendee between attending and not attending
    """
    attendee.attended = not attendee.attended
    attendee.save()

    return {"message": "OK", "status": 200}
コード例 #4
0
def handle_add_attendee(event, user_id):
    resp = {}
    if event.attendance_event.number_of_seats_taken >= event.attendance_event.max_capacity:
        if not event.attendance_event.waitlist:
            return 'Det er ingen ledige plasser på %s.' % event.title

    user = User.objects.filter(pk=user_id)
    if user.count() != 1:
        return 'Fant ingen bruker med oppgitt ID (%s).' % user_id
    user = user[0]
    if Attendee.objects.filter(user=user, event=event.attendance_event).count() != 0:
        return '%s er allerede påmeldt %s.' % (user.get_full_name(), event.title)

    attendee = Attendee(user=user, event=event.attendance_event)
    attendee.save()

    resp['message'] = '%s ble meldt på %s' % (user.get_full_name(), event)
    resp['attendees'] = []

    for number, a in enumerate(attendee.event.attending_attendees_qs):
        resp['attendees'].append({
            'number': number+1,
            'id': a.id,
            'first_name': a.user.first_name,
            'last_name': a.user.last_name,
            'paid': a.paid,
            'extras': str(a.extras),
            'attended': a.attended,
            'link': reverse('dashboard_attendee_details', kwargs={'attendee_id': a.id})
        })
    resp['waitlist'] = []
    for number, a in enumerate(attendee.event.waitlist_qs):
        resp['waitlist'].append({
            'number': number+1,
            'id': a.id,
            'first_name': a.user.first_name,
            'last_name': a.user.last_name,
            'paid': a.paid,
            'extras': str(a.extras),
            'attended': a.attended,
            'link': reverse('dashboard_attendee_details', kwargs={'attendee_id': a.id})
        })
    return resp
コード例 #5
0
def attendEvent(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.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)
コード例 #6
0
    def _handle_attendee(self, attendee: Attendee, waitlist_approved: bool):
        # If attendee is already marked as attended
        if attendee.attended:
            logger.debug(f"Attendee ({attendee}) already marked as attended.")
            raise RegisterAttendanceError(
                detail=f"{attendee.user} har allerede registrert oppmøte.",
                attend_status=AttendStatus.PREVIOUSLY_REGISTERED,
            )

        # If attendee is on waitlist (bypassed if attendee has gotten the all-clear)
        if attendee.is_on_waitlist() and not waitlist_approved:
            raise RegisterAttendanceError(
                detail=f"{attendee.user} er på venteliste. Registrer dem som møtt opp allikevel?",
                attend_status=AttendStatus.ON_WAIT_LIST,
            )