def view_item(request, exception_id): success_message = None error_message = None bank = request.user.get_profile().bank # 0 means create a new one if exception_id != 0: ex = get_object_or_404(Exception, pk=exception_id, bank=bank) if request.method == 'POST': form = ExceptionForm(request.POST, instance=ex) if form.is_valid(): # do some processing (like saving it) form.save() success_message = "Data saved successfully." else: # form is not valid, display an error error_message = "There were errors in your submission." else: form = ExceptionForm(instance=ex) return render('exception/item.html', { 'module': 'exception', 'exception': ex, 'success_message': success_message, 'error_message': error_message, 'form': form }, request, 'exception/item_pdf.html')
def add(request): error_message = None success_message = None success_id = None success_name = None profile = request.user.get_profile() # ignore requests from users # who don't have access if profile.level < 1: raise Http404 bank = request.user.get_profile().bank if request.method == 'POST': # so some posty stuff form = ExceptionForm(request.POST) if form.is_valid(): # do some processing (like saving it) # use commit=False to allow us to # modify the new Exception before saving it new_ex = form.save(commit=False) new_ex.bank = bank new_ex.save() success_id = new_ex.id success_name = new_ex.actionItem form = ExceptionForm() # create a new blank form for the next one. else: # form is not valid, display an error error_message = "There were errors in your submission." else: # create a blank form form = ExceptionForm() return render('exception/add.html', { 'form': form, 'success_id': success_id, 'success_name': success_name, 'error_message': error_message, 'success_message': success_message }, request)