Skip to content

Commit

Permalink
fixup! views: add series-list view
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-accarini committed Feb 18, 2025
1 parent 330d2b0 commit feb1b68
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
19 changes: 19 additions & 0 deletions patchwork/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,25 @@ def received_total(self):
def received_all(self):
return self.total <= self.received_total

@property
def check_count(self):
"""Generate a list of unique checks for all patchs in the series.
Compile a list of checks associated with this series patches for each
type of check. Only "unique" checks are considered, identified by their
'context' field. This means, given n checks with the same 'context', the
newest check is the only one counted regardless of its value. The end
result will be a association of types to number of unique checks for
said type.
"""
counts = {key: 0 for key, _ in Check.STATE_CHOICES}

for p in self.patches.all():
for check in p.checks:
counts[check.state] += 1

return counts

def add_cover_letter(self, cover):
"""Add a cover letter to the series.
Expand Down
16 changes: 8 additions & 8 deletions patchwork/templates/patchwork/series-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
{% load person %}
{% load listurl %}
{% load patch %}
{% load series %}
{% load project %}
{% load static %}

Expand All @@ -37,7 +38,11 @@
</th>

<th>
<span class="series-list-header">Cover Letter</span>
{% project_tags %}
</th>

<th>
<span class="series-list-header" title="Success / Warning / Fail">S/W/F</span>
</th>

<th>
Expand Down Expand Up @@ -83,13 +88,8 @@
{{ series.version|default:"-"}}
</td>

<td>
{% if series.cover_letter.content %}
<b>&check;</b>
{% else %}
-
{% endif %}
</td>
<td id="series-tags:{{series.id}}" class="text-nowrap">{{ series|series_tags }}</td>
<td id="series-checks:{{series.id}}" class="text-nowrap">{{ series|series_checks }}</td>
<td>{{ series.received_total}}</td>
<td class="text-nowrap">{{ series.date|date:"Y-m-d" }}</td>
<td>{{ series.submitter|personify:project }}</td>
Expand Down
61 changes: 61 additions & 0 deletions patchwork/templatetags/series.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Patchwork - automated patch tracking system
# Copyright (C) 2008 Jeremy Kerr <[email protected]>
# Copyright (C) 2015 Intel Corporation
#
# SPDX-License-Identifier: GPL-2.0-or-later

from django import template
from django.utils.safestring import mark_safe

from patchwork.models import Check


register = template.Library()


@register.filter(name='series_tags')
def series_tags(series):
counts = []
titles = []

for tag in [t for t in series.project.tags if t.show_column]:
count = 0
for patch in series.patches.with_tag_counts(series.project).all():
count += getattr(patch, tag.attr_name)

titles.append('%d %s' % (count, tag.name))
if count == 0:
counts.append('-')
else:
counts.append(str(count))

return mark_safe(
'<span title="%s">%s</span>' % (' / '.join(titles), ' '.join(counts))
)


@register.filter(name='series_checks')
def series_checks(series):
required = [Check.STATE_SUCCESS, Check.STATE_WARNING, Check.STATE_FAIL]
titles = ['Success', 'Warning', 'Fail']
counts = series.check_count

check_elements = []
for state in required[::-1]:
if counts[state]:
color = dict(Check.STATE_CHOICES).get(state)
count = str(counts[state])
else:
color = ''
count = '-'

check_elements.append(
f'<span class="patchlistchecks {color}">{count}</span>'
)

check_elements.reverse()

return mark_safe(
'<span title="%s">%s</span>'
% (' / '.join(titles), ''.join(check_elements))
)

0 comments on commit feb1b68

Please sign in to comment.