Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Update to django-email-confirmation #1

Open
wants to merge 1 commit into from

2 participants

@bradbeattie

Adds HTML email support

Brad Beattie Updates devproject to work with Django 1.3
Adds HTML email support
e1b6bc2
@paltman
Owner

Brad,

Really appreciate your patch here and like the idea of email-confirmation supporting HTML emails, however, I would like to see it as an optional addition driven by a setting that defaults to False. So if something like EMAIL_CONFIRMATION_HTML_EMAILS = True is in settings.py then do the multipart building and rendering of the HTML template, otherwise, it functions as it always has.

Does that make sense?

Thanks,
Patrick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 16, 2011
  1. Updates devproject to work with Django 1.3

    Brad Beattie authored
    Adds HTML email support
This page is out of date. Refresh to see the latest.
View
2  .gitignore
@@ -0,0 +1,2 @@
+*.pyc
+devproject/dev.db
View
9 devproject/devtest/forms.py
@@ -1,5 +1,5 @@
-from django import newforms as forms
-from django.core.validators import alnum_re
+from django import forms
+import re
from django.contrib.auth.models import User
from emailconfirmation.models import EmailAddress
@@ -14,7 +14,7 @@ class SignupForm(forms.Form):
email = forms.EmailField(label="Email (optional)", required=False, widget=forms.TextInput())
def clean_username(self):
- if not alnum_re.search(self.cleaned_data["username"]):
+ if not re.compile(r'^\w+$').search(self.cleaned_data["username"]):
raise forms.ValidationError(u"Usernames can only contain letters, numbers and underscores.")
try:
user = User.objects.get(username__exact=self.cleaned_data["username"])
@@ -35,7 +35,6 @@ def save(self):
password = self.cleaned_data["password1"]
new_user = User.objects.create_user(username, email, password)
if email:
- self.user.message_set.create(message="Confirmation email sent to %s" % email)
EmailAddress.objects.add_email(new_user, email)
return username, password # required for authenticate()
@@ -58,4 +57,4 @@ def clean_email(self):
def save(self):
self.user.message_set.create(message="Confirmation email sent to %s" % self.cleaned_data["email"])
return EmailAddress.objects.add_email(self.user, self.cleaned_data["email"])
-
+
View
1  devproject/emailconfirmation
View
2  devproject/urls.py
@@ -11,5 +11,5 @@
(r'^confirm_email/(\w+)/$', 'emailconfirmation.views.confirm_email'),
- (r'^admin/(.*)', admin.site.root),
+ (r'^admin/', include(admin.site.urls))
)
View
10 emailconfirmation/models.py
@@ -3,7 +3,7 @@
from django.conf import settings
from django.db import models, IntegrityError
-from django.core.mail import send_mail
+from django.core.mail import send_mail, EmailMultiAlternatives
from django.core.urlresolvers import reverse, NoReverseMatch
from django.template.loader import render_to_string
from django.utils.hashcompat import sha_constructor
@@ -118,9 +118,13 @@ def send_confirmation(self, email_address):
"emailconfirmation/email_confirmation_subject.txt", context)
# remove superfluous line breaks
subject = "".join(subject.splitlines())
- message = render_to_string(
+ text_content = render_to_string(
"emailconfirmation/email_confirmation_message.txt", context)
- send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email_address.email])
+ html_content = render_to_string(
+ "emailconfirmation/email_confirmation_message.html", context)
+ msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [email_address.email])
+ msg.attach_alternative(html_content, "text/html")
+ msg.send()
confirmation = self.create(
email_address=email_address,
sent=datetime.datetime.now(),
View
10 emailconfirmation/templates/emailconfirmation/email_confirmation_message.html
@@ -0,0 +1,10 @@
+<html>
+<body>
+<p>
+{% load i18n %}{% blocktrans with current_site.name as site_name %}User '{{ user }}' at {{ site_name }} has given this as an email address.
+
+To confirm this is correct, go to {{ activate_url }}
+{% endblocktrans %}
+</p>
+</body>
+</html>
View
2  setup.py
@@ -12,7 +12,7 @@
packages=find_packages(exclude=["devproject.devtest", "devproject"]),
package_data = {
"emailconfirmation": [
- "templates/emailconfirmation/*.txt"
+ "templates/emailconfirmation/*"
],
},
zip_safe=False,
Something went wrong with that request. Please try again.