Skip to content

Commit

Permalink
Make safety layer tags red
Browse files Browse the repository at this point in the history
  • Loading branch information
SmittieC committed Oct 4, 2024
1 parent dded1ec commit 7276e50
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
15 changes: 12 additions & 3 deletions apps/annotations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,29 @@ def add_tag(self, tag: Tag, team: Team, added_by: CustomUser):
self.tags.add(tag, through_defaults={"team": team, "user": added_by})

def get_linked_tags(self):
return self.tags.all()
tags = []
for tag in self.tags.all():
bage_color = "badge-neutral"
if tag.is_system_tag:
bage_color = "badge-error" if tag.category == TagCategories.SAFETY_LAYER_RESPONSE else "badge-warning"
tags.append((tag, bage_color))
return tags

def user_tag_names(self):
return {tag["name"] for tag in self.tags_json if not tag["is_system_tag"]}

def system_tags_names(self):
return {tag["name"] for tag in self.tags_json if tag["is_system_tag"]}
return {(tag["name"], tag["category"]) for tag in self.tags_json if tag["is_system_tag"]}

def all_tag_names(self):
return [tag["name"] for tag in self.tags_json]

@cached_property
def tags_json(self):
return [{"name": tag.name, "id": tag.id, "is_system_tag": tag.is_system_tag} for tag in self.tags.all()]
return [
{"name": tag.name, "id": tag.id, "is_system_tag": tag.is_system_tag, "category": tag.category}
for tag in self.tags.all()
]


class UserComment(BaseTeamModel):
Expand Down
12 changes: 8 additions & 4 deletions templates/annotations/tag_ui.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div id="tag-ui-{{ object.id }}" class="text-gray-500">
{% if not edit_mode %}
<i class="fa-solid fa-tags"></i>
{% for tag in object.get_linked_tags %}
<div class="badge {% if tag.is_system_tag %}badge-warning{% else %}badge-neutral{% endif %}"
{% for tag, badge_color in object.get_linked_tags %}
<div class="badge {{ badge_color }}"
title="{% if tag.is_system_tag %}System Tag{% else %}User Tag{% endif %}: {{ tag.name }}"
>{{ tag.name }}</div>
{% endfor %}
Expand Down Expand Up @@ -35,8 +35,12 @@
<div class="flex place-items-center">
{% if object.system_tags_names %}
<span class="text-gray-500 text-sm">System tags: </span>
{% for tag in object.system_tags_names %}
<div class="badge badge-warning">{{ tag }}</div>
{% for tag, category in object.system_tags_names %}
{% if category == 'safety_layer_response' %}
<div class="badge badge-error">{{ tag }}</div>
{% else %}
<div class="badge badge-warning">{{ tag }}</div>
{% endif %}
{% endfor %}
{% endif %}
</div>
Expand Down

0 comments on commit 7276e50

Please sign in to comment.