diff mbox series

[v4,3/9] templatetags: add utils template filters and tags

Message ID 20210820045030.3364156-4-raxel@google.com
State Accepted
Headers show
Series patch-detail: add unaddressed/addressed status to patch comments | expand

Commit Message

Raxel Gutierrez Aug. 20, 2021, 4:50 a.m. UTC
Add utils.py file to create template filters and tags that can be used
by most if not all objects in Patchwork. In particular, add a template
filter to get the plural verbose name of a model and add a template tag
that returns whether an object is editable by the current user. These
utilities will be used in an upcoming patch that adds the `addressed`
status label to patch and cover comments.

Signed-off-by: Raxel Gutierrez <raxel@google.com>
---
 patchwork/templatetags/utils.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
 create mode 100644 patchwork/templatetags/utils.py

Comments

Stephen Finucane Aug. 20, 2021, 10:17 p.m. UTC | #1
On Fri, 2021-08-20 at 04:50 +0000, Raxel Gutierrez wrote:
> Add utils.py file to create template filters and tags that can be used
> by most if not all objects in Patchwork. In particular, add a template
> filter to get the plural verbose name of a model and add a template tag
> that returns whether an object is editable by the current user. These
> utilities will be used in an upcoming patch that adds the `addressed`
> status label to patch and cover comments.
> 
> Signed-off-by: Raxel Gutierrez <raxel@google.com>

Need to see the caller but otherwise LGTM.

Reviewed-by: Stephen Finucane <stephen@that.guru>
diff mbox series

Patch

diff --git a/patchwork/templatetags/utils.py b/patchwork/templatetags/utils.py
new file mode 100644
index 00000000..78c0aac8
--- /dev/null
+++ b/patchwork/templatetags/utils.py
@@ -0,0 +1,18 @@ 
+# Patchwork - automated patch tracking system
+# Copyright (C) 2021 Google LLC
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+from django import template
+
+register = template.Library()
+
+
+@register.filter
+def verbose_name_plural(obj):
+    return obj._meta.verbose_name_plural
+
+
+@register.simple_tag
+def is_editable(obj, user):
+    return obj.is_editable(user)