Add nick-history functionality

hover a nickname to show previous nicks
This commit is contained in:
Thor77 2017-02-11 22:14:34 +01:00
parent 6366d3ebb1
commit 22f6402bce
4 changed files with 14 additions and 3 deletions

View File

@ -70,6 +70,7 @@ class Client(object):
# public
self.identifier = identifier
self.nick = nick
self.nick_history = set()
self.connected = 0
self.onlinetime = datetime.timedelta()
self.kicks = 0

View File

@ -143,7 +143,11 @@ def _parse_details(log_path, ident_map=None, clients=None, online_dc=True):
continue
nick, clid = match.group('nick'), match.group('clid')
client = clients.setdefault(clid, Client(clid, nick))
client.nick = nick # set nick to display changes
# set current nick
client.nick = nick
# add nick to history
client.nick_history.add(nick)
action = match.group('action')
if action == 'connected':
client.connect(logdatetime)

View File

@ -20,7 +20,7 @@ def prepare_clients(clients, onlinetime_threshold=-1):
'''
Prepare `clients` for rendering
sort them and convert onlinetime to string
sort them, clean their nick-history and convert onlinetime to string
:param clients: List of clients to prepare
:param onlinetime_threshold: threshold for clients onlinetime
@ -31,6 +31,12 @@ def prepare_clients(clients, onlinetime_threshold=-1):
:return: `clients` sorted by onlinetime, kics, pkicks, bans and pbans
:rtype: tsstats.template.SortedClients
'''
# drop current nick from nick-history
[
c.nick_history.remove(c.nick)
for c in clients
if c.nick in c.nick_history
]
# sort by onlinetime
onlinetime_ = sort_clients(
clients, lambda c: c.onlinetime.total_seconds()

View File

@ -13,7 +13,7 @@
{% for client, value in clients %}
{% set id = [headline_id, client.nick|striptags]|join('.') %}
<li id="{{ id }}" onclick="window.location = '#{{ id }}'" class="list-group-item{{ ' list-group-item-success' if client.connected else loop.cycle('" style="background-color: #eee;', '') }}">
<span>{{ client.nick }}{{ " (" + client.identifier + ")" if debug }}</span>
<span class="hint--right" data-hint="{{ client.nick_history|join(', ') }}">{{ client.nick }}{{ " (" + client.identifier + ")" if debug }}</span>
<span class="badge"><div{% if not client.connected and headline == 'Onlinetime' %} class="hint--left" data-hint="{{ client.last_seen|frmttime }}"{% endif %}>{{ value }}</div></span>
</li>
{% endfor %}