Initial import for public release...
[archweb_dev-nj.git] / devel / views.py
blobdea652bed932b36ab2bb069c0263f135135d757c
1 from django.http import HttpResponse, HttpResponseRedirect
2 from django.contrib.auth.decorators import login_required
3 from django.contrib.auth.models import User
4 from django.core import validators
5 from archlinux.utils import render_template
6 from archlinux.packages.models import Package
7 from archlinux.todolists.models import Todolist, TodolistPkg
8 from archlinux.settings import DATA_DIR
9 from archlinux.utils import validate
10 from archlinux.common.models import UserProfile
12 @login_required
13 def index(request):
14 try:
15 thismaint = User.objects.get(username=request.user.username)
16 except User.DoesNotExist:
17 # weird, we don't have a maintainer record for this logged-in user
18 thismaint = None
20 # get a list of incomplete package todo lists
21 todos = Todolist.objects.get_incomplete()
22 # get flagged-package stats for all maintainers
23 stats = Package.objects.get_flag_stats()
24 if thismaint:
25 # get list of flagged packages for this maintainer
26 pkgs = Package.objects.filter(maintainer=thismaint.id).filter(needupdate=True).order_by('repo', 'pkgname')
27 else:
28 pkgs = None
30 return render_template('devel/index.html', request,
31 {'stats':stats, 'pkgs':pkgs, 'todos':todos, 'maint':thismaint})
33 @login_required
34 #@is_maintainer
35 def change_notify(request):
36 maint = User.objects.get(username=request.user.username)
37 notify = request.POST.get('notify', 'no')
38 try:
39 maint.get_profile().notify = notify == 'yes'
40 except UserProfile.DoesNotExist:
41 UserProfile(user_id=maint.id ,notify=notify == 'yes').save()
42 maint.get_profile().save()
43 return HttpResponseRedirect('/devel/')
45 @login_required
46 def change_profile(request):
47 errors = {}
48 if request.POST:
49 passwd1, passwd2 = request.POST['passwd'], request.POST['passwd2']
50 email = request.POST['email']
51 # validate
52 if passwd1 != passwd2:
53 errors['password'] = [' Passwords do not match. ']
54 validate(errors, 'Email', email, validators.isValidEmail, False, request)
55 # apply changes
56 if not errors:
57 request.user.email = email
58 if passwd1:
59 request.user.set_password(passwd1)
60 request.user.save()
61 return HttpResponseRedirect('/devel/')
62 return render_template('devel/profile.html', request, {'errors':errors,'email':request.user.email})
64 @login_required
65 def guide(request):
66 return HttpResponse(file(DATA_DIR + '/pkgmaint_guide.txt').read(),
67 mimetype='text/plain')