本文整理汇总了Python中django.forms.util.ErrorDict.update方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorDict.update方法的具体用法?Python ErrorDict.update怎么用?Python ErrorDict.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.util.ErrorDict
的用法示例。
在下文中一共展示了ErrorDict.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from django.forms.util import ErrorDict [as 别名]
# 或者: from django.forms.util.ErrorDict import update [as 别名]
def render(self, context):
form = self.form.resolve(context, True)
hidden_fields_errors = ErrorDict()
for field in form.hidden_fields():
if field.errors:
hidden_fields_errors.update({field.name: field.errors})
context[self.as_var] = hidden_fields_errors
return ""
示例2: edit
# 需要导入模块: from django.forms.util import ErrorDict [as 别名]
# 或者: from django.forms.util.ErrorDict import update [as 别名]
def edit(request, pk=1, errors=None, reverse=False):
"""Edit main profile data if user is authorized"""
template = 'profiles/edit.html'
result = 'Error'
if errors is None:
errors = ErrorDict()
target = Profile.objects.get(pk=pk)
if request.method == 'POST' and request.user.is_authenticated():
profile = ProfileForm(request.POST, request.FILES, instance=target)
contacts = ContactFormSet(request.POST, request.FILES,
instance=target)
if profile.is_valid() and contacts.is_valid():
contacts.save()
profile.save()
result = 'Done'
if not profile.is_valid():
errors.update(profile.errors)
if not contacts.is_valid():
for num, suberrors in enumerate(contacts.errors):
if suberrors:
for field, error in suberrors.iteritems():
field_id = "%s-%s-%s" % (contacts.prefix, num, field)
errors.update({field_id: error})
if (request.method == 'GET' or not request.user.is_authenticated()
or errors):
profile = ProfileForm(instance=target)
contacts = ContactFormSet(instance=target)
if reverse:
profile.fields.keyOrder.reverse()
contacts.forms.reverse()
template = 'profiles/edit_reversed.html'
if not request.user.is_authenticated():
readonly(profile)
readonly(contacts)
errors['auth: '] = 'you are not authorized to edit this form'
if request.is_ajax():
return HttpResponse(simplejson.dumps({'result': result,
'errors': errors}),
mimetype='application/javascript')
else:
print(errors)
return render_to_response(template, {'profile': profile,
'contacts': contacts,
'errors': errors},
context_instance=RequestContext(request))