Browse Source

Add comment count to task list

devel
Dmitry Novikov 8 years ago
parent
commit
439e8676fd
  1. 4
      taskapp/locale/ru/LC_MESSAGES/django.po
  2. 3
      taskapp/templates/taskapp/tasklist.html
  3. 3
      taskapp/templates/taskapp/tasklist_all.html
  4. 5
      taskapp/views.py

4
taskapp/locale/ru/LC_MESSAGES/django.po

@ -456,3 +456,7 @@ msgstr "Исполнители"
msgid "Author does not specified" msgid "Author does not specified"
msgstr "Автор не указан" msgstr "Автор не указан"
msgid "Name and comment count"
msgstr "Имя и количество комментов"

3
taskapp/templates/taskapp/tasklist.html

@ -7,7 +7,7 @@
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">
<thead> <thead>
<tr> <tr>
<th class="col-sm-3">{% trans 'Name' %}</th>
<th class="col-sm-3">{% trans 'Name and comment count' %}</th>
<th class="col-sm-1">{% trans 'Address' %}</th> <th class="col-sm-1">{% trans 'Address' %}</th>
<th class="col-sm-1">{% trans 'The nature of the damage' %}</th> <th class="col-sm-1">{% trans 'The nature of the damage' %}</th>
<th class="col-sm-4">{% trans 'Description' %}</th> <th class="col-sm-4">{% trans 'Description' %}</th>
@ -40,6 +40,7 @@
<a href="{% url 'abonapp:abon_home' task.abon.group.pk task.abon.pk %}" title="{{ task.abon.description|default:'' }}" data-toggle="tooltip"> <a href="{% url 'abonapp:abon_home' task.abon.group.pk task.abon.pk %}" title="{{ task.abon.description|default:'' }}" data-toggle="tooltip">
{{ task.abon.get_full_name }} {{ task.abon.get_full_name }}
</a> </a>
{% if task.comment_count > 0 %}({{ task.comment_count }}){% endif %}
</td> </td>
<td> <td>
{{ task.abon.group.title }}, {{ task.abon.street|default:'' }} {{ task.abon.house|default:'' }} {{ task.abon.group.title }}, {{ task.abon.street|default:'' }} {{ task.abon.house|default:'' }}

3
taskapp/templates/taskapp/tasklist_all.html

@ -19,7 +19,7 @@
<table class="table table-striped table-bordered"> <table class="table table-striped table-bordered">
<thead> <thead>
<tr> <tr>
<th class="col-sm-2">{% trans 'Name' %}</th>
<th class="col-sm-2">{% trans 'Name and comment count' %}</th>
<th class="col-sm-2">{% trans 'Address' %}</th> <th class="col-sm-2">{% trans 'Address' %}</th>
<th class="col-sm-1">{% trans 'The nature of the damage' %}</th> <th class="col-sm-1">{% trans 'The nature of the damage' %}</th>
<th class="col-sm-3">{% trans 'Description' %}</th> <th class="col-sm-3">{% trans 'Description' %}</th>
@ -53,6 +53,7 @@
<a href="{% url 'abonapp:abon_home' task.abon.group.pk task.abon.pk %}"> <a href="{% url 'abonapp:abon_home' task.abon.group.pk task.abon.pk %}">
{{ task.abon.get_full_name }} {{ task.abon.get_full_name }}
</a> </a>
{% if task.comment_count > 0 %}({{ task.comment_count }}){% endif %}
</td> </td>
<td>{{ task.abon.group.title }}, {{ task.abon.street|default:_('Not assigned') }} {{ task.abon.house|default:_('Not assigned') }}</td> <td>{{ task.abon.group.title }}, {{ task.abon.street|default:_('Not assigned') }} {{ task.abon.house|default:_('Not assigned') }}</td>

5
taskapp/views.py

@ -3,6 +3,7 @@ from json import dumps
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.http import HttpResponse from django.http import HttpResponse
from django.db.models import Count
from django.shortcuts import redirect, get_object_or_404, resolve_url from django.shortcuts import redirect, get_object_or_404, resolve_url
from django.contrib import messages from django.contrib import messages
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
@ -37,6 +38,7 @@ class NewTasksView(BaseTaskListView):
def get_queryset(self): def get_queryset(self):
return Task.objects.filter(recipients=self.request.user, state='S') \ return Task.objects.filter(recipients=self.request.user, state='S') \
.annotate(comment_count=Count('extracomment')) \
.select_related('abon', 'abon__street', 'abon__group', 'author') .select_related('abon', 'abon__street', 'abon__group', 'author')
@ -85,7 +87,8 @@ class AllTasksListView(BaseTaskListView):
context_object_name = 'tasks' context_object_name = 'tasks'
def get_queryset(self): def get_queryset(self):
return Task.objects.select_related('abon', 'abon__street', 'abon__group', 'author')
return Task.objects.annotate(comment_count=Count('extracomment')) \
.select_related('abon', 'abon__street', 'abon__group', 'author')
@login_required @login_required

Loading…
Cancel
Save