-
Notifications
You must be signed in to change notification settings - Fork 27
/
reports.py
29 lines (23 loc) · 1.1 KB
/
reports.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from pydash import get
from core.reports.models import AbstractReport
from core.users.models import UserProfile
class UserReport(AbstractReport):
queryset = UserProfile.objects.filter()
name = 'Users'
verbose_fields = ['username', 'email', 'name', 'date_joined', 'status']
VERBOSE_HEADERS = ["Username", "Email", "Name", "Joined At", "Status"]
@classmethod
def get_authoring_report(cls, usernames):
users = UserProfile.objects.filter(username__in=usernames)
result = {}
for user in users:
user_result = {}
for app, model in [
('concepts', 'concept'), ('mappings', 'mapping'), ('sources', 'source'),
('collections', 'collection'), ('users', 'userprofile'), ('orgs', 'organization')
]:
created = get(user, f"{app}_{model}_related_created_by").count()
updated = get(user, f"{app}_{model}_related_updated_by").count()
user_result[app] = {'created': created, 'updated': updated}
result[user.username] = user_result
return result