From 9d12c0fac5c0580b30c6bf8f578a358dc22afdff Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 4 Mar 2011 12:13:29 -0600 Subject: Move new user email contents to template Signed-off-by: Dan McGee --- devel/views.py | 30 ++++++++++++++++++++---------- packages/views.py | 2 +- templates/devel/new_account.txt | 5 +++++ 3 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 templates/devel/new_account.txt diff --git a/devel/views.py b/devel/views.py index f89d6870..311922ca 100644 --- a/devel/views.py +++ b/devel/views.py @@ -4,6 +4,7 @@ from django.contrib.auth.models import User from django.contrib.sites.models import Site from django.core.mail import send_mail +from django.template import loader, Context from django.views.decorators.cache import never_cache from django.views.generic.simple import direct_to_template @@ -23,8 +24,8 @@ def index(request): '''the Developer dashboard''' inner_q = PackageRelation.objects.filter(user=request.user).values('pkgbase') - flagged = Package.objects.select_related('arch', 'repo').filter(flag_date__isnull=False) - flagged = flagged.filter(pkgbase__in=inner_q).order_by('pkgname') + flagged = Package.objects.select_related('arch', 'repo').filter( + flag_date__isnull=False, pkgbase__in=inner_q).order_by('pkgname') todopkgs = TodolistPkg.objects.select_related( 'pkg', 'pkg__arch', 'pkg__repo').filter(complete=False) @@ -111,25 +112,34 @@ class Meta: first_name = forms.CharField(required=False) last_name = forms.CharField(required=False) + def clean_username(self): + username = self.cleaned_data['username'] + if User.objects.filter(username=username).exists(): + raise forms.ValidationError( + "A user with that username already exists.") + return username + def save(self): profile = forms.ModelForm.save(self, False) pwletters = ascii_letters + digits - pw = ''.join([random.choice(pwletters) for i in xrange(8)]) + password = ''.join([random.choice(pwletters) for i in xrange(8)]) user = User.objects.create_user(username=self.cleaned_data['username'], - email=self.cleaned_data['email'], password=pw) + email=self.cleaned_data['email'], password=password) user.first_name = self.cleaned_data['first_name'] user.last_name = self.cleaned_data['last_name'] user.save() profile.user = user profile.save() - domain = Site.objects.get_current().domain + + t = loader.get_template('devel/new_account.txt') + c = Context({ + 'site': Site.objects.get_current(), + 'user': user, + 'password': password, + }) send_mail("Your new archweb account", - """You can now log into: -https://%s/login/ -with these login details: -Username: %s -Password: %s""" % (domain, user.username, pw), + t.render(c), 'Arch Website Notification ', [user.email], fail_silently=False) diff --git a/packages/views.py b/packages/views.py index 2291c4f4..59779fe4 100644 --- a/packages/views.py +++ b/packages/views.py @@ -8,7 +8,7 @@ from django.db.models import Q from django.http import HttpResponse, Http404 from django.shortcuts import get_object_or_404, redirect -from django.template import loader, Context, RequestContext +from django.template import loader, Context from django.utils import simplejson from django.views.decorators.cache import never_cache from django.views.decorators.http import require_POST diff --git a/templates/devel/new_account.txt b/templates/devel/new_account.txt new file mode 100644 index 00000000..1159992a --- /dev/null +++ b/templates/devel/new_account.txt @@ -0,0 +1,5 @@ +You can now log into https://{{ site.domain }}/login/ with these login details: +Username: {{ user.username }} +Password: {{ password }} + +Please update your profile once logged in and change your password. -- cgit v1.2.3-54-g00ecf