From 51e16052f7be18ffeb69c3a64d886830b058c98b Mon Sep 17 00:00:00 2001 From: hernani Date: Sat, 29 May 2010 22:05:55 +0000 Subject: [PATCH] Preparation for the new mail system. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@343 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/forms.py | 2 -- forum/templatetags/email_tags.py | 52 ++++++++++++++++++++++++++++++++ forum/tests.py | 23 -------------- 3 files changed, 52 insertions(+), 25 deletions(-) delete mode 100644 forum/tests.py diff --git a/forum/forms.py b/forum/forms.py index 66d78b2..0a5afe3 100644 --- a/forum/forms.py +++ b/forum/forms.py @@ -252,9 +252,7 @@ class EditUserForm(forms.Form): self.user = user def clean_email(self): - """For security reason one unique email in database""" if self.user.email != self.cleaned_data['email']: - #todo dry it, there is a similar thing in openidauth if settings.EMAIL_UNIQUE == True: if 'email' in self.cleaned_data: try: diff --git a/forum/templatetags/email_tags.py b/forum/templatetags/email_tags.py index 0f62bad..3597112 100644 --- a/forum/templatetags/email_tags.py +++ b/forum/templatetags/email_tags.py @@ -1,2 +1,54 @@ from django import template +register = template.Library() + +class MultiUserMailMessage(template.Node): + def __init__(self, nodelist): + self.nodelist = nodelist + + def render(self, context): + recipients = context['recipients'] + messages = list() + + for recipient in recipients: + context['recipient'] = recipient + self.nodelist.render(context) + messages.append((recipient, context['subject'], context['html_content'], context['text_content'])) + + print messages + +@register.tag +def email(parser, token): + nodelist = parser.parse(('endemail',)) + parser.delete_first_token() + return MultiUserMailMessage(nodelist) + + + +class EmailPartNode(template.Node): + def __init__(self, nodelist, varname): + self.nodelist = nodelist + self.varname = varname + + def render(self, context): + context[self.varname] = self.nodelist.render(context).strip() + +@register.tag +def subject(parser, token): + nodelist = parser.parse(('endsubject',)) + parser.delete_first_token() + return EmailPartNode(nodelist, 'subject') + +@register.tag +def htmlcontent(parser, token): + nodelist = parser.parse(('endhtmlcontent',)) + parser.delete_first_token() + return EmailPartNode(nodelist, 'html_content') + +@register.tag +def textcontent(parser, token): + nodelist = parser.parse(('endtextcontent',)) + parser.delete_first_token() + return EmailPartNode(nodelist, 'text_content') + + diff --git a/forum/tests.py b/forum/tests.py deleted file mode 100644 index 194262e..0000000 --- a/forum/tests.py +++ /dev/null @@ -1,23 +0,0 @@ -import unittest -from django.test.client import Client - -import forum.startup - -from forum.models import * -from forum.actions import * - -client = Client() - -class SanityTest(unittest.TestCase): - def testIndex(self): - self.assertEquals(client.get('/').status_code, 200) - -class FirstUsersTest(unittest.TestCase): - def setUp(self): - self.response = client.get('/') - - def testResponse(self): - self.assertEquals(self.response.status_code, 200) - - - -- 2.39.5