本文整理匯總了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))