Skip to content

Commit a35750d

Browse files
committed
reformat metric template
1 parent 67dbb1b commit a35750d

File tree

4 files changed

+114
-15
lines changed

4 files changed

+114
-15
lines changed

api/skills_matcher_db/core/views.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.db.models.functions import TruncMonth
55
from django.db.models import Count
66

7-
from skills_matcher_db.users.models import User
7+
from skills_matcher_db.users.models import User, Engagement
88
from skills_matcher_db.project_owners.models import Project
99

1010

@@ -29,19 +29,28 @@ def get_context_data(self, **kwargs):
2929
.order_by("month")
3030
)
3131

32-
# get user metric data
32+
# get project metric data
3333
projects_metrics_qs = (
3434
Project.objects.annotate(month=TruncMonth("date_created"))
3535
.values("month")
3636
.annotate(project_count=Count("id"))
3737
.order_by("month")
3838
)
3939

40+
# get Engagement metric data
41+
eng_metrics_qs = (
42+
Engagement.objects.annotate(month=TruncMonth("date_created"))
43+
.values("month")
44+
.annotate(eng_count=Count("id"))
45+
.order_by("month")
46+
)
47+
4048
context.update(
4149
{
4250
"node_type": "assemblies",
4351
"user_metrics": user_metrics_qs,
4452
"project_metrics": projects_metrics_qs,
53+
"eng_metrics": eng_metrics_qs,
4554
}
4655
)
4756
return context
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{% load i18n %}
2+
3+
{% if app_list %}
4+
5+
{% for app in app_list %}
6+
<div class="app-{{ app.app_label }} module{% if app.app_url in request.path|urlencode %} current-app{% endif %}">
7+
<table>
8+
<caption>
9+
<a href="{{ app.app_url }}" class="section" title="{% blocktranslate with name=app.name %}Models in the {{ name }} application{% endblocktranslate %}">{{ app.name }}</a>
10+
</caption>
11+
12+
{% for model in app.models %}
13+
{% with model_name=model.object_name|lower %}
14+
<tr class="model-{{ model_name }}{% if model.admin_url in request.path|urlencode %} current-model{% endif %}">
15+
<th scope="row" id="{{ app.app_label }}-{{ model_name }}">
16+
{% if model.admin_url %}
17+
<a href="{{ model.admin_url }}"{% if model.admin_url in request.path|urlencode %} aria-current="page"{% endif %}>{{ model.name }}</a>
18+
{% else %}
19+
{{ model.name }}
20+
{% endif %}
21+
</th>
22+
23+
{% if model.add_url %}
24+
<td><a href="{{ model.add_url }}" class="addlink" aria-describedby="{{ app.app_label }}-{{ model_name }}">{% translate 'Add' %}</a></td>
25+
{% else %}
26+
<td></td>
27+
{% endif %}
28+
29+
{% if model.admin_url and show_changelinks %}
30+
{% if model.view_only %}
31+
<td><a href="{{ model.admin_url }}" class="viewlink" aria-describedby="{{ app.app_label }}-{{ model_name }}">{% translate 'View' %}</a></td>
32+
{% else %}
33+
<td><a href="{{ model.admin_url }}" class="changelink" aria-describedby="{{ app.app_label }}-{{ model_name }}">{% translate 'Change' %}</a></td>
34+
{% endif %}
35+
{% elif show_changelinks %}
36+
<td></td>
37+
{% endif %}
38+
</tr>
39+
{% endwith %}
40+
{% endfor %}
41+
</table>
42+
</div>
43+
{% endfor %}
44+
{% else %}
45+
<p>{% translate 'You don’t have permission to view or edit anything.' %}</p>
46+
{% endif %}

api/skills_matcher_db/templates/admin/core/metrics.html

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,67 @@
2121
<h1>Application Metrics</h1>
2222

2323
<h2>New Users by Month</h2>
24-
<ul>
25-
{% for item in user_metrics %}
26-
<li>{{ item.month|date:"Y-m" }} - {{ item.user_count }} user</li>
24+
<table style="width:300px">
25+
<tr>
26+
<th scope="row">
27+
<a href="{% url 'admin:view_metrics' %}"> Month </a>
28+
</th>
29+
<th scope="row">
30+
<a href="{% url 'admin:view_metrics' %}"> Users </a>
31+
</th>
32+
</tr>
33+
34+
{% for item in user_metrics %}
35+
<tr>
36+
<td>{{ item.month|date:"Y-m" }} </td><td> {{ item.user_count }} </td>
2737
{% empty %}
28-
<li>No items found.</li>
29-
{% endfor %}
30-
</ul>
38+
<td>No items found.</td><td></td>
39+
</tr>
40+
{% endfor %}
3141

42+
</table>
3243

3344
<h2>New Projects by Month</h2>
34-
<ul>
35-
{% for item in projects_metrics_qs %}
36-
<li>{{ item.month|date:"Y-m" }} - {{ item.project_count }} project</li>
37-
{% empty %}
38-
<li>No items found.</li>
45+
<table style="width:300px">
46+
<tr>
47+
<th scope="row">
48+
<a href="{% url 'admin:view_metrics' %}"> Month </a>
49+
</th>
50+
<th scope="row">
51+
<a href="{% url 'admin:view_metrics' %}"> Projects </a>
52+
</th>
53+
</tr>
54+
55+
{% for item in project_metrics %}
56+
<tr>
57+
<td>{{ item.month|date:"Y-m" }} </td><td> {{ item.project_count }} </td>
58+
{% empty %}
59+
<td>No items found.</td><td></td>
60+
</tr>
3961
{% endfor %}
40-
</ul>
62+
63+
</table>
64+
65+
<h2>New Engagements by Month</h2>
66+
<table style="width:300px">
67+
<tr>
68+
<th scope="row">
69+
<a href="{% url 'admin:view_metrics' %}"> Month </a>
70+
</th>
71+
<th scope="row">
72+
<a href="{% url 'admin:view_metrics' %}"> Engagements </a>
73+
</th>
74+
</tr>
75+
76+
{% for item in eng_metrics %}
77+
<tr>
78+
<td>{{ item.month|date:"Y-m" }} </td><td> {{ item.eng_count }} </td>
79+
{% empty %}
80+
<td>No items found.</td><td></td>
81+
</tr>
82+
{% endfor %}
83+
84+
</table>
4185

4286

4387

api/skills_matcher_db/users/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ class FavoriteAdmin(admin.ModelAdmin):
6161

6262
@admin.register(Engagement)
6363
class EngagementAdmin(admin.ModelAdmin):
64-
pass
64+
list_display = ["project_owner", "expert", "date_created", "date_responded"]

0 commit comments

Comments
 (0)