Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#2170] Instructor badge display #2206

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions amy/templates/includes/instructor_role_badge.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if role.is_active %}
<span class="badge badge-success">Instructor role (active)</span>
{% else %}
<span class="badge badge-danger">Instructor role (inactive)</span>
{% endif %}
8 changes: 5 additions & 3 deletions amy/templates/workshops/all_persons.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
</tr>
{% for person in all_persons %}
<tr>
<td>{% for badge in person.important_badges %}
{% bootstrap_tag badge.name|cut:"-instructor"|upper %}
{% empty %}&mdash;{% endfor %}</td>
<td>
{% for badge in person.important_badges %}{% bootstrap_tag badge.name|upper %}{% endfor %}
{% for role in person.instructor_community_roles %}{% include "includes/instructor_role_badge.html" with role=role %}{% endfor %}
{% if not person.important_badges and not person.instructor_community_roles %}&mdash;{% endif %}
</td>
<td><a href="{% url 'person_details' person.id %}">{{ person.full_name }}</a></td>
<td>{% if person.email %}<a href="mailto:{{ person.email }}">{{ person.email }}</a>{% else %}—{% endif %}</td>
<td>
Expand Down
8 changes: 5 additions & 3 deletions amy/templates/workshops/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ <h3>Tasks</h3>
<tbody>
{% for t in tasks %}
<tr>
<td>{% for badge in t.person.important_badges %}
{% bootstrap_tag badge.name|cut:"-instructor"|upper %}
{% empty %}&mdash;{% endfor %}</td>
<td>
{% for badge in t.person.important_badges %}{% bootstrap_tag badge.name|upper %}{% endfor %}
{% for role in t.person.instructor_community_roles %}{% include "includes/instructor_role_badge.html" with role=role %}{% endfor %}
{% if not t.person.important_badges and not person.instructor_community_roles %}&mdash;{% endif %}
</td>
<td><a href="{{ t.person.get_absolute_url }}">{{ t.person.full_name }}</a>{% if t.person.email and t.person.may_contact %} &lt;{{ t.person.email|urlize }}&gt;{% endif %}</td>
<td>{{ t.url|default:"&mdash;"|urlize_newtab }}</td>
<td>{{ t.role.name }}</td>
Expand Down
5 changes: 2 additions & 3 deletions amy/templates/workshops/workshop_staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ <h3>Filter</h3>
<table class="table table-striped">
<tr>
<th><input type="checkbox" value="Select all" select-all-checkbox /></th>
<th class="badges-column">Instructor <i class="fas fa-question-circle" data-toggle="tooltip"
title="Has an active Instructor Community Role."></i></th>
<th class="badges-column">Instructor Community Role</th>
<th>Trainer</th>
<th>Person</th>
<th>Taught (inc. TTT)</th>
Expand All @@ -29,7 +28,7 @@ <h3>Filter</h3>
{% for p in persons %}
<tr>
<td><input type="checkbox" email="{{ p.email }}" respond-to-select-all-checkbox /></td>
<td>{% if p.is_instructor %}{% bootstrap_tag 'INSTRUCTOR' %}{% else %}&mdash;{% endif %}</td>
<td>{% for role in p.instructor_community_roles %}{% include "includes/instructor_role_badge.html" with role=role %}{% empty %}&mdash;{% endfor %}</td>
<td>{% if p.is_trainer %}{% bootstrap_tag 'TRAINER' %}{% else %}&mdash;{% endif %}</td>
<td><a href="{{ p.get_absolute_url }}">{{ p.full_name }}</a>{% if p.email and p.may_contact %} &lt;{{ p.email|urlize }}&gt;{% endif %}</td>
<td>{{ p.num_instructor|add:p.num_trainer }}</td>
Expand Down
5 changes: 4 additions & 1 deletion amy/workshops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,8 @@ class BadgeQuerySet(models.query.QuerySet):
SINGLE_INSTRUCTOR_BADGE,
)

TRAINER_BADGE = "trainer"

def instructor_badges(self):
"""Filter for instructor badges only."""

Expand All @@ -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)
Expand Down
37 changes: 22 additions & 15 deletions amy/workshops/templatetags/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 23 additions & 5 deletions amy/workshops/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
)

Expand Down Expand Up @@ -2225,20 +2236,20 @@ 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(
config__name="instructor"
)

# 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(
Expand All @@ -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")
)

Expand Down