当前位置: 首页>>代码示例>>Python>>正文


Python forms.ValidationError方法代码示例

本文整理汇总了Python中django.forms.ValidationError方法的典型用法代码示例。如果您正苦于以下问题:Python forms.ValidationError方法的具体用法?Python forms.ValidationError怎么用?Python forms.ValidationError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms的用法示例。


在下文中一共展示了forms.ValidationError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clean_username

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean_username(self):
        reserved = (
            'admin',
            'orders',
            'sales',
            'devices',
            'customers',
            'notes',
            'api',
            'checkin',
            'feedback',
        )
        username = self.cleaned_data.get('username')
        if username in reserved:
            raise forms.ValidationError(_(u'"%s" cannot be used as a username') % username)

        return username 
开发者ID:fpsw,项目名称:Servo,代码行数:19,代码来源:admin.py

示例2: clean

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean(self):
        self.ip = self.request.META.get(conf.IP_HEADER, None)
        if not is_payfast_ip_address(self.ip):
            raise forms.ValidationError('untrusted ip: %s' % self.ip)

        # Verify signature
        sig = api.itn_signature(self.data)
        if sig != self.cleaned_data['signature']:
            raise forms.ValidationError('Signature is invalid: %s != %s' % (
                sig, self.cleaned_data['signature'],))

        if conf.USE_POSTBACK:
            is_valid = api.data_is_valid(self.request.POST, conf.SERVER)
            if is_valid is None:
                raise forms.ValidationError('Postback fails')
            if not is_valid:
                raise forms.ValidationError('Postback validation fails')

        return self.cleaned_data 
开发者ID:PiDelport,项目名称:django-payfast,代码行数:21,代码来源:forms.py

示例3: clean_image

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean_image(self):
        image = self.cleaned_data.get('image')
        if image:
            try:
                if image._size > settings.SPEAKER_IMAGE_MAXIMUM_FILESIZE_IN_MB * 1024 * 1024:
                    raise forms.ValidationError(
                        _('Maximum size is %d MB')
                        % settings.SPEAKER_IMAGE_MAXIMUM_FILESIZE_IN_MB
                    )
            except AttributeError:
                pass

            w, h = get_image_dimensions(image)
            if w < settings.SPEAKER_IMAGE_MINIMUM_DIMENSION[0] \
                    or h < settings.SPEAKER_IMAGE_MINIMUM_DIMENSION[1]:
                raise forms.ValidationError(
                    _('Minimum dimension is %d x %d')
                    % settings.SPEAKER_IMAGE_MINIMUM_DIMENSION
                )

        return image 
开发者ID:pythonkr,项目名称:pyconkr-2015,代码行数:23,代码来源:forms.py

示例4: confirm_login_allowed

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def confirm_login_allowed(self, user):
        """
        Controls whether the given User may log in. This is a policy setting,
        independent of end-user authentication. This default behavior is to
        allow login by active users, and reject login by inactive users.

        If the given user cannot log in, this method should raise a
        ``forms.ValidationError``.

        If the given user may log in, this method should return None.
        """
        if not user.is_active:
            raise forms.ValidationError(
                self.error_messages['inactive'],
                code='inactive',
            ) 
开发者ID:tmm,项目名称:django-username-email,代码行数:18,代码来源:forms.py

示例5: config_to_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def config_to_form(self, data, points):
        # undo the .clean just so it can be re-done for validation
        formdata = super().config_to_form(data, points)
        if 'options' not in formdata:
            raise forms.ValidationError(' missing ["options"]')
        options = formdata['options']
        del formdata['options']

        for i, (opt, marks) in enumerate(options):
            formdata['options_%i' % (i,)] = str(opt)
            try:
                formdata['options_%i' % (MAX_MC_CHOICES+i,)] = Decimal(marks)
            except ValueError:
                raise forms.ValidationError(' marks must be an integer (or decimal represented as a string).')

        if 'permute' not in formdata:
            formdata['permute'] = 'keep'
        if 'show_no_answer' not in formdata:
            formdata['show_no_answer'] = 'noshow'

        return formdata 
开发者ID:sfu-fas,项目名称:coursys,代码行数:23,代码来源:mc.py

示例6: clean_letter_review

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean_letter_review(self):
        review = self.cleaned_data['letter_review']
        if review:
            # cannot set to true if other required fields not filled in
            case = self.instance
            step = case.next_step()
            if step in PRE_LETTER_STEPS:
                raise forms.ValidationError(
                    mark_safe('Cannot finalize letter: have not entered <a href="%s">%s</a>.'
                        % (reverse('offering:discipline:edit_case_info',
                            kwargs={'field': STEP_VIEW[step], 'course_slug':case.offering.slug, 'case_slug':case.slug}),
                        STEP_DESC[step])))

            # cannot set to true if too many attachments
            if case.public_attachments_size() > MAX_ATTACHMENTS:
                raise forms.ValidationError('Total size of public attachments must be at most %s because of email limitations. Please make some of the attachments private.' % (MAX_ATTACHMENTS_TEXT))


        return review 
