python类NON_FIELD_ERRORS的实例源码

forms.py 文件源码 项目:planet-b-saleor 作者: planet-b 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def clean(self):
        cleaned_data = super(AddToCartForm, self).clean()
        quantity = cleaned_data.get('quantity')
        if quantity is None:
            return cleaned_data
        try:
            product_variant = self.get_variant(cleaned_data)
        except ObjectDoesNotExist:
            msg = self.error_messages['variant-does-not-exists']
            self.add_error(NON_FIELD_ERRORS, msg)
        else:
            cart_line = self.cart.get_line(product_variant)
            used_quantity = cart_line.quantity if cart_line else 0
            new_quantity = quantity + used_quantity
            try:
                product_variant.check_quantity(new_quantity)
            except InsufficientStock as e:
                remaining = e.item.get_stock_quantity() - used_quantity
                if remaining:
                    msg = self.error_messages['insufficient-stock']
                    self.add_error('quantity', msg % remaining)
                else:
                    msg = self.error_messages['empty-stock']
                    self.add_error('quantity', msg)
        return cleaned_data
forms.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
views.py 文件源码 项目:basket 作者: mozmeao 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def respond_error(request, form, message, code, template_name='news/formerror.html'):
    """
    Return either a JSON or HTML error response

    @param request: the request
    @param form: the bound form object
    @param message: the error message
    @param code: the HTTP status code
    @param template_name: the template name in case of HTML response
    @return: HttpResponse object
    """
    if request.is_ajax():
        return HttpResponseJSON({
            'status': 'error',
            'errors': [message],
            'errors_by_field': {NON_FIELD_ERRORS: [message]}
        }, code)
    else:
        form.add_error(None, message)
        return render(request, template_name, {'form': form}, status=code)
models.py 文件源码 项目:tissuelab 作者: VirtualPlants 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def _update_errors(self, errors):
        for field, messages in errors.error_dict.items():
            if field not in self.fields:
                continue
            field = self.fields[field]
            for message in messages:
                if isinstance(message, ValidationError):
                    if message.code in field.error_messages:
                        message.message = field.error_messages[message.code]

        message_dict = errors.message_dict
        for k, v in message_dict.items():
            if k != NON_FIELD_ERRORS:
                self._errors.setdefault(k, self.error_class()).extend(v)
                # Remove the data from the cleaned_data dict since it was invalid
                if k in self.cleaned_data:
                    del self.cleaned_data[k]
        if NON_FIELD_ERRORS in message_dict:
            messages = message_dict[NON_FIELD_ERRORS]
            self._errors.setdefault(NON_FIELD_ERRORS, self.error_class()).extend(messages)
forms.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
views.py 文件源码 项目:lighthouse 作者: dstl 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def form_invalid(self, form):
        """
        The user has provided invalid credentials (this was checked in
        AuthenticationForm.is_valid()). So now we set the test cookie again
        and re-render the form with errors.
        """
        self.set_test_cookie()
        if form.has_error(NON_FIELD_ERRORS, 'admin_user'):
            return HttpResponseRedirect('/admin/')
        return super(LoginView, self).form_invalid(form)
forms.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:tumanov_castleoaks 作者: Roamdev 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def error_dict_full(self):
        """
            ?????????? error_dict, ?? ????????????? ????????
            ?????? ???? ?????.
        """
        errors = self.error_dict
        if NON_FIELD_ERRORS in self.errors:
            errors = ({
                'name': NON_FIELD_ERRORS,
                'fullname': NON_FIELD_ERRORS,
                'class': '',
                'errors': self.errors[NON_FIELD_ERRORS],
            }, ) + errors

        return errors
forms.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:django_ecommerce 作者: rick-ey 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def addError(self, message):
        self._errors[NON_FIELD_ERRORS] = self.error_class([message])
forms.py 文件源码 项目:wanblog 作者: wanzifa 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:tabmaster 作者: NicolasMinghetti 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:trydjango18 作者: lucifer-yqh 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:ims 作者: ims-team 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:django-open-lecture 作者: DmLitov4 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:travlr 作者: gauravkulkarni96 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
test_models.py 文件源码 项目:volla 作者: sgrowe 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_one_vollume_cant_have_multiple_root_chunks(self):
        new_chunk = VollumeChunk(
            vollume=self.vollume,
            author=create_and_save_dummy_user(username='Stevo'),
            text='top stuff'
        )
        with self.assertRaises(ValidationError) as caught:
            new_chunk.full_clean()
        error_messages = caught.exception.message_dict[NON_FIELD_ERRORS]
        self.assertIn("A Vollume can't have more than one starting paragraph.", error_messages)
test_models.py 文件源码 项目:volla 作者: sgrowe 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_author_of_first_chunk_must_also_be_vollume_author(self):
        vollume = Vollume(
            author=create_and_save_dummy_user(username='Mickey'),
            title='Top dollar mate'
        )
        vollume.save()
        chunk = VollumeChunk(
            vollume=vollume,
            author=create_and_save_dummy_user(username='Steves'),
            text="Huh? Yeah, I just feel like... you know when you roll a blinding spliff?"
        )
        with self.assertRaises(ValidationError) as caught:
            chunk.full_clean()
        error_messages = caught.exception.message_dict[NON_FIELD_ERRORS]
        self.assertIn("The author of the first paragraph of a Vollume must also be the Vollume author.", error_messages)
forms.py 文件源码 项目:logo-gen 作者: jellene4eva 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:gmail_scanner 作者: brandonhub 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:CSCE482-WordcloudPlus 作者: ggaytan00 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:producthunt 作者: davidgengler 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:django-rtc 作者: scifiswapnil 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))
forms.py 文件源码 项目:geekpoint 作者: Lujinghu 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def non_field_errors(self):
        """
        Returns an ErrorList of errors that aren't associated with a particular
        field -- i.e., from Form.clean(). Returns an empty ErrorList if there
        are none.
        """
        return self.errors.get(NON_FIELD_ERRORS, self.error_class(error_class='nonfield'))


问题


面经


文章

微信
公众号

扫码关注公众号