本文整理汇总了Python中django.forms.util.ErrorDict.keys方法的典型用法代码示例。如果您正苦于以下问题:Python ErrorDict.keys方法的具体用法?Python ErrorDict.keys怎么用?Python ErrorDict.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms.util.ErrorDict
的用法示例。
在下文中一共展示了ErrorDict.keys方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ReporterSearchForm
# 需要导入模块: from django.forms.util import ErrorDict [as 别名]
# 或者: from django.forms.util.ErrorDict import keys [as 别名]
class ReporterSearchForm(forms.Form):
q = forms.CharField(required=False, label='', widget=SearchInput(
attrs={'placeholder': _lazy('Search by keyword')}))
product = forms.ChoiceField(choices=PROD_CHOICES, label=_lazy('Product:'),
initial=FIREFOX.short, required=False)
version = forms.ChoiceField(required=False, label=_lazy('Version:'),
choices=VERSION_CHOICES[FIREFOX])
sentiment = forms.ChoiceField(required=False, label=_lazy('Sentiment:'),
choices=SENTIMENT_CHOICES)
locale = forms.ChoiceField(required=False, label=_lazy('Locale:'),
choices=LOCALE_CHOICES)
platform = forms.ChoiceField(required=False, label=_lazy('PLATFORM:'),
choices=PLATFORM_CHOICES)
manufacturer = forms.ChoiceField(required=False,
choices=MANUFACTURER_CHOICES)
device = forms.ChoiceField(required=False, choices=DEVICE_CHOICES)
date_start = forms.DateField(required=False, widget=DateInput(
attrs={'class': 'datepicker'}), label=_lazy('Date range:'))
date_end = forms.DateField(required=False, widget=DateInput(
# L10n: This indicates the second part of a date range.
attrs={'class': 'datepicker'}), label=_lazy('to'))
page = forms.IntegerField(widget=forms.HiddenInput, required=False)
# TODO(davedash): Make this prettier.
def __init__(self, *args, **kwargs):
"""Pick version choices and initial product based on site ID."""
super(ReporterSearchForm, self).__init__(*args, **kwargs)
self.fields['version'].choices = VERSION_CHOICES[FIREFOX]
# Show Mobile versions if that was picked by the user.
picked = None
if self.is_bound:
try:
picked = self.fields['product'].clean(self.data.get('product'))
except forms.ValidationError:
pass
if (picked == MOBILE.short or not self.is_bound and
settings.SITE_ID == settings.MOBILE_SITE_ID):
# We default to Firefox. Only change if this is the mobile site.
self.fields['product'].initial = MOBILE.short
self.fields['version'].choices = VERSION_CHOICES[MOBILE]
def clean(self):
cleaned = self.cleaned_data
# default date_end to today
if (self.cleaned_data.get('date_start') and
not self.cleaned_data.get('date_end')):
self.cleaned_data['date_end'] = date.today()
# Flip start and end if necessary.
if (cleaned.get('date_start') and cleaned.get('date_end') and
cleaned['date_start'] > cleaned['date_end']):
(cleaned['date_start'], cleaned['date_end']) = (
cleaned['date_end'], cleaned['date_start'])
# Ensure page is a natural number.
try:
cleaned['page'] = int(cleaned.get('page'))
assert cleaned['page'] > 0
except (TypeError, AssertionError):
cleaned['page'] = 1
if not cleaned.get('version'):
cleaned['version'] = (getattr(FIREFOX, 'default_version', None) or
Version(LATEST_BETAS[FIREFOX]).simplified)
elif cleaned['version'] == '--':
cleaned['version'] = ''
return cleaned
def full_clean(self):
"""
Like Django's but we don't delete cleaned_data on error.
"""
self._errors = ErrorDict()
if not self.is_bound: # Stop further processing.
return
self.cleaned_data = {}
# If the form is permitted to be empty, and none of the form data has
# changed from the initial data, short circuit any validation.
if self.empty_permitted and not self.has_changed():
return
self._clean_fields()
self._clean_form()
self._post_clean()
# Errors are for data-prudes
for field in self._errors.keys():
self.cleaned_data[field] = ''
self._errors = ErrorDict()