comparison gpp/core/functions.py @ 9:b3b11edf91d8

News: removed the lxml stuff. Based on Jacob Kaplan-Moss suggestion, use html5lib to clean html. Added that functionality in a new core.html module.
author Brian Neal <bgneal@gmail.com>
date Sun, 12 Apr 2009 02:03:03 +0000
parents dbd703f7d63a
children 91fd31dc78fb
comparison
equal deleted inserted replaced
8:d6f3c38e8f50 9:b3b11edf91d8
3 import django.core.mail 3 import django.core.mail
4 from django.contrib.sites.models import Site 4 from django.contrib.sites.models import Site
5 from django.conf import settings 5 from django.conf import settings
6 6
7 from core import logging 7 from core import logging
8 from lxml.html.clean import Cleaner
9
10 html_cleaner = Cleaner(scripts=True,
11 javascript=True,
12 comments=True,
13 style=True,
14 links=True,
15 meta=True,
16 page_structure=True,
17 processing_instructions=True,
18 embedded=True,
19 frames=True,
20 forms=True,
21 annoying_tags=True,
22 remove_unknown_tags=True,
23 safe_attrs_only=True,
24 host_whitelist=['www.youtube.com'],
25 whitelist_tags=['object', 'param', 'embed'],
26 )
27 8
28 9
29 def send_mail(subject, message, from_email, recipient_list, 10 def send_mail(subject, message, from_email, recipient_list,
30 fail_silently = False, auth_user = None, auth_password = None): 11 fail_silently = False, auth_user = None, auth_password = None):
31 """The main gpp send email function. 12 """The main gpp send email function.
59 msg, 40 msg,
60 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain), 41 '%s@%s' % (settings.GPP_NO_REPLY_EMAIL, site.domain),
61 [mail_tuple[1] for mail_tuple in settings.MANAGERS]) 42 [mail_tuple[1] for mail_tuple in settings.MANAGERS])
62 43
63 44
64 def clean_html(s):
65 """Cleans HTML of dangerous tags and content."""
66 if s:
67 return html_cleaner.clean_html(s)
68 return s
69
70
71 def get_full_name(user): 45 def get_full_name(user):
72 """Returns the user's full name if available, otherwise falls back 46 """Returns the user's full name if available, otherwise falls back
73 to the username.""" 47 to the username."""
74 full_name = user.get_full_name() 48 full_name = user.get_full_name()
75 if full_name: 49 if full_name:
76 return full_name 50 return full_name
77 return user.username 51 return user.username
52
53 # vim: ts=4 sw=4