Skip to content

Commit

Permalink
fix: [AXM-1302] fix accredible redirecting on rule save
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo-kh committed Jan 6, 2025
1 parent aea8047 commit b4f8fa2
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,9 +34,6 @@
DataRule,
Fulfillment,
PenaltyDataRule,
AccredibleAPIConfig,
AccredibleBadge,
AccredibleGroup,
)
from credentials.apps.badges.toggles import is_badges_enabled

Expand Down Expand Up @@ -388,14 +388,24 @@ def template_link(self, instance):
"""
Interactive link to parent (badge template).
"""
url = reverse("admin:badges_credlybadgetemplate_change", args=[instance.template.pk])
if instance.template.origin == CredlyBadgeTemplate.ORIGIN:
reverse_name = "admin:badges_credlybadgetemplate_change"
elif instance.template.origin == AccredibleGroup.ORIGIN:
reverse_name = "admin:badges_accrediblegroup_change"

url = reverse(reverse_name, args=[instance.template.pk])
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]))
if obj.template.origin == CredlyBadgeTemplate.ORIGIN:
reverse_name = "admin:badges_credlybadgetemplate_change"
elif obj.template.origin == AccredibleGroup.ORIGIN:
reverse_name = "admin:badges_accrediblegroup_change"

return HttpResponseRedirect(reverse(reverse_name, args=[obj.template.pk]))
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 b4f8fa2

Please sign in to comment.