forms.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:ISS 作者: RyanJenkins 项目源码 文件源码
def clean(self, value):
        value = super(BBCodeField, self).clean(value)

        if not isinstance(value, basestring):
            # Probably none, field might be optional, in any case there's no
            # use trying to parse this thing.
            return value

        counts = utils.get_tag_distribution(value)
        embedded_tags = counts['video'] + counts['img'] + counts['bc']
        cool_tags = counts['byusingthistagiaffirmlannyissupercool']
        max_embeds = utils.get_config('max_embedded_items')

        if embedded_tags > max_embeds:
            raise ValidationError(
                ('BBCode must contain %d or fewer embedded items. '
                 'Contained %d.') % (max_embeds, embedded_tags),
                code='TOO_MANY_EMBEDS')

        if cool_tags > 10:
            raise ValidationError(
                'Cool tag bro, but don\'t overuse it.',
                code='TOO_MUCH_COOL')

        return value
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号