Skip to content

Commit

Permalink
fix: flat list of enterprise group uuids on policies
Browse files Browse the repository at this point in the history
also, broadly try/except the django admin API repr of serialized
subsidy access policy records.
  • Loading branch information
iloveagent57 committed Mar 20, 2024
1 parent 8450375 commit c9b9fb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class Meta:
read_only_fields = fields

def get_group_associations(self, obj):
return obj.groups.values_list("enterprise_group_uuid", flat=True)
return list(obj.groups.values_list("enterprise_group_uuid", flat=True))


class SubsidyAccessPolicyCRUDSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -275,7 +275,7 @@ def calling_view(self):
return self.context['view']

def get_group_associations(self, obj):
return obj.groups.values_list("enterprise_group_uuid", flat=True)
return list(obj.groups.values_list("enterprise_group_uuid", flat=True))

def create(self, validated_data):
policy_type = validated_data.get('policy_type')
Expand Down
23 changes: 13 additions & 10 deletions enterprise_access/apps/subsidy_access_policy/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,23 @@ def api_serialized_repr(self, obj):
https://daniel.feldroy.com/posts/pretty-formatting-json-django-admin
for this styling idea.
"""
data = SubsidyAccessPolicyResponseSerializer(obj).data
json_string = json.dumps(data, indent=4, sort_keys=True)
try:
data = SubsidyAccessPolicyResponseSerializer(obj).data
json_string = json.dumps(data, indent=4, sort_keys=True)

# Get the Pygments formatter
formatter = HtmlFormatter(style='default')
# Get the Pygments formatter
formatter = HtmlFormatter(style='default')

# Highlight the data
response = highlight(json_string, JsonLexer(), formatter)
# Highlight the data
response = highlight(json_string, JsonLexer(), formatter)

# Get the stylesheet
style = "<style>" + formatter.get_style_defs() + "</style><br>"
# Get the stylesheet
style = "<style>" + formatter.get_style_defs() + "</style><br>"

# Safe the output
return mark_safe(style + response)
# Safe the output
return mark_safe(style + response)
except Exception: # pylint: disable=broad-except
return ''

def _short_description(self, obj):
return Truncator(str(obj.description)).chars(255)
Expand Down

0 comments on commit c9b9fb9

Please sign in to comment.