开发者ID:sfu-fas,项目名称:coursys,代码行数:21,代码来源:forms.py

示例7: clean

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean(self):
        letter_sent = self.cleaned_data.get('letter_sent', '')
        date = self.cleaned_data.get('letter_date', '')
        text = self.cleaned_data.get('letter_text', '')
        case = self.instance

        if letter_sent=="MAIL":
            if not case.letter_review:
                raise forms.ValidationError(
                    mark_safe('Cannot send letter: it has not <a href="%s">been reviewed</a>.'
                        % (reverse('offering:discipline:edit_case_info',
                            kwargs={'field': 'letter_review', 'course_slug':case.offering.slug, 'case_slug':case.slug}))))
            self.instance.send_letter_now = True # trigger email sending in view logic
        elif letter_sent=="OTHR":
            if not text.strip():
                raise forms.ValidationError('Please enter details of the letter delivery.')
            if not date:
                raise forms.ValidationError('Please enter the date the letter was sent.')

        return self.cleaned_data 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:forms.py

示例8: clean_tag

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean_tag(self):
            # https://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
            tag = self.cleaned_data['tag']

            if '..' in tag or tag[-1] == '.':
                raise forms.ValidationError('Tag names cannot contain ".." or end with a dot.')

            if not all(_tag_allowed(c) for c in tag):
                raise forms.ValidationError('Tag name contains an illegal character.')

            if tag[0] == '/' or tag[-1] == '/' or '//' in tag:
                raise forms.ValidationError('Tags cannot start or end with a slash, or contain consecutive slashes.')

            if '@{' in tag:
                raise forms.ValidationError('Tags cannot contain "@{".')

            if tag == '@':
                raise forms.ValidationError('"@" is not a valid tag name.')

            return tag 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:gittag.py

示例9: clean_url

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean_url(self):
            url = self.cleaned_data['url']
            if self.check_is_empty(url):
                raise forms.ValidationError("No URL given.")

            if self.component.prefix:
                # check that the URL starts with the provided prefix
                if not url.startswith(self.component.prefix):
                    raise forms.ValidationError('Submitted URL must start with "%s".' % (self.component.prefix))

            if self.component.check:
                # instructor asked to check that URLs really exist: do it.
                validator = QuickURLValidator()
                try:
                    validator(url) # throws ValidationError if there's a problem
                except forms.ValidationError:
                    # re-throw to produce a better error message
                    raise forms.ValidationError("The submitted URL doesn't seem to exist: please check the URL and resubmit.")
            return url 
开发者ID:sfu-fas,项目名称:coursys,代码行数:21,代码来源:url.py

示例10: clean

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean(self):
        name = self.cleaned_data["name"]
        parent = self.cleaned_data.get("parent")
        if Folder.already_exists(name, parent):
            raise forms.ValidationError(f"{name} already exists.") 
开发者ID:pinax,项目名称:pinax-documents,代码行数:7,代码来源:forms.py

示例11: clean_file

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean_file(self):
        value = self.cleaned_data["file"]
        if (value.size + self.storage.bytes_used) > self.storage.bytes_total:
            raise forms.ValidationError("File will exceed storage capacity.")
        return value 
开发者ID:pinax,项目名称:pinax-documents,代码行数:7,代码来源:forms.py

示例12: clean

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean(self):
        cd = super(CustomerSearchForm, self).clean()

        for k, v in cd.items():
            if v not in ['', None]:
                return cd

        raise forms.ValidationError(_('Please specify at least one parameter')) 
开发者ID:fpsw,项目名称:Servo,代码行数:10,代码来源:customer.py

示例13: clean_datafile

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean_datafile(self):
        d = self.cleaned_data.get('datafile')
        if not d.content_type.startswith('text'):
            raise forms.ValidationError(_('Data file should be in text format'))
        return d 
开发者ID:fpsw,项目名称:Servo,代码行数:7,代码来源:customer.py

示例14: clean

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean(self, *args, **kwargs):
        cd = super(GsxRepairForm, self).clean(*args, **kwargs)
        if self.instance.has_serialized_parts():
            if cd.get('mark_complete') and not cd.get('replacement_sn'):
                error = _('Replacement serial number must be set when completing repair.')
                raise forms.ValidationError(error)

        return cd 
开发者ID:fpsw,项目名称:Servo,代码行数:10,代码来源:repairs.py

示例15: clean_attachment

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import ValidationError [as 别名]
def clean_attachment(self):
        max_filesize = 10 * 1024 * 1024  # 10MB
        from django.template.defaultfilters import filesizeformat
        f = self.cleaned_data.get('attachment')
        if f and f.size > max_filesize:
            size = filesizeformat(max_filesize)
            error = _('Attachment should be no larger than %s') % size
            raise forms.ValidationError(error)

        return f 
开发者ID:fpsw,项目名称:Servo,代码行数:12,代码来源:repairs.py


注:本文中的django.forms.ValidationError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。