Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def to_python(self, value):
- if self._linktype is None:
- raise ValidationError(_('Type for this field is not set.'))
- try:
- value = value.strip()
- if not value:
- raise ValueError
- except:
- return None
- if not self._animeobject:
- raise ValidationError(_('AnimeItem not set.'))
- if self._linktype == 0:
- for t, r, l in LINKS_URLS[1:]:
- if r:
- m = r.match(value)
- if m:
- self._linktype = t
- if l:
- value = l + m.groups()[-1]
- if not self._linktype:
- self._linktype = 15
- if self._linktype in (1, 2, 3) and value.isdecimal():
- value = LINKS_URLS[self._linktype][2] + value
- m = LINKS_URLS[self._linktype][1]
- if m and not m.match(value):
- raise ValidationError(_('Bad link type choosen.'))
- return super(TextToAnimeLinkField, self).to_python(value)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement