Exemplo n.º 1
0
 def save(self):
     data = self.cleaned_data               
                 
     account = Account(
         firstname=data['firstname'],
         lastname=data['lastname'],            
         email=data['email'],
         is_active=True,
     )            
     account.set_password(data['password'])            
     account.save()
     
     # email the password to the user                
     from django.core.mail import send_mail
     from django.template import Template, Context, loader  
     context = Context({            
         'account': account,
         'password': data['password'],
         'sitename': settings.SITENAME,
         'seymour_domain': settings.SEYMOUR_DOMAIN            
     })
     
     subject = u"Welcome to %s" % (settings.SITENAME)
     t = loader.get_template('emails/account_added.email')            
     
     email_body = t.render(context)
     if settings.DEBUG:
         print "Subject: " + subject.encode('utf8')
         print "-"*80
         print email_body.encode('utf8')
     else:
         send_mail(subject, email_body, settings.EMAIL_FROM, [account.email], fail_silently=True)
     
     return account