summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-03-04 19:13:29 +0100
committerDan McGee <dan@archlinux.org>2011-03-04 19:13:29 +0100
commit9d12c0fac5c0580b30c6bf8f578a358dc22afdff (patch)
tree1cf29477638a864039dc1d94472c5ef58de480bf
parent3f4570c1995be17fefa9701e943ba9851113cd44 (diff)
downloadarchweb-9d12c0fac5c0580b30c6bf8f578a358dc22afdff.tar.gz
archweb-9d12c0fac5c0580b30c6bf8f578a358dc22afdff.tar.xz
Move new user email contents to template
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--devel/views.py30
-rw-r--r--packages/views.py2
-rw-r--r--templates/devel/new_account.txt5
3 files changed, 26 insertions, 11 deletions
diff --git a/devel/views.py b/devel/views.py
index f89d687..311922c 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -4,6 +4,7 @@ from django.contrib.auth.decorators import login_required, permission_required
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 @@ from string import ascii_letters, digits
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 NewUserForm(forms.ModelForm):
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 <nobody@archlinux.org>',
[user.email],
fail_silently=False)
diff --git a/packages/views.py b/packages/views.py
index 2291c4f..59779fe 100644
--- a/packages/views.py
+++ b/packages/views.py
@@ -8,7 +8,7 @@ from django.core.mail import send_mail
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 0000000..1159992
--- /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.