Skip to content

Commit 3085b6f

Browse files
committed
ok
1 parent 21be141 commit 3085b6f

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

etsd/core/templates/core/stats.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% block page_title %}{% blocktrans %}Stats{% endblocktrans %}{% endblock %}
99

1010
{% block page_content %}
11-
11+
{% include "partials/_filter.html" with filter=filter %}
1212
<div class='row'>
1313
{% for s in stats %}
1414
<div class='col-md-4 mb-5' style='max-height: 500px; overflow: auto;'>

etsd/core/views.py

+46-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.http.response import HttpResponseRedirect
22
from django.views.generic import UpdateView, TemplateView, CreateView, ListView
33
from authorities.models import Authority
4+
from etsd.msgs.filters import MessageFilter
45
from .forms import AuthorityUsersModelForm
56
from django.contrib import messages
67
from django.utils.translation import gettext as _
@@ -324,11 +325,23 @@ def send_test_mail(request):
324325
"field": "cc",
325326
},
326327
{
327-
"label": "Per avg read time",
328+
"label": "Avg read time",
328329
"kind": "query_aggregate_single",
329330
"method": "avg",
330331
"field": "read_time",
331332
},
333+
{
334+
"label": "Max read time",
335+
"kind": "query_aggregate_single",
336+
"method": "max",
337+
"field": "read_time",
338+
},
339+
{
340+
"label": "Min read time",
341+
"kind": "query_aggregate_single",
342+
"method": "min",
343+
"field": "read_time",
344+
},
332345
]
333346

334347
AUTH_STATS_CFG = [
@@ -365,6 +378,28 @@ def send_test_mail(request):
365378
]
366379

367380

381+
class StatsMessageFilter(django_filters.FilterSet):
382+
sender = django_filters.CharFilter(
383+
label="Sender", field_name="sender", lookup_expr="icontains"
384+
)
385+
recipient = django_filters.CharFilter(
386+
label="Recipient", field_name="recipient", lookup_expr="icontains"
387+
)
388+
cc = django_filters.CharFilter(label="CC", field_name="cc", lookup_expr="icontains")
389+
390+
class Meta:
391+
model = models.Message
392+
fields = {
393+
"kind": ["exact"],
394+
"status": ["exact"],
395+
"protocol_year": ["exact"],
396+
"sent_on": ["exact", "month", "year"],
397+
}
398+
399+
def __init__(self, *args, **kwargs):
400+
super().__init__(*args, **kwargs)
401+
402+
368403
class StatsView(TemplateView):
369404
template_name = "core/stats.html"
370405

@@ -395,7 +430,9 @@ def get_context_data(self, **kwargs):
395430
read_time=F("data_access_date") - F("sent_on"),
396431
)
397432

398-
stats = get_stats(qs, STATS_CFG)
433+
filter = StatsMessageFilter(self.request.GET, qs)
434+
435+
stats = get_stats(filter.qs, STATS_CFG)
399436

400437
auth_qs = auth_models.Authority.objects.all().annotate(
401438
has_users=Exists(User.objects.filter(authorities__id=OuterRef("pk"))),
@@ -406,6 +443,12 @@ def get_context_data(self, **kwargs):
406443
),
407444
)
408445
auth_stats = get_stats(auth_qs, AUTH_STATS_CFG)
409-
ctx.update({"stats": stats, "auth_stats": auth_stats})
446+
ctx.update(
447+
{
448+
"stats": stats,
449+
"auth_stats": auth_stats,
450+
"filter": filter,
451+
}
452+
)
410453

411454
return ctx

0 commit comments

Comments
 (0)