Skip to content

Commit

Permalink
feat: [ACI-935] add rules list to inline badge requirement admin (#154)
Browse files Browse the repository at this point in the history
* feat: [ACI-935] add rules list to inline badge requirement admin

* fix: [ACI-935] wrap li tags into ul to get valid html

---------

Co-authored-by: Andrii <[email protected]>
  • Loading branch information
andrii-hantkovskyi and Andrii authored Apr 19, 2024
1 parent e3f991f commit 2b82941
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion credentials/apps/badges/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from django.contrib import admin, messages
from django.contrib.sites.shortcuts import get_current_site
from django.core.management import call_command
from django.urls import resolve
from django.utils.html import format_html
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.urls import reverse

Expand Down Expand Up @@ -35,12 +35,28 @@ class BadgeRequirementInline(admin.TabularInline):
model = BadgeRequirement
show_change_link = True
extra = 0
fields = ("event_type", "rules", "description")
readonly_fields = ("rules",)

# FIXME: disable until "Release VI"
exclude = [
"group",
]

def rules(self, obj):
"""
Display all data rules for the requirement.
"""
return format_html(
"<ul>{}</ul>",
mark_safe(
"".join(
f"<li>{rule.data_path} {rule.OPERATORS[rule.operator]} {rule.value}</li>"
for rule in obj.rules.all()
)
)
)


class BadgePenaltyInline(admin.TabularInline):
model = BadgePenalty
Expand Down

0 comments on commit 2b82941

Please sign in to comment.