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
评论列表
文章目录