iwla/plugins/display/all_visits_enlight.py

80 lines
2.1 KiB
Python
Raw Normal View History

2022-11-20 10:15:13 +01:00
# -*- coding: utf-8 -*-
#
# Copyright Grégory Soutadé 2022
# This file is part of iwla
# iwla is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iwla is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with iwla. If not, see <http://www.gnu.org/licenses/>.
#
from iwla import IWLA
from iplugin import IPlugin
from display import *
import logging
import re
"""
Display hook
Enlight users in all visits page if visitor['enlight'] property is True
or user is filtered
Can be set in filter users callback
Plugin requirements :
IWLADisplayAllVisits
Conf values needed :
None
Output files :
None
Statistics creation :
None
Statistics update :
None
Statistics deletion :
None
"""
class IWLADisplayAllVisitsEnlight(IPlugin):
def load(self):
self.ip_re = re.compile(r'.*\[(.*)\].*')
return True
def hook(self):
display = self.iwla.getDisplay()
visitors = self.iwla.getValidVisitors()
path = self.iwla.getCurDisplayPath('all_visits.html')
page = display.getPage(path)
if not page:
self.logger.error('No page for %s' % (path))
return
title = self.iwla._('All visits')
block = page.getBlock(title)
if not block:
self.logger.error('Block %s not found' % (title))
return
for (idx, row) in enumerate(block.rows):
remote_ip = block.objects[idx]
if remote_ip is None or not remote_ip in visitors.keys(): continue
visitor = visitors[remote_ip]
2023-04-28 16:17:47 +02:00
if visitor.get('enlight', False) or\
visitor.get('filtered', False):
2022-11-20 10:15:13 +01:00
block.setCellCSSClass(idx, 0, 'iwla_enlight')