def edit_agreement(request, agreement_id): if auth.get_user(request).is_authenticated(): agreement = get_object_or_404(Agreement, id=agreement_id) form = AgreementForm(instance=agreement) username = auth.get_user(request).username try: user = User.objects.get(username=username).first_name except Exception: user = '' context = { 'agreement': agreement, 'username': username, 'user': user, 'form': form, } context.update(csrf(request)) if request.method == 'POST': form = AgreementForm(request.POST, request.FILES, instance=agreement) if form.is_valid(): agreement = form.save(commit=False) agreement.save() return redirect('/agreement/%s' % agreement.id) else: context.update({'error': 'True'}) return render_to_response('agreement/edit_agreement.html', context) return render_to_response('agreement/edit_agreement.html', context) else: return HttpResponseRedirect('/login/')
def new_agreement(request): if auth.get_user(request).is_authenticated(): username = auth.get_user(request).username try: id = Agreement.objects.last().agreement_id except Exception: id = 999 new_id = id + 1 form = AgreementForm(initial={'agreement_id': new_id}) try: user = User.objects.get(username=username).first_name except Exception: user = '' context = { 'username': username, 'user': user, 'form': form, } context.update(csrf(request)) if request.method == 'POST': form = AgreementForm(request.POST, request.FILES) if form.is_valid(): agreement = form.save(commit=False) agreement.save() return redirect('/agreement/%s' % agreement.id) else: context.update({'error': 'True'}) return render_to_response('agreement/new_agreement.html', context) return render_to_response('agreement/new_agreement.html', context) else: return HttpResponseRedirect('/login/')
def agreement_input_view(request): form = AgreementForm(request.POST or None) print(request.POST) if '_next' in request.POST and form.is_valid(): post = form.save(commit=False) post.agreement_date = request.POST['agreement_date'] post.effected_date_as_actual = request.POST['effected_date_as_actual'] post.effected_date_as_per_agreement = request.POST[ 'effected_date_as_per_agreement'] post.agreement_cat_type = request.POST['agreement_cat_type'] post.notice_period = request.POST['notice_period'] post.file_no = request.POST['file_no'] post.serial_no = request.POST['serial_no'] post.agreement_advance_amount = request.POST[ 'agreement_advance_amount'] post.agreement_security_amount = request.POST[ 'agreement_security_amount'] site1 = form['main_site'].value() print(site1) print(" test begin") print(post.properties.type) print("test end") post.properties.type = 'not available' print(post.properties.type) post.properties.save() post.agrm_id = create_id_for_agreement(post.main_site, post.file_no, post.serial_no) post.save() return redirect(agreement_detail_view, pk=post.id) else: print(form.errors) if '_save' in request.POST and form.is_valid(): post = form.save(commit=False) post = form.save(commit=False) post.agreement_date = request.POST['agreement_date'] post.effected_date_as_actual = request.POST['effected_date_as_actual'] post.effected_date_as_per_agreement = request.POST[ 'effected_date_as_per_agreement'] post.agreement_cat_type = request.POST['agreement_cat_type'] post.notice_period = request.POST['notice_period'] post.file_no = request.POST['file_no'] post.serial_no = request.POST['serial_no'] post.agreement_advance_amount = request.POST[ 'agreement_advance_amount'] post.agreement_security_amount = request.POST[ 'agreement_security_amount'] site1 = form['main_site'].value() post.agrm_id = create_id_for_agreement(post.main_site, post.file_no, post.serial_no) post.save() return redirect(agreement_view) else: print(form.errors) return render(request, 'agreement/agreement.html', {'form': form})