Skip to content

Commit

Permalink
fix: [AXM-1302] fix accredible redirecting on rule save (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo-kh authored Jan 7, 2025
1 parent aea8047 commit cfdfc7d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions credentials/apps/badges/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
PenaltyDataRuleFormSet,
)
from credentials.apps.badges.models import (
AccredibleAPIConfig,
AccredibleBadge,
AccredibleGroup,
BadgePenalty,
BadgeProgress,
BadgeRequirement,
Expand All @@ -31,13 +34,15 @@
DataRule,
Fulfillment,
PenaltyDataRule,
AccredibleAPIConfig,
AccredibleBadge,
AccredibleGroup,
)
from credentials.apps.badges.toggles import is_badges_enabled


ADMIN_CHANGE_VIEW_REVERSE_NAMES = {
CredlyBadgeTemplate.ORIGIN: "admin:badges_credlybadgetemplate_change",
AccredibleGroup.ORIGIN: "admin:badges_accrediblegroup_change",
}

class BadgeRequirementInline(admin.TabularInline):
"""
Badge template requirement inline setup.
Expand Down Expand Up @@ -388,14 +393,19 @@ def template_link(self, instance):
"""
Interactive link to parent (badge template).
"""
url = reverse("admin:badges_credlybadgetemplate_change", args=[instance.template.pk])
reverse_name = ADMIN_CHANGE_VIEW_REVERSE_NAMES.get(instance.template.origin, "admin:index")
reverse_args = [] if reverse_name == "admin:index" else [instance.template.pk]

url = reverse(reverse_name, args=reverse_args)
return format_html('<a href="{}">{}</a>', url, instance.template)

template_link.short_description = _("badge template")

def response_change(self, request, obj):
if "_save" in request.POST:
return HttpResponseRedirect(reverse("admin:badges_credlybadgetemplate_change", args=[obj.template.pk]))
reverse_name = ADMIN_CHANGE_VIEW_REVERSE_NAMES.get(obj.template.origin, "admin:index")
reverse_args = [] if reverse_name == "admin:index" else [obj.template.pk]
return HttpResponseRedirect(reverse(reverse_name, args=reverse_args))
return super().response_change(request, obj)


Expand Down Expand Up @@ -713,6 +723,7 @@ def image(self, obj):
return format_html('<img src="{}" width="50" height="auto" />', obj.icon)
return None


# register admin configurations with respect to the feature flag
if is_badges_enabled():
admin.site.register(CredlyOrganization, CredlyOrganizationAdmin)
Expand Down

0 comments on commit cfdfc7d

Please sign in to comment.