Repository: carpentries/amy

Issue:
update views to only show "Instructor" award instead of individual lesson program Instructor awards
There are several views that display the different individual lesson program Instructor awards that someone might have, for example:

![Screenshot from 2022-04-26 10-39-53](https://user-images.githubusercontent.com/5502922/165325956-47589b4b-675e-4f7b-96e5-d022d626fa0a.png)

update these views to only display the unified "Instructor" award instead.



Discussion:
We should have an  indicator for the badge and also have an indicator for an active community role.
@maneesha this is how indicator for instructor badge as well as for an active instructor community role looks like:
![obraz](https://user-images.githubusercontent.com/72821/181371531-df682438-0eb1-4ccd-b804-601a6f677bd6.png)

Do you accept this look?

Resolving patch:
diff --git a/amy/workshops/models.py b/amy/workshops/models.py
--- a/amy/workshops/models.py
+++ b/amy/workshops/models.py
@@ -1821,6 +1821,8 @@ class BadgeQuerySet(models.query.QuerySet):
         SINGLE_INSTRUCTOR_BADGE,
     )
 
+    TRAINER_BADGE = "trainer"
+
     def instructor_badges(self):
         """Filter for instructor badges only."""
 
@@ -1833,7 +1835,8 @@ class Badge(models.Model):
     # just for easier access outside `models.py`
     SINGLE_INSTRUCTOR_BADGE = BadgeQuerySet.SINGLE_INSTRUCTOR_BADGE
     INSTRUCTOR_BADGES = BadgeQuerySet.INSTRUCTOR_BADGES
-    IMPORTANT_BADGES = INSTRUCTOR_BADGES + ("trainer",)
+    TRAINER_BADGE = BadgeQuerySet.TRAINER_BADGE
+    IMPORTANT_BADGES = (SINGLE_INSTRUCTOR_BADGE, TRAINER_BADGE)
 
     name = models.CharField(max_length=STR_MED, unique=True)
     title = models.CharField(max_length=STR_MED)
diff --git a/amy/workshops/templatetags/tags.py b/amy/workshops/templatetags/tags.py
--- a/amy/workshops/templatetags/tags.py
+++ b/amy/workshops/templatetags/tags.py
@@ -10,21 +10,28 @@
 def bootstrap_tag_class(name):
     name_low = name.lower()
 
-    class_ = "badge-secondary"
-    if name_low.startswith("swc"):
-        class_ = "badge-primary"
-    elif name_low.startswith("dc"):
-        class_ = "badge-success"
-    elif name_low.startswith("online"):
-        class_ = "badge-info"
-    elif name_low.startswith("lc"):
-        class_ = "badge-warning"
-    elif name_low.startswith("ttt"):
-        class_ = "badge-danger"
-    elif name_low.startswith("itt"):
-        class_ = "badge-danger"
-
-    return mark_safe(class_)
+    mapping = {
+        "swc": "badge-primary",
+        "dc": "badge-success",
+        "online": "badge-info",
+        "lc": "badge-warning",
+        "ttt": "badge-danger",
+        "itt": "badge-danger",
+        "instructor": "badge-primary",
+        "trainer": "badge-dark",
+    }
+    default = "badge-secondary"
+
+    return mark_safe(
+        next(
+            (
+                css_class
+                for prefix, css_class in mapping.items()
+                if name_low.startswith(prefix)
+            ),
+            default,
+        )
+    )
 
 
 @register.simple_tag
diff --git a/amy/workshops/views.py b/amy/workshops/views.py
--- a/amy/workshops/views.py
+++ b/amy/workshops/views.py
@@ -216,6 +216,11 @@ class AllPersons(OnlyForAdminsMixin, AMYListView):
             to_attr="important_badges",
             queryset=Badge.objects.filter(name__in=Badge.IMPORTANT_BADGES),
         ),
+        Prefetch(
+            "communityrole_set",
+            to_attr="instructor_community_roles",
+            queryset=CommunityRole.objects.filter(config__name="instructor"),
+        ),
     )
     title = "All Persons"
 
@@ -995,10 +1000,16 @@ def event_details(request, slug):
         queryset=Badge.objects.filter(name__in=Badge.IMPORTANT_BADGES),
     )
 
+    person_instructor_community_roles = Prefetch(
+        "person__communityrole_set",
+        to_attr="instructor_community_roles",
+        queryset=CommunityRole.objects.filter(config__name="instructor"),
+    )
+
     tasks = (
         Task.objects.filter(event__id=event.id)
         .select_related("event", "person", "role")
-        .prefetch_related(person_important_badges)
+        .prefetch_related(person_important_badges, person_instructor_community_roles)
         .order_by("role__name")
     )
 
@@ -2225,12 +2236,12 @@ def _workshop_staff_query(lat=None, lng=None) -> QuerySet[Person]:
     TTT = Tag.objects.get(name="TTT")
     stalled = Tag.objects.get(name="stalled")
     learner = Role.objects.get(name="learner")
-    important_badges = Badge.objects.filter(name__in=Badge.IMPORTANT_BADGES)
+    instructor_badges = Badge.objects.filter(name__in=Badge.INSTRUCTOR_BADGES)
 
     trainee_tasks = (
         Task.objects.filter(event__tags=TTT, role=learner)
         .exclude(event__tags=stalled)
-        .exclude(person__badges__in=important_badges)
+        .exclude(person__badges__in=instructor_badges)
     )
 
     active_instructor_community_roles = CommunityRole.objects.active().filter(
@@ -2238,7 +2249,7 @@ def _workshop_staff_query(lat=None, lng=None) -> QuerySet[Person]:
     )
 
     # we need to count number of specific roles users had
-    # and if they are SWC/DC/LC instructors
+    # and if they are instructors
     people = (
         Person.objects.annotate_with_role_count()
         .annotate(
@@ -2251,7 +2262,14 @@ def _workshop_staff_query(lat=None, lng=None) -> QuerySet[Person]:
         )
         .filter(airport__isnull=False)
         .select_related("airport")
-        .prefetch_related("lessons")
+        .prefetch_related(
+            "lessons",
+            Prefetch(
+                "communityrole_set",
+                to_attr="instructor_community_roles",
+                queryset=CommunityRole.objects.filter(config__name="instructor"),
+            ),
+        )
         .order_by("family", "personal")
     )
 


Test patch: