예제 #1
0
파일: views.py 프로젝트: SVArago/alexia
def event_edit_bartender_availability(request, pk, user_pk):
    event = get_object_or_404(Event, pk=pk)
    user = get_object_or_404(User, pk=user_pk)

    if event.organizer != request.organization:
        raise PermissionDenied

    try:
        bartender_availability = BartenderAvailability.objects.get(event=event,
                                                                   user=user)
        old_availability = bartender_availability.availability
    except BartenderAvailability.DoesNotExist:
        bartender_availability = None
        old_availability = None

    if request.method == 'POST':
        form = BartenderAvailabilityForm(data=request.POST,
                                         instance=bartender_availability, event=event, user=user)
        if form.is_valid():
            if bartender_availability:
                form.save()
                log.availability_changed(
                    request.user, event, user, old_availability,
                    bartender_availability.availability)
            else:
                bartender_availability = form.save()
                log.availability_created(
                    request.user, event, user,
                    bartender_availability.availability)
            return redirect(event_show, pk=event.pk)
    else:
        form = BartenderAvailabilityForm(instance=bartender_availability,
                                         event=event, user=user)

    return render(request, 'scheduling/event_bartender_availability_form.html', locals())
예제 #2
0
파일: views.py 프로젝트: SVArago/alexia
def set_bartender_availability(request):
    event = get_object_or_404(Event, pk=request.POST.get('event_id'))
    availability = get_object_or_404(
        Availability, pk=request.POST.get('availability_id'))

    if (request.organization not in event.participants.all()) or \
            not request.user.profile.is_tender(request.organization) or \
            event.is_closed:
        raise PermissionDenied

    # When the organizer assigns tenders, only planners and higher are allowed
    # to set availability to assigned.
    if event.organizer.assigns_tenders and \
            not request.user.is_superuser and \
            not request.user.profile.is_planner(event.organizer) and \
            availability.nature == Availability.ASSIGNED:
        raise PermissionDenied

    # And if you're already assigned, you can't change your own availability.
    if event.organizer.assigns_tenders and \
            not request.user.is_superuser and \
            not request.user.profile.is_planner(event.organizer) and \
            request.user in event.get_assigned_bartenders():
        raise PermissionDenied

    if request.method == 'POST' and request.is_ajax():
        bartender_availability, is_new_record = \
            BartenderAvailability.objects.get_or_create(
                user=request.user, event=event,
                defaults={'availability': availability})
        if not is_new_record:
            old_availability = bartender_availability.availability
            bartender_availability.availability = availability
            bartender_availability.save()
            log.availability_changed(
                request.user, event, request.user, old_availability,
                availability)
        else:
            log.availability_created(
                request.user, event, request.user, availability)
        return render(request, 'scheduling/partials/assigned_bartenders.html',
                      {'e': event})
    else:
        # TODO Better error message and HTTP status code [JZ]
        return HttpResponse("NOTOK")
예제 #3
0
파일: views.py 프로젝트: J3173/alexia
def set_bartender_availability(request):
    event = get_object_or_404(Event, pk=request.POST.get('event_id'))
    availability = get_object_or_404(Availability,
                                     pk=request.POST.get('availability_id'))

    if (request.organization not in event.participants.all()) or \
            not request.user.profile.is_tender(request.organization) or \
            event.is_closed:
        raise PermissionDenied

    # When the organizer assigns tenders, only planners and higher are allowed
    # to set availability to assigned.
    if event.organizer.assigns_tenders and \
            not request.user.is_superuser and \
            not request.user.profile.is_planner(event.organizer) and \
            availability.nature == Availability.ASSIGNED:
        raise PermissionDenied

    # And if you're already assigned, you can't change your own availability.
    if event.organizer.assigns_tenders and \
            not request.user.is_superuser and \
            not request.user.profile.is_planner(event.organizer) and \
            request.user in event.get_assigned_bartenders():
        raise PermissionDenied

    if request.method == 'POST' and request.is_ajax():
        bartender_availability, is_new_record = \
            BartenderAvailability.objects.get_or_create(
                user=request.user, event=event,
                defaults={'availability': availability})
        if not is_new_record:
            old_availability = bartender_availability.availability
            bartender_availability.availability = availability
            bartender_availability.save()
            log.availability_changed(request.user, event, request.user,
                                     old_availability, availability)
        else:
            log.availability_created(request.user, event, request.user,
                                     availability)
        return render(request, 'scheduling/partials/assigned_bartenders.html',
                      {'e': event})
    else:
        # TODO Better error message and HTTP status code [JZ]
        return HttpResponse("NOTOK")
예제 #4
0
파일: views.py 프로젝트: J3173/alexia
def event_edit_bartender_availability(request, pk, user_pk):
    event = get_object_or_404(Event, pk=pk)
    user = get_object_or_404(User, pk=user_pk)

    if event.organizer != request.organization:
        raise PermissionDenied

    try:
        bartender_availability = BartenderAvailability.objects.get(event=event,
                                                                   user=user)
        old_availability = bartender_availability.availability
    except BartenderAvailability.DoesNotExist:
        bartender_availability = None
        old_availability = None

    if request.method == 'POST':
        form = BartenderAvailabilityForm(data=request.POST,
                                         instance=bartender_availability,
                                         event=event,
                                         user=user)
        if form.is_valid():
            if bartender_availability:
                form.save()
                log.availability_changed(request.user, event, user,
                                         old_availability,
                                         bartender_availability.availability)
            else:
                bartender_availability = form.save()
                log.availability_created(request.user, event, user,
                                         bartender_availability.availability)
            return redirect(event_show, pk=event.pk)
    else:
        form = BartenderAvailabilityForm(instance=bartender_availability,
                                         event=event,
                                         user=user)

    return render(request, 'scheduling/event_bartender_availability_form.html',
                  locals())