diff options
author | Dan McGee <dan@archlinux.org> | 2010-10-04 16:35:31 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-10-04 16:35:31 -0500 |
commit | 0e58a2e49f59fe41a27afa7bf8f9b3c77405c6d1 (patch) | |
tree | 9943d4c2984b2e18586cb8fd530bbe733ec81b72 | |
parent | 5e509529f00bd50ddfc6638d92c601209664d5d8 (diff) |
Todo list minor fixes and comments for later
When we show the edit todo list page, use a sorted list retrieved straight
from the database instead of a unordered set() we create at the application
level. Also add some comments for potential later improvements on
transaction boundaries and async emailing.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | main/models.py | 3 | ||||
-rw-r--r-- | todolists/views.py | 14 |
2 files changed, 10 insertions, 7 deletions
diff --git a/main/models.py b/main/models.py index c3cb5cf0..79d99e8c 100644 --- a/main/models.py +++ b/main/models.py @@ -307,7 +307,8 @@ class Todolist(models.Model): @property def package_names(self): - return '\n'.join(set([p.pkg.pkgname for p in self.packages])) + # depends on packages property returning a queryset + return self.packages.values_list('pkg__pkgname', flat=True).distinct() class Meta: db_table = 'todolists' diff --git a/todolists/views.py b/todolists/views.py index 25186243..519fae9d 100644 --- a/todolists/views.py +++ b/todolists/views.py @@ -68,6 +68,7 @@ def list(request): return direct_to_template(request, 'todolists/list.html', {'lists': lists}) +# TODO: this calls for transaction management and async emailing @permission_required('main.add_todolist') @never_cache def add(request): @@ -80,7 +81,7 @@ def add(request): description = form.cleaned_data['description']) for pkg in form.cleaned_data['packages']: - tpkg = TodolistPkg.objects.create(list = todo, pkg = pkg) + tpkg = TodolistPkg.objects.create(list=todo, pkg=pkg) send_todolist_email(tpkg) return redirect('/todo/') @@ -91,9 +92,10 @@ def add(request): 'title': 'Add Todo List', 'form': form, 'submit_text': 'Create List' - } + } return direct_to_template(request, 'general_form.html', page_dict) +# TODO: this calls for transaction management and async emailing @permission_required('main.change_todolist') @never_cache def edit(request, list_id): @@ -116,7 +118,7 @@ def edit(request, list_id): for pkg in form.cleaned_data['packages']: if pkg not in packages: tpkg = TodolistPkg.objects.create( - list = todo_list, pkg = pkg) + list=todo_list, pkg=pkg) send_todolist_email(tpkg) return redirect(todo_list) @@ -124,13 +126,13 @@ def edit(request, list_id): form = TodoListForm(initial={ 'name': todo_list.name, 'description': todo_list.description, - 'packages': todo_list.package_names, - }) + 'packages': '\n'.join(todo_list.package_names), + }) page_dict = { 'title': 'Edit Todo List: %s' % todo_list.name, 'form': form, 'submit_text': 'Save List' - } + } return direct_to_template(request, 'general_form.html', page_dict) @permission_required('main.delete_todolist') |