diff options
Diffstat (limited to 'todolists/views.py')
-rw-r--r-- | todolists/views.py | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/todolists/views.py b/todolists/views.py index 6278c6bf..d6a25463 100644 --- a/todolists/views.py +++ b/todolists/views.py @@ -5,14 +5,14 @@ from django.core.mail import send_mail from django.shortcuts import get_object_or_404, redirect from django.contrib.auth.decorators import login_required, permission_required from django.db import transaction -from django.db.models import Count from django.views.decorators.cache import never_cache -from django.views.generic.create_update import delete_object +from django.views.generic import DeleteView from django.views.generic.simple import direct_to_template from django.template import Context, loader from django.utils import simplejson from main.models import Todolist, TodolistPkg, Package +from .utils import get_annotated_todolists class TodoListForm(forms.ModelForm): packages = forms.CharField(required=False, @@ -35,7 +35,7 @@ class TodoListForm(forms.ModelForm): @permission_required('main.change_todolistpkg') @never_cache def flag(request, listid, pkgid): - list = get_object_or_404(Todolist, id=listid) + todolist = get_object_or_404(Todolist, id=listid) pkg = get_object_or_404(TodolistPkg, id=pkgid) pkg.complete = not pkg.complete pkg.save() @@ -43,29 +43,18 @@ def flag(request, listid, pkgid): return HttpResponse( simplejson.dumps({'complete': pkg.complete}), mimetype='application/json') - return redirect(list) + return redirect(todolist) @login_required @never_cache def view(request, listid): - list = get_object_or_404(Todolist, id=listid) - return direct_to_template(request, 'todolists/view.html', {'list': list}) + todolist = get_object_or_404(Todolist, id=listid) + return direct_to_template(request, 'todolists/view.html', {'list': todolist}) @login_required @never_cache -def list(request): - lists = Todolist.objects.select_related('creator').annotate( - pkg_count=Count('todolistpkg')).order_by('-date_added') - incomplete = Todolist.objects.filter(todolistpkg__complete=False).annotate( - Count('todolistpkg')).values_list('id', 'todolistpkg__count') - - # tag each list with an incomplete package count - lookup = {} - for k, v in incomplete: - lookup[k] = v - for l in lists: - l.incomplete_count = lookup.get(l.id, 0) - +def todolist_list(request): + lists = get_annotated_todolists() return direct_to_template(request, 'todolists/list.html', {'lists': lists}) @permission_required('main.add_todolist') @@ -109,13 +98,11 @@ def edit(request, list_id): } return direct_to_template(request, 'general_form.html', page_dict) -@permission_required('main.delete_todolist') -@never_cache -def delete_todolist(request, object_id): - return delete_object(request, object_id=object_id, model=Todolist, - template_name="todolists/todolist_confirm_delete.html", - post_delete_redirect='/todo/') - +class DeleteTodolist(DeleteView): + model = Todolist + # model in main == assumes name 'main/todolist_confirm_delete.html' + template_name = 'todolists/todolist_confirm_delete.html' + success_url = '/todo/' @transaction.commit_on_success def create_todolist_packages(form, creator=None): @@ -163,13 +150,13 @@ def send_todolist_emails(todo_list, new_packages): maint_packages.setdefault(maint, []).append(todo_package) for maint, packages in maint_packages.iteritems(): - c = Context({ + ctx = Context({ 'todo_packages': sorted(packages), 'todolist': todo_list, }) - t = loader.get_template('todolists/email_notification.txt') + template = loader.get_template('todolists/email_notification.txt') send_mail('Packages added to todo list \'%s\'' % todo_list.name, - t.render(c), + template.render(ctx), 'Parabola <packages@list.parabolagnulinux.org>', [maint], fail_silently=True) |