예제 #1
0
def scheme_submit(request):
    context = {}

    form = SchemeForm(request.POST or None, request.FILES or None)

    if request.method == 'POST':
        if form.is_valid():
            new_scheme = form.save(commit=False)
            new_scheme.user = request.user
            new_scheme.save()
            messages.info(request, u'Scheme submitted correctly little dragon.')

            return redirect('schemes')
        else:
            messages.error(
                    request,
                    u'Something went wrong in your submit. Please, check it.')

    context['form'] = form
    return render_response(request, 'scheme-submit.html', context)
예제 #2
0
def scheme_edit(request, scheme_id):
    """ scheme edition/update view."""
    context = {}

    scheme = Scheme.objects.get(id=scheme_id)
    form = SchemeForm(request.POST or None,
                      request.FILES or None,
                      instance=scheme)

    if request.method == 'POST':
        if form.is_valid():
            messages.info(request, u'scheme updated correctly little dragon!')

            redirect_url = reverse('scheme_detail', args=(scheme.id,))
            return redirect(redirect_url)
        else:
            messages.error(
                    request,
                    u'Something went wrong editing your Scheme.'\
                    u' Please, check it.')

    context['form'] = form
    return render_response(request, 'scheme-submit.html', context)