|
| 1 | +# Patchwork - automated patch tracking system |
| 2 | +# Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org> |
| 3 | +# Copyright (C) 2015 Intel Corporation |
| 4 | +# |
| 5 | +# SPDX-License-Identifier: GPL-2.0-or-later |
| 6 | + |
| 7 | +from django import template |
| 8 | +from django.utils.safestring import mark_safe |
| 9 | + |
| 10 | +from patchwork.models import Check |
| 11 | + |
| 12 | + |
| 13 | +register = template.Library() |
| 14 | + |
| 15 | + |
| 16 | +@register.filter(name='series_tags') |
| 17 | +def series_tags(series): |
| 18 | + counts = [] |
| 19 | + titles = [] |
| 20 | + |
| 21 | + for tag in [t for t in series.project.tags if t.show_column]: |
| 22 | + count = 0 |
| 23 | + for patch in series.patches.with_tag_counts(series.project).all(): |
| 24 | + count += getattr(patch, tag.attr_name) |
| 25 | + |
| 26 | + titles.append('%d %s' % (count, tag.name)) |
| 27 | + if count == 0: |
| 28 | + counts.append('-') |
| 29 | + else: |
| 30 | + counts.append(str(count)) |
| 31 | + |
| 32 | + return mark_safe( |
| 33 | + '<span title="%s">%s</span>' % (' / '.join(titles), ' '.join(counts)) |
| 34 | + ) |
| 35 | + |
| 36 | + |
| 37 | +@register.filter(name='series_checks') |
| 38 | +def series_checks(series): |
| 39 | + required = [Check.STATE_SUCCESS, Check.STATE_WARNING, Check.STATE_FAIL] |
| 40 | + titles = ['Success', 'Warning', 'Fail'] |
| 41 | + counts = series.check_count |
| 42 | + |
| 43 | + check_elements = [] |
| 44 | + for state in required[::-1]: |
| 45 | + if counts[state]: |
| 46 | + color = dict(Check.STATE_CHOICES).get(state) |
| 47 | + count = str(counts[state]) |
| 48 | + else: |
| 49 | + color = '' |
| 50 | + count = '-' |
| 51 | + |
| 52 | + check_elements.append( |
| 53 | + f'<span class="patchlistchecks {color}">{count}</span>' |
| 54 | + ) |
| 55 | + |
| 56 | + check_elements.reverse() |
| 57 | + |
| 58 | + return mark_safe( |
| 59 | + '<span title="%s">%s</span>' |
| 60 | + % (' / '.join(titles), ''.join(check_elements)) |
| 61 | + ) |
| 62 | + |
| 63 | + |
| 64 | +@register.filter(name='series_interest') |
| 65 | +def series_interest(series): |
| 66 | + reviews = series.interest_count |
| 67 | + review_title = ( |
| 68 | + f'has {reviews} interested reviewers' |
| 69 | + if reviews > 0 |
| 70 | + else 'no interested reviewers' |
| 71 | + ) |
| 72 | + review_class = 'exists' if reviews > 0 else '' |
| 73 | + return mark_safe( |
| 74 | + '<span class="patchinterest %s" title="%s">%s</span>' |
| 75 | + % (review_class, review_title, reviews if reviews > 0 else '-') |
| 76 | + ) |
0 commit comments