summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--devel/views.py8
-rw-r--r--templates/devel/index.html21
-rw-r--r--todolists/urls.py2
-rw-r--r--todolists/utils.py19
-rw-r--r--todolists/views.py17
5 files changed, 43 insertions, 24 deletions
diff --git a/devel/views.py b/devel/views.py
index cb0ff05..b61e605 100644
--- a/devel/views.py
+++ b/devel/views.py
@@ -11,10 +11,11 @@ from django.template import loader, Context
from django.views.decorators.cache import never_cache
from django.views.generic.simple import direct_to_template
-from main.models import Package, Todolist, TodolistPkg
+from main.models import Package, TodolistPkg
from main.models import Arch, Repo
from main.models import UserProfile
from packages.models import PackageRelation
+from todolists.utils import get_annotated_todolists
from .utils import get_annotated_maintainers
import datetime
@@ -35,6 +36,9 @@ def index(request):
todopkgs = todopkgs.filter(pkg__pkgbase__in=inner_q).order_by(
'list__name', 'pkg__pkgname')
+ todolists = get_annotated_todolists()
+ todolists = [todolist for todolist in todolists if todolist.incomplete_count > 0]
+
maintainers = get_annotated_maintainers()
maintained = PackageRelation.objects.filter(
@@ -48,7 +52,7 @@ def index(request):
}
page_dict = {
- 'todos': Todolist.objects.incomplete().order_by('-date_added'),
+ 'todos': todolists,
'repos': Repo.objects.all(),
'arches': Arch.objects.all(),
'maintainers': maintainers,
diff --git a/templates/devel/index.html b/templates/devel/index.html
index af2e5d2..92332c7 100644
--- a/templates/devel/index.html
+++ b/templates/devel/index.html
@@ -72,19 +72,26 @@
<tr>
<th>Name</th>
<th>Creation Date</th>
+ <th>Creator</th>
<th>Description</th>
+ <th>Package Count</th>
+ <th>Incomplete Count</th>
+ </tr>
</tr>
</thead>
<tbody>
{% for todo in todos %}
- <tr class="{% cycle 'odd' 'even' %}">
- <td><a href="{{ todo.get_absolute_url }}"
- title="View todo list: {{ todo.name }}">{{ todo.name }}</a></td>
- <td>{{ todo.date_added|date }}</td>
- <td class="wrap">{{ todo.description|urlize }}</td>
- </tr>
+ <tr class="{% cycle 'odd' 'even' %}">
+ <td><a href="{{ todo.get_absolute_url }}"
+ title="View todo list: {{ todo.name }}">{{ todo.name }}</a></td>
+ <td>{{ todo.date_added|date }}</td>
+ <td>{{ todo.creator.get_full_name }}</td>
+ <td class="wrap">{{ todo.description|urlize }}</td>
+ <td>{{ todo.pkg_count }}</td>
+ <td>{{ todo.incomplete_count }}</td>
+ </tr>
{% empty %}
- <tr class="empty"><td colspan="3"><em>No package todo lists to display</em></td></tr>
+ <tr class="empty"><td colspan="3"><em>No package todo lists to display</em></td></tr>
{% endfor %}
</tbody>
</table>
diff --git a/todolists/urls.py b/todolists/urls.py
index 8814d65..2612a52 100644
--- a/todolists/urls.py
+++ b/todolists/urls.py
@@ -4,7 +4,7 @@ from django.contrib.auth.decorators import permission_required
from .views import DeleteTodolist
urlpatterns = patterns('todolists.views',
- (r'^$', 'list'),
+ (r'^$', 'todolist_list'),
(r'^(\d+)/$', 'view'),
(r'^add/$', 'add'),
(r'^edit/(?P<list_id>\d+)/$', 'edit'),
diff --git a/todolists/utils.py b/todolists/utils.py
new file mode 100644
index 0000000..894f3f1
--- /dev/null
+++ b/todolists/utils.py
@@ -0,0 +1,19 @@
+from django.db.models import Count
+
+from main.models import Todolist
+
+def get_annotated_todolists():
+ qs = Todolist.objects.all()
+ lists = qs.select_related('creator').annotate(
+ pkg_count=Count('todolistpkg')).order_by('-date_added')
+ incomplete = qs.filter(todolistpkg__complete=False).annotate(
+ Count('todolistpkg')).values_list('id', 'todolistpkg__count')
+
+ # tag each list with an incomplete package count
+ lookup = dict(incomplete)
+ for todolist in lists:
+ todolist.incomplete_count = lookup.get(todolist.id, 0)
+
+ return lists
+
+# vim: set ts=4 sw=4 et:
diff --git a/todolists/views.py b/todolists/views.py
index d3ed781..ffe4c32 100644
--- a/todolists/views.py
+++ b/todolists/views.py
@@ -5,7 +5,6 @@ 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 import DeleteView
from django.views.generic.simple import direct_to_template
@@ -13,6 +12,7 @@ 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,
@@ -53,19 +53,8 @@ def view(request, listid):
@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')