1
0
mirror of https://github.com/django/django.git synced 2025-07-05 10:19:20 +00:00

Possible fix for #499. Also gets error handling working properly in the admin without changing field names.

git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@748 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Robert Wittams 2005-09-30 17:17:50 +00:00
parent eb07d93938
commit e6c080db2b
4 changed files with 31 additions and 21 deletions

View File

@ -300,12 +300,16 @@ class FormField:
def convert_post_data(self, new_data):
name = self.get_member_name()
if new_data.has_key(name):
d = new_data.getlist(name)
if new_data.has_key(self.field_name):
d = new_data.getlist(self.field_name)
#del new_data[self.field_name]
new_data.setlist(name,
[self.__class__.html2python(data)
for data in d])
try:
converted_data = [self.__class__.html2python(data)
for data in d]
except ValueError:
converted_data = d
new_data.setlist(name, converted_data)
else:
try:
# individual fields deal with None values themselves
@ -860,6 +864,9 @@ class CommaSeparatedIntegerField(TextField):
except validators.ValidationError, e:
raise validators.CriticalValidationError, e.messages
def html2python(data):
return data.split(',');
class XMLLargeTextField(LargeTextField):
"""
A LargeTextField with an XML validator. The schema_path argument is the

View File

@ -859,12 +859,6 @@ def method_save(opts, self):
# If it does already exist, do an UPDATE.
if cursor.fetchone():
db_values = [f.get_db_prep_save(f.pre_save(getattr(self, f.column), False)) for f in non_pks]
while 1:
try:
idx = db_values.index('')
non_pks[idx:idx+1] = []
db_values[idx:idx +1] = []
except: break
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % (opts.db_table,
','.join(['%s=%%s' % f.column for f in non_pks]), opts.pk.column),
db_values + [pk_val])

View File

@ -163,7 +163,7 @@ class Field(object):
"""
Returns a list of field names that this object adds to the manipulator.
"""
return [name_prefix + self.column]
return [name_prefix + self.name]
def get_manipulator_fields(self, opts, manipulator, change, name_prefix='', rel=False):
"""
@ -638,6 +638,12 @@ class ForeignKey(Field):
def get_manipulator_field_objs(self):
return [formfields.IntegerField]
def get_db_prep_save(self,value):
if value == '':
return None
else:
return int(value)
def flatten_data(self, obj = None):
if not obj:
# In required many-to-one fields with only one available choice,

View File

@ -686,11 +686,12 @@ def add_stage_new(request, app_label, module_name, show_delete=False, form_url='
if opts.has_field_type(meta.FileField):
new_data.update(request.FILES)
errors = manipulator.get_validation_errors(new_data)
manipulator.do_html2python(new_data)
if not errors and not request.POST.has_key("_preview"):
for f in opts.many_to_many:
if f.rel.raw_id_admin:
new_data.setlist(f.name, new_data[f.name].split(","))
manipulator.do_html2python(new_data)
new_object = manipulator.save(new_data)
pk_value = getattr(new_object, opts.pk.column)
log.log_action(request.user.id, opts.get_content_type_id(), pk_value, repr(new_object), log.ADDITION)
@ -711,8 +712,8 @@ def add_stage_new(request, app_label, module_name, show_delete=False, form_url='
else:
request.user.add_message(msg)
return HttpResponseRedirect(post_url)
if request.POST.has_key("_preview"):
manipulator.do_html2python(new_data)
# if request.POST.has_key("_preview"): # Always happens anyway.
# manipulator.do_html2python(new_data)
else:
# Add default data.
new_data = manipulator.flatten_data()
@ -757,11 +758,13 @@ def change_stage_new(request, app_label, module_name, object_id):
new_data.update(request.FILES)
errors = manipulator.get_validation_errors(new_data)
manipulator.do_html2python(new_data)
if not errors and not request.POST.has_key("_preview"):
for f in opts.many_to_many:
if f.rel.raw_id_admin:
new_data.setlist(f.name, new_data[f.name].split(","))
manipulator.do_html2python(new_data)
# Now done in commaseparatedint
# for f in opts.many_to_many:
# if f.rel.raw_id_admin:
# new_data.setlist(f.name, new_data[f.name].split(","))
new_object = manipulator.save(new_data)
pk_value = getattr(new_object, opts.pk.column)
@ -794,8 +797,8 @@ def change_stage_new(request, app_label, module_name, object_id):
else:
request.user.add_message(msg)
return HttpResponseRedirect("../")
if request.POST.has_key("_preview"):
manipulator.do_html2python(new_data)
# if request.POST.has_key("_preview"): # always happens
# manipulator.do_html2python(new_data)
else:
# Populate new_data with a "flattened" version of the current data.
new_data = manipulator.flatten_data()