Fix for loosing data when there is a form validation error. Issue #42.

Added info message when there is an validation error and items are not shown.
This commit is contained in:
Tom Price
2015-03-31 10:33:57 +01:00
parent 6e5c6fbb31
commit 93af55ccbb
3 changed files with 68 additions and 45 deletions

View File

@@ -17,6 +17,7 @@ from PyPDF2 import PdfFileMerger, PdfFileReader
from RIGS import models, forms
import datetime
import re
__author__ = 'ghost'
@@ -44,6 +45,17 @@ class EventCreate(generic.CreateView):
def get_context_data(self, **kwargs):
context = super(EventCreate, self).get_context_data(**kwargs)
context['edit'] = True
form = context['form']
if re.search('"-\d+"', form['items_json'].value()):
messages.info(self.request, "Your item changes have been saved. Please fix the errors and save the event.")
# Get some other objects to include in the form. Used when there are errors but also nice and quick.
for field, model in form.related_models.iteritems():
value = form[field].value()
if value is not None and value != '':
context[field] = model.objects.get(pk=value)
return context
def get_success_url(self):
@@ -57,6 +69,14 @@ class EventUpdate(generic.UpdateView):
def get_context_data(self, **kwargs):
context = super(EventUpdate, self).get_context_data(**kwargs)
context['edit'] = True
form = context['form']
# Get some other objects to include in the form. Used when there are errors but also nice and quick.
for field, model in form.related_models.iteritems():
value = form[field].value()
if value is not None and value != '':
context[field] = model.objects.get(pk=value)
return context
def get_success_url(self):