Repository: carpentries/amy

Issue:
View Trainers badge with other instructor badges
When you view a list of Persons it shows the DC/LC/SWC badge they have. Trainer badge should also be noted here.


![image](https://user-images.githubusercontent.com/829690/65461454-ee9c0480-de21-11e9-8faf-5de597c5fde9.png)



Discussion:

Resolving patch:
diff --git a/amy/workshops/models.py b/amy/workshops/models.py
--- a/amy/workshops/models.py
+++ b/amy/workshops/models.py
@@ -1413,6 +1413,7 @@ class Badge(models.Model):
 
     # just for easier access outside `models.py`
     INSTRUCTOR_BADGES = BadgeQuerySet.INSTRUCTOR_BADGES
+    IMPORTANT_BADGES = INSTRUCTOR_BADGES + ('trainer', )
 
     name       = models.CharField(max_length=STR_MED, unique=True)
     title      = models.CharField(max_length=STR_MED)
diff --git a/amy/workshops/views.py b/amy/workshops/views.py
--- a/amy/workshops/views.py
+++ b/amy/workshops/views.py
@@ -203,9 +203,9 @@ class AllPersons(OnlyForAdminsMixin, AMYListView):
     queryset = Person.objects.prefetch_related(
         Prefetch(
             'badges',
-            to_attr='instructor_badges',
-            queryset=Badge.objects.instructor_badges()
-        )
+            to_attr='important_badges',
+            queryset=Badge.objects.filter(name__in=Badge.IMPORTANT_BADGES),
+        ),
     )
     title = 'All Persons'
 
@@ -836,16 +836,17 @@ def event_details(request, slug):
     except Event.DoesNotExist:
         raise Http404('Event matching query does not exist.')
 
-    person_instructor_badges = Prefetch(
+    person_important_badges = Prefetch(
         'person__badges',
-        to_attr='instructor_badges',
-        queryset=Badge.objects.instructor_badges()
+        to_attr='important_badges',
+        queryset=Badge.objects.filter(name__in=Badge.IMPORTANT_BADGES)
     )
+
     tasks = (
         Task.objects
             .filter(event__id=event.id)
             .select_related('event', 'person', 'role')
-            .prefetch_related(person_instructor_badges)
+            .prefetch_related(person_important_badges)
             .order_by('role__name')
     )
 
@@ -1409,11 +1410,11 @@ def _workshop_staff_query(lat=None, lng=None):
     TTT = Tag.objects.get(name='TTT')
     stalled = Tag.objects.get(name='stalled')
     learner = Role.objects.get(name='learner')
-    instructor_badges = Badge.objects.instructor_badges()
+    important_badges = Badge.objects.filter(name__in=Badge.IMPORTANT_BADGES)
 
     trainee_tasks = Task.objects.filter(event__tags=TTT, role=learner) \
                                 .exclude(event__tags=stalled) \
-                                .exclude(person__badges__in=instructor_badges)
+                                .exclude(person__badges__in=important_badges)
 
     # we need to count number of specific roles users had
     # and if they are SWC/DC/LC instructors
@@ -1446,8 +1447,8 @@ def _workshop_staff_query(lat=None, lng=None):
             'lessons',
             Prefetch(
                 'badges',
-                to_attr='instructor_badges',
-                queryset=Badge.objects.instructor_badges()
+                to_attr='important_badges',
+                queryset=Badge.objects.filter(name__in=Badge.IMPORTANT_BADGES)
             ),
         )
         .order_by('family', 'personal')
@@ -1523,7 +1524,7 @@ def workshop_staff_csv(request):
     people = f.qs
 
     # first row of the CSV output
-    header_row = ('Name', 'Email', 'Instructor badges', 'Has Trainer badge',
+    header_row = ('Name', 'Email', 'Some badges', 'Has Trainer badge',
                   'Taught times', 'Is trainee', 'Airport', 'Country',
                   'Lessons', 'Affiliation')
 
@@ -1539,7 +1540,7 @@ def workshop_staff_csv(request):
             person.full_name,
             person.email,
             " ".join([
-                badge.name for badge in person.instructor_badges
+                badge.name for badge in person.important_badges
             ]),
             "yes" if person.is_trainer else "no",
             person.num_taught,


Test patch:
diff --git a/amy/workshops/tests/test_workshop_staff_searching.py b/amy/workshops/tests/test_workshop_staff_searching.py
--- a/amy/workshops/tests/test_workshop_staff_searching.py
+++ b/amy/workshops/tests/test_workshop_staff_searching.py
@@ -368,7 +368,7 @@ def test_header_row(self):
         rv = self.client.get(self.url)
         first_row = rv.content.decode('utf-8').splitlines()[0]
         first_row_expected = (
-            "Name,Email,Instructor badges,Has Trainer badge,Taught times,"
+            "Name,Email,Some badges,Has Trainer badge,Taught times,"
             "Is trainee,Airport,Country,Lessons,Affiliation"
         )
 
@@ -382,9 +382,9 @@ def test_results(self):
         for row, expected in zip(reader, results):
             self.assertEqual(row['Name'], expected.full_name)
             self.assertEqual(row['Email'] or None, expected.email)
-            self.assertEqual(row['Instructor badges'],
+            self.assertEqual(row['Some badges'],
                              " ".join(map(lambda x: x.name,
-                                          expected.instructor_badges)))
+                                          expected.important_badges)))
             self.assertEqual(row['Has Trainer badge'],
                              'yes' if expected.is_trainer else 'no')
             self.assertEqual(row['Taught times'], str(expected.num_taught))