Пример #1
0
Файл: views.py Проект: Ads7/vms
def edit(request, shift_id):

    shift = None
    if shift_id:
        shift = get_shift_by_id(shift_id)

    if request.method == 'POST':
        form = ShiftForm(request.POST, instance=shift)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('shift:list_shifts', args=(shift.job.id,)))
        else:
            return render(request, 'shift/edit.html', {'form' : form, 'shift' : shift})
    else:
        form = ShiftForm(instance=shift)
        return render(request, 'shift/edit.html', {'form' : form, 'shift' : shift})
Пример #2
0
def create(request, job_id):
    if job_id:
        if request.method == 'POST':
            job = get_job_by_id(job_id)
            if job:
                form = ShiftForm(request.POST)
                if form.is_valid():
                    shift = form.save(commit=False)
                    shift.job = job
                    shift.save()
                    return HttpResponseRedirect(
                        reverse('shift:list_shifts', args=(job_id, )))
                else:
                    return render(request, 'shift/create.html', {
                        'form': form,
                        'job_id': job_id,
                    })
            else:
                raise Http404
        else:
            form = ShiftForm()
            return render(request, 'shift/create.html', {
                'form': form,
                'job_id': job_id,
            })
    else:
        raise Http404
Пример #3
0
def edit(request, shift_id):
    user = request.user
    admin = None

    try:
        admin = user.administrator
    except ObjectDoesNotExist:
        pass

    # check that an admin is logged in
    if not admin:
        return render(request, 'vms/no_admin_rights.html')
    else:
        shift = None
        if shift_id:
            shift = get_shift_by_id(shift_id)

        if request.method == 'POST':
            form = ShiftForm(request.POST, instance=shift)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse(
                    'shift:list_shifts',
                    args=(shift.job.id, )
                    ))
            else:
                return render(
                    request,
                    'shift/edit.html',
                    {'form': form, 'shift': shift, 'job': shift.job}
                    )
        else:
            form = ShiftForm(instance=shift)
            return render(
                request,
                'shift/edit.html',
                {'form': form, 'shift': shift, 'job': shift.job}
                )
Пример #4
0
def edit(request, shift_id):

    shift = None
    if shift_id:
        shift = get_shift_by_id(shift_id)

    if request.method == 'POST':
        form = ShiftForm(request.POST, instance=shift)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(
                reverse('shift:list_shifts', args=(shift.job.id, )))
        else:
            return render(request, 'shift/edit.html', {
                'form': form,
                'shift': shift
            })
    else:
        form = ShiftForm(instance=shift)
        return render(request, 'shift/edit.html', {
            'form': form,
            'shift': shift
        })
Пример #5
0
def create(request, job_id):
    user = request.user
    admin = None

    try:
        admin = user.administrator
    except ObjectDoesNotExist:
        pass

    # check that an admin is logged in
    if not admin:
        return render(request, 'vms/no_admin_rights.html')
    else:
        if job_id:
            job = get_job_by_id(job_id)
            event = job.event
            if request.method == 'POST':
                if job:
                    form = ShiftForm(request.POST)
                    if form.is_valid():
                        shift = form.save(commit=False)
                        shift.job = job
                        shift.save()
                        return HttpResponseRedirect(reverse('shift:list_shifts', args=(job_id,)))
                    else:
                        return render(
                            request,
                            'shift/create.html',
                            {'form': form, 'job_id': job_id, }
                            )
                else:
                    raise Http404
            else:
                form = ShiftForm()
                country = event.country
                state = event.state
                city = event.city
                address = event.address
                venue = event.venue
                return render(
                    request,
                    'shift/create.html',
                    {'form': form, 'job_id': job_id, 'country': country, 'state': state, 'city': city, 'address': address, 'venue': venue, 'job': job}
                    )
        else:
            raise Http404
Пример #6
0
Файл: views.py Проект: Ads7/vms
def create(request, job_id):
    if job_id:
        if request.method == 'POST':
            job = get_job_by_id(job_id)
            if job:
                form = ShiftForm(request.POST)
                if form.is_valid():
                    shift = form.save(commit=False)
                    shift.job = job
                    shift.save()
                    return HttpResponseRedirect(reverse('shift:list_shifts', args=(job_id,)))
                else:
                    return render(request, 'shift/create.html', {'form' : form, 'job_id' : job_id,})
            else:
                raise Http404
        else:
            form = ShiftForm()
            return render(request, 'shift/create.html', {'form' : form, 'job_id' : job_id,})
    else:
        raise Http404
Пример #7
0
def create_shift(request, job_id):

    if job_id:
        if request.method == 'POST':
            job = get_job_by_id(job_id)
            if job:
                form = ShiftForm(request.POST)
                if form.is_valid():
                    shift = form.save(commit=False)
                    #Keep track of number of open slots
                    shift.slots_remaining = shift.max_volunteers;
                    shift.job = job
                    shift.save()
                    return render(request, 'shift/create_shift_success.html')
                else:
                    form = ShiftForm()
                    return render(request, 'shift/create_shift.html', {'form' : form, 'job_id' : job_id,})
            else:
                raise Http404
        else:
            form = ShiftForm()
            return render(request, 'shift/create_shift.html', {'form' : form, 'job_id' : job_id,})
    else:
        raise Http404