Ejemplo n.º 1
0
def create_event(request):
    if request.method == 'POST':
        event_form = EventForm(request.POST)
        if event_form.is_valid():
            event_form.save()
            return HttpResponseRedirect(reverse('staff_todo'))
    else:
        event_form = EventForm()
    return render(request, 'staff/create_event.html', {'event_form': event_form})
Ejemplo n.º 2
0
def create_event(request):
    if request.method == 'POST':
        event_form = EventForm(request.POST)
        if event_form.is_valid():
            event_form.save()
            return HttpResponseRedirect(reverse('staff:tasks'))
    else:
        event_form = EventForm()
    return render(request, 'staff/create_event.html', {'event_form': event_form})
Ejemplo n.º 3
0
def confirm_booking(request, room, start, end, date, rate):
    user = request.user
    room = get_object_or_404(Room, name=room)

    start_ts, end_ts, start, end = coerce_times(start, end, date)
    target_date = start_ts.date()

    event_dict = {}
    calendar = room.get_calendar(target_date)
    event_dict[room] = calendar
    if len(calendar) > 48:
        loop_count = 4
    else:
        loop_count = 2

    # Infuse room calendar with search range
    search_start = start.replace(':', '')
    search_end = end.replace(':', '')

    for block in calendar:
        block_int = int(block['mil_hour'] + block['minutes'])
        if int(search_start) <= block_int and block_int <= int(search_end):
            block['searched'] = True

    if request.method == 'POST':
        booking_form = EventForm(request.POST)
        user = request.user
        room = request.POST.get('room')
        room = get_object_or_404(Room, name=room)
        start = request.POST.get('start')
        end = request.POST.get('end')
        date = request.POST.get('date')
        start_ts, end_ts, start, end = coerce_times(start, end, date)
        description = request.POST.get('description', '')
        charge = request.POST.get('charge', 0)
        is_public = request.POST.get('is_public', False)
        if is_public == 'True':
            is_public = True
        else:
            is_public = False
        event = Event(user=user,
                      room=room,
                      start_ts=start_ts,
                      end_ts=end_ts,
                      description=description,
                      charge=charge,
                      is_public=is_public)

        stillAv = Room.objects.available(start=start_ts, end=end_ts)

        if room in stillAv:
            try:
                event.save()

                return HttpResponseRedirect(
                    reverse('member:profile:view',
                            kwargs={'username': user.username}))

            except Exception as e:
                messages.error(request, str(e))
                logger.error(str(e))
        else:
            messages.error(
                request,
                'This room is no longer available at the requested time.')
    else:
        booking_form = EventForm()

    context = {
        'booking_form': booking_form,
        'start': start,
        'end': end,
        'room': room,
        'date': date,
        'rate': rate,
        'loop_count': loop_count,
        'event_dict': event_dict,
    }
    return render(request, 'member/events/booking_confirm.html', context)