コード例 #1
0
def calendar(request):
    events = Event.objects.filter(is_public=True)
    data = []

    for event in events:
        host = get_object_or_404(User, id=event.user_id)
        data.append((event, host))

    if request.method == 'POST':
        user = request.user
        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)
        if start_ts < end_ts :
            description = request.POST.get('description', '')
            charge = request.POST.get('charge', 0)
            is_public = True

            event = Event(user=user, start_ts=start_ts, end_ts=end_ts, description=description, charge=charge, is_public=is_public)
            event.save()

            return HttpResponseRedirect(reverse('member_calendar'))
        else:
            messages.add_message(request, messages.ERROR, "Did not save your event. Double check that the event start is before the end time. Thank you.")

    template = 'members/calendar.html'
    context = {'data': data, 'CALENDAR_DICT': settings.CALENDAR_DICT}
    if hasattr(settings, 'GOOGLE_CALENDAR_ID'):
        context['feed_url'] = "https://calendar.google.com/calendar/ical/%s/public/basic.ics" % settings.GOOGLE_CALENDAR_ID
        context['GOOGLE_CALENDAR_ID'] = settings.GOOGLE_CALENDAR_ID
        context['GOOGLE_API_KEY'] = settings.GOOGLE_API_KEY
        template = 'members/calendar_google.html'
    return render(request, template, context)
コード例 #2
0
def calendar(request):
    events = Event.objects.filter(is_public=True)
    data = []

    for event in events:
        host = get_object_or_404(User, id=event.user_id)
        data.append((event, host))

    if request.method == 'POST':
        user = request.user
        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)
        if start_ts < end_ts:
            description = request.POST.get('description', '')
            charge = request.POST.get('charge', 0)
            is_public = True

            event = Event(user=user, start_ts=start_ts, end_ts=end_ts, description=description, charge=charge, is_public=is_public)
            event.save()

            return HttpResponseRedirect(reverse('member:event:calendar'))
        else:
            messages.add_message(request, messages.ERROR, _("Did not save your event. Double check that the event start is before the end time. Thank you."))

    template = 'member/events/calendar.html'
    context = {'data': data, 'CALENDAR_DICT': settings.CALENDAR_DICT}
    if hasattr(settings, 'GOOGLE_CALENDAR_ID'):
        context['feed_url'] = "https://calendar.google.com/calendar/ical/%s/public/basic.ics" % settings.GOOGLE_CALENDAR_ID
        context['GOOGLE_CALENDAR_ID'] = settings.GOOGLE_CALENDAR_ID
        context['GOOGLE_API_KEY'] = settings.GOOGLE_API_KEY
        template = 'member/events/calendar_google.html'
    return render(request, template, context)
コード例 #3
0
def confirm_booking(request, room, start, end, date):
    user = request.user
    room = get_object_or_404(Room, name=room)
    page_message = None

    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

    # 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':
        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', kwargs={'username': user.username}))

            except Exception as e:
                page_message = str(e)
                logger.error(str(e))
        else:
            page_message = '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, 'page_message': page_message,
        'event_dict': event_dict}
    return render(request, 'members/booking_confirm.html', context)
コード例 #4
0
ファイル: events.py プロジェクト: manens/nadine
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)