forked from readthedocs/readthedocs.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filters.py
45 lines (36 loc) · 1.24 KB
/
filters.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""Filters used in our views."""
from django.utils.translation import gettext_lazy as _
from django_filters import (
CharFilter,
ChoiceFilter,
DateFromToRangeFilter,
FilterSet,
)
from readthedocs.audit.models import AuditLog
class UserSecurityLogFilter(FilterSet):
ip = CharFilter(field_name='ip', lookup_expr='exact')
project = CharFilter(field_name='log_project_slug', lookup_expr='exact')
action = ChoiceFilter(
field_name='action',
lookup_expr='exact',
choices=[
(AuditLog.AUTHN, _('Authentication success')),
(AuditLog.AUTHN_FAILURE, _('Authentication failure')),
],
)
date = DateFromToRangeFilter(field_name='created')
class Meta:
model = AuditLog
fields = []
class OrganizationSecurityLogFilter(UserSecurityLogFilter):
action = ChoiceFilter(
field_name='action',
lookup_expr='exact',
choices=[
(AuditLog.AUTHN, _('Authentication success')),
(AuditLog.AUTHN_FAILURE, _('Authentication failure')),
(AuditLog.PAGEVIEW, _('Page view')),
(AuditLog.DOWNLOAD, _('Download')),
],
)
user = CharFilter(field_name='log_user_username', lookup_expr='exact')