diff options
Diffstat (limited to 'forum/utils')
-rwxr-xr-x | forum/utils/email.py | 21 | ||||
-rwxr-xr-x | forum/utils/forms.py | 4 | ||||
-rwxr-xr-x | forum/utils/lists.py | 4 | ||||
-rwxr-xr-x | forum/utils/time.py | 4 |
4 files changed, 33 insertions, 0 deletions
diff --git a/forum/utils/email.py b/forum/utils/email.py new file mode 100755 index 00000000..dc712572 --- /dev/null +++ b/forum/utils/email.py @@ -0,0 +1,21 @@ +from django.core.mail import send_mail, EmailMultiAlternatives +from django.conf import settings +from django.template import loader, Context +from django.utils.html import strip_tags +from threading import Thread + +def send_email(subject, recipients, template, context={}, sender=settings.DEFAULT_FROM_EMAIL, txt_template=None): + context['settings'] = settings + html_body = loader.get_template(template).render(Context(context)) + + if txt_template is None: + txt_body = strip_tags(html_body) + else: + txt_body = loader.get_template(txt_template).render(Context(context)) + + msg = EmailMultiAlternatives(subject, txt_body, sender, recipients) + msg.attach_alternative(html_body, "text/html") + + thread = Thread(target=EmailMultiAlternatives.send, args=[msg]) + thread.setDaemon(True) + thread.start() diff --git a/forum/utils/forms.py b/forum/utils/forms.py index c54056ca..c8305c7c 100755 --- a/forum/utils/forms.py +++ b/forum/utils/forms.py @@ -133,6 +133,10 @@ class SetPasswordForm(forms.Form): error_messages={'required':_('please, retype your password'), 'nomatch':_('sorry, entered passwords did not match, please try again')}, ) + + def __init__(self, data=None, user=None, *args, **kwargs): + super(SetPasswordForm, self).__init__(data, *args, **kwargs) + def clean_password2(self): """ Validates that the two password inputs match. diff --git a/forum/utils/lists.py b/forum/utils/lists.py index bbcfae98..f69c8f20 100755 --- a/forum/utils/lists.py +++ b/forum/utils/lists.py @@ -1,5 +1,9 @@ """Utilities for working with lists and sequences.""" +class LazyList(list): + def __init__(self, get_data): + self.data = get_data + def flatten(x): """ Returns a single, flat list which contains all elements retrieved diff --git a/forum/utils/time.py b/forum/utils/time.py new file mode 100755 index 00000000..39e01d0f --- /dev/null +++ b/forum/utils/time.py @@ -0,0 +1,4 @@ +import datetime + +def one_day_from_now(): + return datetime.datetime.now() + datetime.timedelta(days=1) |