Example #1
0
def bartender_availability_set(request, user_id, event_id, status_id):
    """Changes the availability for the given user and event."""

    try:
        # Get the data from the database
        event = Event.objects.get(pk=event_id)
        user = User.objects.get(pk=user_id)
        form = BartenderAvailabilityForm(event=event, user=user, data={
            "availability": status_id
        })

        if form.is_valid():
            form.save()
            return True
    except:
        pass

    return False
Example #2
0
def bartender_availability_set(request, user_id, event_id, status_id):
    """Changes the availability for the given user and event."""

    try:
        # Get the data from the database
        event = Event.objects.get(pk=event_id)
        user = User.objects.get(pk=user_id)
        form = BartenderAvailabilityForm(event=event,
                                         user=user,
                                         data={"availability": status_id})

        if form.is_valid():
            form.save()
            return True
    except:
        pass

    return False
Example #3
0
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())
Example #4
0
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())