示例#1
0
文件: views.py 项目: patrup/ResPla
def book_a_resource(request):
    ''' books an available resource '''
    if request.method == 'GET':
        resource_list = Resource.objects.all()
        form = ResourceTimeSpanForm()
        context = {'resource_list': resource_list, 'form': form}
        return render(request, 'Planer/book_resource.html', context)
    if request.method == 'POST':
        form = ResourceTimeSpanForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['resources'] is not None:
                resource = form.cleaned_data['resources']
                booking = Booking()
                booking.resource = resource
                booking.start_date = form.cleaned_data['start_date']
                booking.end_date = form.cleaned_data['end_date']
                booking.title = resource.title
                booking.description = "Resourcenbuchung"
                booking.save()
                return render(request, 'Planer/index.html')
            else:
                start_date = form.cleaned_data['start_date']
                end_date = form.cleaned_data['end_date']
                resource_list = get_available_resources(start_date, end_date)
                form.fields['resources'].queryset = resource_list
        else:
            resource_list = Resource.objects.all()
        context = {'resource_list': resource_list, 'form': form}
        return render(request, 'Planer/book_resource.html', context)
示例#2
0
文件: views.py 项目: patrup/ResPla
def book_a_person(request):
    ''' books an available person '''
    if request.method == 'GET':
        person_list = Person.objects.all()
        form = PersonsTimeSpanForm()
        context = {'person_list': person_list, 'form': form}
        return render(request, 'Planer/book_person.html', context)
    if request.method == 'POST':
        form = PersonsTimeSpanForm(request.POST)
        if form.is_valid():
            if form.cleaned_data['persons'] is not None:
                person = form.cleaned_data['persons']
                booking = Booking()
                booking.person = person
                booking.start_date = form.cleaned_data['start_date']
                booking.end_date = form.cleaned_data['end_date']
                booking.title = person.first_name + ' ' + person.last_name
                booking.description = "Personenbuchung"
                booking.save()
                return render(request, 'Planer/index.html')
            else:
                start_date = form.cleaned_data['start_date']
                end_date = form.cleaned_data['end_date']
                person_list = get_available_persons(start_date, end_date)
                form.fields['persons'].queryset = person_list
        else:
            person_list = Person.objects.all()
        context = {'person_list': person_list, 'form': form}
        return render(request, 'Planer/book_person.html', context)