Skip to content

Commit

Permalink
email address model and manager
Browse files Browse the repository at this point in the history
git-svn-id: http://django-email-confirmation.googlecode.com/svn/trunk@9 e143efbd-a74b-0410-b764-bd10452ab0ba
  • Loading branch information
jtauber committed Apr 26, 2008
1 parent 65de627 commit 620fcc5
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions devproject/emailconfirmation/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
from django.db import models
from django.db import models, IntegrityError
from django.template.loader import render_to_string
from django.core.mail import send_mail
from django.conf import settings

# Create your models here.
from django.contrib.auth.models import User

# this code based in-part on django-registration

class EmailAddressManager(models.Manager):

def add_email(self, user, email):
try:
email_address = self.create(user=user, email=email)
subject = render_to_string("emailconfirmation/email_confirmation_subject.txt")
message = render_to_string("emailconfirmation/email_confirmation_message.txt")
# @@@ eventually use django-mailer
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email])
print "sent %s '%s' to %s" % (subject, message, email)
return email_address
except IntegrityError:
return None

class EmailAddress(models.Model):

user = models.ForeignKey(User)
email = models.EmailField()
verified = models.BooleanField(default=False)

objects = EmailAddressManager()

def __unicode__(self):
return u"%s (%s)" % (self.email, self.user)

class Meta:
unique_together = (
("user", "email"),
)

class Admin:
pass

0 comments on commit 620fcc5

Please sign in to comment.