Advertisement
Guest User

Untitled

a guest
Oct 27th, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1.     def to_python(self, value):
  2.         if self._linktype is None:
  3.             raise ValidationError(_('Type for this field is not set.'))
  4.         try:
  5.             value = value.strip()
  6.             if not value:
  7.                 raise ValueError
  8.         except:
  9.             return None
  10.         if not self._animeobject:
  11.             raise ValidationError(_('AnimeItem not set.'))
  12.         if self._linktype == 0:
  13.             for t, r, l in LINKS_URLS[1:]:
  14.                 if r:
  15.                     m = r.match(value)
  16.                     if m:
  17.                         self._linktype = t
  18.                         if l:
  19.                             value = l + m.groups()[-1]
  20.             if not self._linktype:
  21.                 self._linktype = 15
  22.         if self._linktype in (1, 2, 3) and value.isdecimal():
  23.             value = LINKS_URLS[self._linktype][2] + value
  24.         m = LINKS_URLS[self._linktype][1]
  25.         if m and not m.match(value):
  26.             raise ValidationError(_('Bad link type choosen.'))
  27.         return super(TextToAnimeLinkField, self).to_python(value)
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement