Skip to content

Commit

Permalink
Move projects and issues unread count to views.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nsurbay committed Nov 13, 2017
1 parent 0d7f9fa commit 8d73cc6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
8 changes: 0 additions & 8 deletions tracker/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ def process_view(self, request, view, view_args, view_kwargs):
return
project = view_kwargs.get('project')
if not project:
# count unread issues by projects
request.read_state_projects = {}
for project in request.projects.all():
request.read_state_projects[project] = project.get_unread_issues_nb(request.user)
return
try:
project = all_projects.get(name=project)
Expand All @@ -56,8 +52,4 @@ def process_view(self, request, view, view_args, view_kwargs):
request.project = project
request.archived = project.archived
request.projects = all_projects.filter(archived=request.archived)
# count unread event by issues
request.read_state_issues = {}
for issue in project.issues.all():
request.read_state_issues[issue] = issue.get_unread_event_nb(request.user)

4 changes: 2 additions & 2 deletions tracker/templates/tracker/issue_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
&#160;–&#160;&#160;<span class="glyphicon glyphicon-road"></span> <a href="{% issue_url milestone=issue.milestone %}"><b>{{ issue.milestone }}</b></a>
{% endif %}
&#160;–&#160;&#160;<span><span class="badge"><span class="glyphicon glyphicon-comment"></span>&#160;{{ issue.comments.count }}</span></span>
{% if request.read_state_issues|get_item:issue > 0 %}
<span><span class="badge badge-unread"><span class="glyphicon glyphicon-bullhorn"></span>&#160;{{ request.read_state_issues|get_item:issue }}</span></span>
{% if read_state_issues|get_item:issue > 0 %}
<span><span class="badge badge-unread"><span class="glyphicon glyphicon-bullhorn"></span>&#160;{{ read_state_issues|get_item:issue }}</span></span>
{% endif %}
</li>
{% endfor %}
Expand Down
4 changes: 2 additions & 2 deletions tracker/templates/tracker/project_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ <h1>
<div class="list-group">
<a class="list-group-item" href="{% url 'list-issue' project.name %}">
<h4>{{ project }}
{% if request.read_state_projects|get_item:project > 0 %}
<span><span class="badge badge-unread"><span class="glyphicon glyphicon-bullhorn"></span>&#160;{{ request.read_state_projects|get_item:project }}</span></span>
{% if read_state_projects|get_item:project > 0 %}
<span><span class="badge badge-unread"><span class="glyphicon glyphicon-bullhorn"></span>&#160;{{ read_state_projects|get_item:project }}</span></span>
{% endif %}
</h4>
{% if project.description %}
Expand Down
10 changes: 10 additions & 0 deletions tracker/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ def project_list(request, archived=False):
messages.info(request, 'Start by creating a project.')
return redirect('add-project')


read_state_projects = {}
for project in request.projects.all():
read_state_projects[project] = project.get_unread_issues_nb(request.user)
c = {
'archived': archived,
'read_state_projects': read_state_projects,
}

return render(request, 'tracker/project_list.html', c)
Expand Down Expand Up @@ -271,6 +276,10 @@ def issue_list(request, project):
else:
paginator = None

read_state_issues = {}
for issue in project.issues.all():
read_state_issues[issue] = issue.get_unread_event_nb(request.user)

c = {
'project': project,
'issues': issues,
Expand All @@ -280,6 +289,7 @@ def issue_list(request, project):
'status_values': STATUS_VALUES,
'sort': issuemanager.sort,
'sort_values': SORT_VALUES,
'read_state_issues': read_state_issues,
}

return render(request, 'tracker/issue_list.html', c)
Expand Down

0 comments on commit 8d73cc6

Please sign in to comment.