# HG changeset patch # User Sverre Rabbelier # Date 1236292206 0 # Node ID 242ca517c3401e18542235fe04dad41bac1bed00 # Parent b0e10552f5c2caec2cacc31be072fe22ce186aea Make clean_document_content generic Also allow all input for Developers. Patch by: Sverre Rabbelier diff -r b0e10552f5c2 -r 242ca517c340 app/soc/logic/cleaning.py --- a/app/soc/logic/cleaning.py Thu Mar 05 22:29:29 2009 +0000 +++ b/app/soc/logic/cleaning.py Thu Mar 05 22:30:06 2009 +0000 @@ -288,17 +288,28 @@ return feed_url -def clean_document_content(self): - """Clean method for cleaning document content. +def clean_html_content(field_name): + """Clean method for cleaning HTML content. """ - content = self.cleaned_data.get('content') + + @check_field_is_empty(field_name) + def wrapped(self): + """Decorator wrapper method. + """ + + content = self.cleaned_data.get(field_name) - sanitizer = feedparser._HTMLSanitizer('utf-8') - sanitizer.feed(content) - content = sanitizer.output() - content = content.strip().replace('\r\n', '\n') + if user_logic.isDeveloper(): + return content - return content + sanitizer = feedparser._HTMLSanitizer('utf-8') + sanitizer.feed(content) + content = sanitizer.output() + content = content.strip().replace('\r\n', '\n') + + return content + + return wrapped def clean_url(field_name): """Clean method for cleaning a field belonging to a LinkProperty. diff -r b0e10552f5c2 -r 242ca517c340 app/soc/views/models/document.py --- a/app/soc/views/models/document.py Thu Mar 05 22:29:29 2009 +0000 +++ b/app/soc/views/models/document.py Thu Mar 05 22:30:06 2009 +0000 @@ -84,7 +84,7 @@ 'prefix': forms.fields.CharField(widget=widgets.ReadOnlyInput(), required=True), - 'clean_content': cleaning.clean_document_content, + 'clean_content': cleaning.clean_html_content('content'), 'clean_link_id': cleaning.clean_link_id('link_id'), 'clean_scope_path': cleaning.clean_scope_path('scope_path'), 'clean': cleaning.validate_document_acl(self),