|
6 | 6 | from collections import OrderedDict, namedtuple
|
7 | 7 |
|
8 | 8 | from django.conf import settings
|
| 9 | +from django.db.models import Q |
9 | 10 |
|
10 | 11 | from .models import Revision, Ticket, TicketChange
|
11 | 12 |
|
@@ -34,44 +35,46 @@ def _inner(f):
|
34 | 35 | return _inner
|
35 | 36 |
|
36 | 37 |
|
37 |
| -def get_user_stats(username): |
| 38 | +def get_user_stats(user): |
38 | 39 | stats = OrderedDict()
|
39 | 40 | for func in sorted(_statfuncs, key=operator.attrgetter("title")):
|
40 |
| - stats[func.title] = func(username) |
| 41 | + stats[func.title] = func(user) |
41 | 42 | return stats
|
42 | 43 |
|
43 | 44 |
|
44 | 45 | @stat("Commits")
|
45 |
| -def commit_count(username): |
46 |
| - count = Revision.objects.filter(author=username).count() |
47 |
| - # This assumes that the username is their GitHub username, this is very |
48 |
| - # often the case. If this is incorrect, the GitHub will show no commits. |
49 |
| - link = f"https://github.com/django/django/commits/main/?author={username}" |
| 46 | +def commit_count(user): |
| 47 | + count = Revision.objects.filter( |
| 48 | + Q(author__istartswith=f"{user.username} <") |
| 49 | + | Q(author__istartswith=f"{user.get_full_name()} <") |
| 50 | + ).count() |
| 51 | + # This assumes that the username is their GitHub username. |
| 52 | + link = f"https://github.com/django/django/commits/main/?author={user.username}" |
50 | 53 | return StatData(count=count, link=link)
|
51 | 54 |
|
52 | 55 |
|
53 | 56 | @stat("Tickets fixed")
|
54 |
| -def tickets_fixed(username): |
55 |
| - query = f"owner={username}&resolution=fixed" |
| 57 | +def tickets_fixed(user): |
| 58 | + query = f"owner={user.username}&resolution=fixed" |
56 | 59 | count = Ticket.objects.from_querystring(query).count()
|
57 | 60 | link = get_trac_link(query)
|
58 | 61 | return StatData(count=count, link=link)
|
59 | 62 |
|
60 | 63 |
|
61 | 64 | @stat("Tickets opened")
|
62 |
| -def tickets_opened(username): |
63 |
| - query = f"reporter={username}" |
| 65 | +def tickets_opened(user): |
| 66 | + query = f"reporter={user.username}" |
64 | 67 | count = Ticket.objects.from_querystring(query).count()
|
65 | 68 | link = get_trac_link(query)
|
66 | 69 | return StatData(count=count, link=link)
|
67 | 70 |
|
68 | 71 |
|
69 | 72 | @stat("New tickets triaged")
|
70 |
| -def new_tickets_reviewed(username): |
| 73 | +def new_tickets_reviewed(user): |
71 | 74 | # We don't want to de-dup as for tickets_closed: multiple reviews of the
|
72 | 75 | # same ticket should "count" as a review.
|
73 | 76 | qs = TicketChange.objects.filter(
|
74 |
| - author=username, field="stage", oldvalue="Unreviewed" |
| 77 | + author=user.username, field="stage", oldvalue="Unreviewed" |
75 | 78 | )
|
76 | 79 | qs = qs.exclude(newvalue="Unreviewed")
|
77 | 80 | return StatData(count=qs.count(), link=None)
|
0 commit comments