Skip to content

Instantly share code, notes, and snippets.

@mathjazz
Last active September 16, 2016 07:00
Show Gist options
  • Save mathjazz/df146570736b6896876b3564e70df169 to your computer and use it in GitHub Desktop.
Save mathjazz/df146570736b6896876b3564e70df169 to your computer and use it in GitHub Desktop.
diff --git a/pontoon/base/templates/widgets/contributors.html b/pontoon/base/templates/widgets/contributors.html
index e01eac2..d5fe4a5 100644
--- a/pontoon/base/templates/widgets/contributors.html
+++ b/pontoon/base/templates/widgets/contributors.html
@@ -30,7 +30,7 @@
<img class="rounded" src="{{ contributor.gravatar_url(44) }}">
<p class="name">{{ contributor.name_or_email }}</p>
</a>
- <p class="rights">{{ contributor.rights }}</p>
+ <p class="rights">{{ contributor.role }}</p>
</td>
<td class="stats">
<div class="details">
diff --git a/pontoon/base/views.py b/pontoon/base/views.py
index 38d41cd..ac46808 100755
--- a/pontoon/base/views.py
+++ b/pontoon/base/views.py
@@ -14,7 +14,7 @@ from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.contrib import messages
from django.contrib.auth.decorators import login_required
-from django.contrib.auth.models import User
+from django.contrib.auth.models import User, Group
from django.core.exceptions import ValidationError, ImproperlyConfigured
from django.core.mail import EmailMessage
from django.core.paginator import Paginator, EmptyPage
@@ -325,7 +325,31 @@ class ContributorsMixin(object):
period = None
start_date = None
- context['contributors'] = User.translators.with_translation_counts(start_date, self.contributors_filter(**kwargs))
+ MANAGERS = {}
+ manager_groups = Group.objects.filter(name__endswith='managers').prefetch_related('user_set')
+ for group in manager_groups:
+ for user in group.user_set.all():
+ MANAGERS.setdefault(user, []).append(group.name.split(' ')[0])
+
+ TRANSLATORS = {}
+ translator_groups = Group.objects.filter(name__endswith='translators').prefetch_related('user_set')
+ for group in translator_groups:
+ for user in group.user_set.all():
+ TRANSLATORS.setdefault(user, []).append(group.name.split(' ')[0])
+
+ contributors = User.translators.with_translation_counts(start_date, self.contributors_filter(**kwargs))
+
+ for contributor in contributors:
+ if contributor.is_superuser:
+ contributor.role = 'Admin'
+ elif contributor in MANAGERS:
+ contributor.role = 'Manager for ' + ', '.join(MANAGERS[contributor])
+ elif contributor in TRANSLATORS:
+ contributor.role = 'Translator for ' + ', '.join(TRANSLATORS[contributor])
+ else:
+ contributor.role = 'Contributor'
+
+ context['contributors'] = contributors
context['period'] = period
return context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment