summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDusty Phillips <buchuki@gmail.com>2008-06-27 20:10:28 -0400
committerDusty Phillips <buchuki@gmail.com>2008-06-27 20:10:28 -0400
commitfdaa35a9386ccb8adab23f46d9260f8ed407bf5c (patch)
treec515ad832889f513252706e073173bc63601a81b
parentacc68977135b880b28f2aa83b6938eae46467195 (diff)
refactor todo packages a bit
-rw-r--r--main/models.py9
-rw-r--r--templates/todolists/view.html2
-rw-r--r--todolists/views.py11
3 files changed, 13 insertions, 9 deletions
diff --git a/main/models.py b/main/models.py
index cab6a9cb..6688031d 100644
--- a/main/models.py
+++ b/main/models.py
@@ -290,6 +290,15 @@ class Todolist(models.Model):
objects = TodolistManager()
def __str__(self):
return self.name
+
+ @property
+ def packages(self):
+ return TodolistPkg.objects.filter(list=self.id).order_by('pkg')
+
+ @property
+ def package_names(self):
+ return '\n'.join([p.pkg.pkgname for p in self.packages])
+
class Meta:
db_table = 'todolists'
diff --git a/templates/todolists/view.html b/templates/todolists/view.html
index db9be6e8..02c228e4 100644
--- a/templates/todolists/view.html
+++ b/templates/todolists/view.html
@@ -44,7 +44,7 @@
</tr>
</thead>
<tbody>
- {% for pkg in pkgs %}
+ {% for pkg in list.packages %}
<tr class="{% cycle even,odd %}">
<td><a href="/packages/{{ pkg.pkg.id }}/">{{ pkg.pkg.pkgname }}</a></td>
<td>{{ pkg.pkg.arch.name }}</td>
diff --git a/todolists/views.py b/todolists/views.py
index d76c24b3..dc1a9aa7 100644
--- a/todolists/views.py
+++ b/todolists/views.py
@@ -41,11 +41,10 @@ def flag(request, listid, pkgid):
def view(request, listid):
list = get_object_or_404(Todolist, id=listid)
- pkgs = TodolistPkg.objects.filter(list=list.id).order_by('pkg')
return render_response(
request,
'todolists/view.html',
- {'list':list,'pkgs':pkgs})
+ {'list':list})
def list(request):
lists = Todolist.objects.order_by('-date_added')
@@ -57,18 +56,14 @@ def list(request):
@permission_required('todolists.add_todolist')
def add(request):
if request.POST:
- # create the list
form = TodoListForm(request.POST)
if form.is_valid():
- todo = Todolist(
+ todo = Todolist.objects.create(
creator = request.user,
name = form.clean_data['name'],
description = form.clean_data['description'])
- todo.save()
- # now link in packages
for pkg in form.clean_data['packages']:
- todopkg = TodolistPkg(list = todo, pkg = pkg)
- todopkg.save()
+ TodolistPkg.objects.create(list = todo, pkg = pkg)
return HttpResponseRedirect('/todo/')
else:
form = TodoListForm()