Exemplo n.º 1
0
def change_status(request, ccr_number):
	ccr = get_object_or_404(Ccr, ccr_number=ccr_number)
	if has_group(request.user, "Approvers"):
		form = ApproveStatusForm(request.POST or None, instance=ccr)
		#email = approver email 
		new_notification_for = ccr.entered_by
	else:
		form = ReviewStatusForm(request.POST or None, instance=ccr)
		new_notification_for = ccr.approver
		#email = reviewer email 

		
	if request.POST: 
		if form.is_valid():
			ccr = form.save(commit=False)
			new_rev = Revision(edited_by=request.user, ccr_ref=ccr, status_at_rev=ccr.status, date=datetime.now())
			
			#send_mail() 
			form.save()
			new_rev.save()
			notification = get_object_or_404(Notification, ccr=ccr)
			if "Rejected" not in ccr.status:
				notification.user = new_notification_for
			else:
				notification.user = ccr.entered_by
			notification.seen = False
			notification.save()
			return HttpResponseRedirect('/ccrform/ccr/'+str(ccr.ccr_number)+'/')	
	args = {}
	args['form'] = form
	args.update(csrf(request))
	return render(request, 'ccrform/review_ccr.html', args)
Exemplo n.º 2
0
def edit_ccr(request, ccr_number):

	ccr = get_object_or_404(Ccr, ccr_number=ccr_number)
	if request.user == ccr.entered_by:
		form = EditCcrForm(request.POST or None, instance=ccr)
		args = {}
		args['ccr'] = ccr
		if request.POST:
			if form.is_valid():
				new_rev = Revision(edited_by=request.user, ccr_ref=ccr, status_at_rev=ccr.status, date=datetime.now())
				new_rev.save() 
				form.save()
				if ccr.status == "Complete" or "Rejected":
					notification = get_object_or_404(Notification, ccr=ccr)
					notification.seen = True
					notification.save()
				if ccr.status == "For Review":
					notification.user = ccr.reviewer
					notification.seen = False 
					notification.save()
				return HttpResponseRedirect('/ccrform/ccr/'+str(ccr.ccr_number)+'/')
 
		else:
			form = EditCcrForm(request.POST or None, instance=ccr)
		args['form'] = form 
		args.update(csrf(request))
		return render(request, 'ccrform/edit_ccr.html', args) 
	else:	
		return noaccess(request)