8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 03:13:12 +00:00

Pep8 compliance on logs

This commit is contained in:
Maël Kervella 2018-04-13 20:37:04 +00:00
parent 9d7a7fa1f5
commit 0c8bb61574
4 changed files with 127 additions and 71 deletions

View file

@ -26,6 +26,7 @@
Here are defined some functions to check acl on the application. Here are defined some functions to check acl on the application.
""" """
def can_view(user): def can_view(user):
"""Check if an user can view the application. """Check if an user can view the application.

View file

@ -20,4 +20,3 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., # with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

View file

@ -25,7 +25,7 @@ from django import template
register = template.Library() register = template.Library()
@register.filter @register.filter
def classname(obj): def classname(obj):
return obj.__class__.__name__ return obj.__class__.__name__

View file

@ -227,66 +227,99 @@ def stats_general(request):
_all_baned = all_baned() _all_baned = all_baned()
_all_whitelisted = all_whitelisted() _all_whitelisted = all_whitelisted()
_all_active_interfaces_count = all_active_interfaces_count() _all_active_interfaces_count = all_active_interfaces_count()
_all_active_assigned_interfaces_count = all_active_assigned_interfaces_count() _all_active_assigned_interfaces_count = \
all_active_assigned_interfaces_count()
stats = [ stats = [
[["Categorie", "Nombre d'utilisateurs (total club et adhérents)", "Nombre d'adhérents", "Nombre de clubs"], { [ # First set of data (about users)
'active_users': [ [ # Headers
"Users actifs", "Categorie",
User.objects.filter(state=User.STATE_ACTIVE).count(), "Nombre d'utilisateurs (total club et adhérents)",
Adherent.objects.filter(state=Adherent.STATE_ACTIVE).count(), "Nombre d'adhérents",
Club.objects.filter(state=Club.STATE_ACTIVE).count()], "Nombre de clubs"
'inactive_users': [ ],
"Users désactivés", { # Data
User.objects.filter(state=User.STATE_DISABLED).count(), 'active_users': [
Adherent.objects.filter(state=Adherent.STATE_DISABLED).count(), "Users actifs",
Club.objects.filter(state=Club.STATE_DISABLED).count()], User.objects.filter(state=User.STATE_ACTIVE).count(),
'archive_users': [ (Adherent.objects
"Users archivés", .filter(state=Adherent.STATE_ACTIVE)
User.objects.filter(state=User.STATE_ARCHIVE).count(), .count()),
Adherent.objects.filter(state=Adherent.STATE_ARCHIVE).count(), Club.objects.filter(state=Club.STATE_ACTIVE).count()
Club.objects.filter(state=Club.STATE_ARCHIVE).count()], ],
'adherent_users': [ 'inactive_users': [
"Cotisant à l'association", "Users désactivés",
_all_adherent.count(), User.objects.filter(state=User.STATE_DISABLED).count(),
_all_adherent.exclude(adherent__isnull=True).count(), (Adherent.objects
_all_adherent.exclude(club__isnull=True).count()], .filter(state=Adherent.STATE_DISABLED)
'connexion_users': [ .count()),
"Utilisateurs bénéficiant d'une connexion", Club.objects.filter(state=Club.STATE_DISABLED).count()
_all_has_access.count(), ],
_all_has_access.exclude(adherent__isnull=True).count(), 'archive_users': [
_all_has_access.exclude(club__isnull=True).count()], "Users archivés",
'ban_users': [ User.objects.filter(state=User.STATE_ARCHIVE).count(),
"Utilisateurs bannis", (Adherent.objects
_all_baned.count(), .filter(state=Adherent.STATE_ARCHIVE)
_all_baned.exclude(adherent__isnull=True).count(), .count()),
_all_baned.exclude(club__isnull=True).count()], Club.objects.filter(state=Club.STATE_ARCHIVE).count()
'whitelisted_user': [ ],
"Utilisateurs bénéficiant d'une connexion gracieuse", 'adherent_users': [
_all_whitelisted.count(), "Cotisant à l'association",
_all_whitelisted.exclude(adherent__isnull=True).count(), _all_adherent.count(),
_all_whitelisted.exclude(club__isnull=True).count()], _all_adherent.exclude(adherent__isnull=True).count(),
'actives_interfaces': [ _all_adherent.exclude(club__isnull=True).count()
"Interfaces actives (ayant accès au reseau)", ],
_all_active_interfaces_count.count(), 'connexion_users': [
_all_active_interfaces_count.exclude( "Utilisateurs bénéficiant d'une connexion",
machine__user__adherent__isnull=True _all_has_access.count(),
).count(), _all_has_access.exclude(adherent__isnull=True).count(),
_all_active_interfaces_count.exclude( _all_has_access.exclude(club__isnull=True).count()
machine__user__club__isnull=True ],
).count()], 'ban_users': [
'actives_assigned_interfaces': [ "Utilisateurs bannis",
"Interfaces actives et assignées ipv4", _all_baned.count(),
_all_active_assigned_interfaces_count.count(), _all_baned.exclude(adherent__isnull=True).count(),
_all_active_assigned_interfaces_count.exclude( _all_baned.exclude(club__isnull=True).count()
machine__user__adherent__isnull=True ],
).count(), 'whitelisted_user': [
_all_active_assigned_interfaces_count.exclude( "Utilisateurs bénéficiant d'une connexion gracieuse",
machine__user__club__isnull=True _all_whitelisted.count(),
).count()] _all_whitelisted.exclude(adherent__isnull=True).count(),
}], _all_whitelisted.exclude(club__isnull=True).count()
[["Range d'ip", "Vlan", "Nombre d'ip totales", "Ip assignées", ],
"Ip assignées à une machine active", "Ip non assignées"], ip_dict] 'actives_interfaces': [
"Interfaces actives (ayant accès au reseau)",
_all_active_interfaces_count.count(),
(_all_active_interfaces_count
.exclude(machine__user__adherent__isnull=True)
.count()),
(_all_active_interfaces_count
.exclude(machine__user__club__isnull=True)
.count())
],
'actives_assigned_interfaces': [
"Interfaces actives et assignées ipv4",
_all_active_assigned_interfaces_count.count(),
(_all_active_assigned_interfaces_count
.exclude(machine__user__adherent__isnull=True)
.count()),
(_all_active_assigned_interfaces_count
.exclude(machine__user__club__isnull=True)
.count())
]
}
],
[ # Second set of data (about ip adresses)
[ # Headers
"Range d'ip",
"Vlan",
"Nombre d'ip totales",
"Ip assignées",
"Ip assignées à une machine active",
"Ip non assignées"
],
ip_dict # Data already prepared
] ]
]
return render(request, 'logs/stats_general.html', {'stats_list': stats}) return render(request, 'logs/stats_general.html', {'stats_list': stats})
@ -313,11 +346,26 @@ def stats_models(request):
'whitelist': [Whitelist.PRETTY_NAME, Whitelist.objects.count()] 'whitelist': [Whitelist.PRETTY_NAME, Whitelist.objects.count()]
}, },
'Cotisations': { 'Cotisations': {
'factures': [Facture._meta.verbose_name.title(), Facture.objects.count()], 'factures': [
'vente': [Vente._meta.verbose_name.title(), Vente.objects.count()], Facture._meta.verbose_name.title(),
'cotisation': [Cotisation._meta.verbose_name.title(), Cotisation.objects.count()], Facture.objects.count()
'article': [Article._meta.verbose_name.title(), Article.objects.count()], ],
'banque': [Banque._meta.verbose_name.title(), Banque.objects.count()], 'vente': [
Vente._meta.verbose_name.title(),
Vente.objects.count()
],
'cotisation': [
Cotisation._meta.verbose_name.title(),
Cotisation.objects.count()
],
'article': [
Article._meta.verbose_name.title(),
Article.objects.count()
],
'banque': [
Banque._meta.verbose_name.title(),
Banque.objects.count()
],
}, },
'Machines': { 'Machines': {
'machine': [Machine.PRETTY_NAME, Machine.objects.count()], 'machine': [Machine.PRETTY_NAME, Machine.objects.count()],
@ -432,14 +480,22 @@ def stats_actions(request):
} }
return render(request, 'logs/stats_users.html', {'stats_list': stats}) return render(request, 'logs/stats_users.html', {'stats_list': stats})
@login_required @login_required
@can_view_app('users') @can_view_app('users')
def stats_droits(request): def stats_droits(request):
"""Affiche la liste des droits et les users ayant chaque droit""" """Affiche la liste des droits et les users ayant chaque droit"""
depart=time() depart = time()
stats_list={} stats_list = {}
for droit in ListRight.objects.all().select_related('group_ptr'):
stats_list[droit]=droit.user_set.all().annotate(num=Count('revision'),last=Max('revision__date_created'))
return render(request, 'logs/stats_droits.html', {'stats_list': stats_list}) for droit in ListRight.objects.all().select_related('group_ptr'):
stats_list[droit] = droit.user_set.all().annotate(
num=Count('revision'),
last=Max('revision__date_created')
)
return render(
request,
'logs/stats_droits.html',
{'stats_list': stats_list}
)