app/soc/logic/cleaning.py
changeset 1446 bcbbcb72429d
parent 1440 58ac0b3f59ac
child 1472 27c9ae3f8d8b
equal deleted inserted replaced
1445:c2e09f7d62d9 1446:bcbbcb72429d
    22     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
    22     '"Sverre Rabbelier" <sverre@rabbelier.nl>',
    23     '"Lennard de Rijk" <ljvderijk@gmail.com>',
    23     '"Lennard de Rijk" <ljvderijk@gmail.com>',
    24     ]
    24     ]
    25 
    25 
    26 
    26 
       
    27 import feedparser
       
    28 
    27 from google.appengine.api import users
    29 from google.appengine.api import users
    28 
    30 
    29 from django import forms
    31 from django import forms
    30 from django.forms.util import ErrorList
    32 from django.forms.util import ErrorList
    31 from django.utils.translation import ugettext
    33 from django.utils.translation import ugettext
    43 DEF_NO_RIGHTS_FOR_ACL_MSG = ugettext(
    45 DEF_NO_RIGHTS_FOR_ACL_MSG = ugettext(
    44     'You do not have the required rights for that ACL.')
    46     'You do not have the required rights for that ACL.')
    45 
    47 
    46 DEF_ORGANZIATION_NOT_ACTIVE_MSG = ugettext(
    48 DEF_ORGANZIATION_NOT_ACTIVE_MSG = ugettext(
    47     'This organization is not active/existent')
    49     'This organization is not active/existent')
    48 
       
    49 
    50 
    50 def check_field_is_empty(field_name):
    51 def check_field_is_empty(field_name):
    51   """Returns decorator that bypasses cleaning for empty fields.
    52   """Returns decorator that bypasses cleaning for empty fields.
    52   """
    53   """
    53 
    54 
   263     raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
   264     raise forms.ValidationError('This URL is not a valid ATOM or RSS feed.')
   264 
   265 
   265   return feed_url
   266   return feed_url
   266 
   267 
   267 
   268 
       
   269 def clean_document_content(self):
       
   270   content = self.cleaned_data.get('content')
       
   271 
       
   272   sanitizer = feedparser._HTMLSanitizer('utf-8')
       
   273   sanitizer.feed(content)
       
   274   content = sanitizer.output()
       
   275   content = content.strip().replace('\r\n', '\n')
       
   276 
       
   277   return content
       
   278 
   268 def clean_url(field_name):
   279 def clean_url(field_name):
   269   """Clean method for cleaning a field belonging to a LinkProperty.
   280   """Clean method for cleaning a field belonging to a LinkProperty.
   270   """
   281   """
   271 
   282 
   272   @check_field_is_empty(field_name)
   283   @check_field_is_empty(field_name)