Ejemplo n.º 1
0
def edit_addition(request, addition_id):
    if auth.get_user(request).is_authenticated():
        additions = get_object_or_404(AgreementAddition, id=addition_id)
        form = AdditionForm(instance=additions)
        username = auth.get_user(request).username
        try:
            user = User.objects.get(username=username).first_name
        except:
            user = ''
        context = {
            'additions': additions,
            'username': username,
            'user': user,
            'form': form,
            'addition_id': addition_id,
        }
        context.update(csrf(request))
        if request.method == 'POST':
            form = AdditionForm(request.POST, request.FILES, instance=additions)
            if form.is_valid():
                addition = form.save(commit=False)
                addition.save()
                return redirect('/agreement/%s' % addition.addition_agreement_number)
            else:
                context.update({'error': 'True'})
                return render_to_response('agreement/edit_addition.html', context)
        return render_to_response('agreement/edit_addition.html', context)
    else:
        return HttpResponseRedirect('/login/')
Ejemplo n.º 2
0
def new_addition(request, agreement_id):
    if auth.get_user(request).is_authenticated():
        username = auth.get_user(request).username
        agreement = Agreement.objects.get(id=agreement_id)
        form = AdditionForm()
        try:
            user = User.objects.get(username=username).first_name
        except:
            user = ''
        context = {
            'username': username,
            'user': user,
            'form': form,
            'agreement_id': agreement_id,
        }
        context.update(csrf(request))
        if request.method == 'POST':
            form = AdditionForm(request.POST, request.FILES)
            if form.is_valid():
                addition = form.save(commit=False)
                addition.addition_agreement_number = agreement_id
                addition.save()
                agreement.agreement_addition.add(addition)
                return redirect('/agreement/%s' % agreement_id)
            else:
                context.update({'error': 'True'})
                return render_to_response('agreement/new_addition.html', context)
        return render_to_response('agreement/new_addition.html', context)
    else:
        return HttpResponseRedirect('/login/')