iwla

iwla Git Source Tree

Root/plugins/display/referers_diff.py

1# -*- coding: utf-8 -*-
2#
3# Copyright Grégory Soutadé 2015
4
5# This file is part of iwla
6
7# iwla is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# iwla is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with iwla. If not, see <http://www.gnu.org/licenses/>.
19#
20
21from iwla import IWLA
22from iplugin import IPlugin
23from display import *
24
25"""
26Display hook
27
28Enlight new and updated key phrases in in all_key_phrases.html
29
30Plugin requirements :
31 display/referers
32
33Conf values needed :
34 None
35
36Output files :
37 None
38
39Statistics creation :
40 None
41
42Statistics update :
43 None
44
45Statistics deletion :
46 None
47"""
48
49class IWLADisplayReferersDiff(IPlugin):
50 def __init__(self, iwla):
51 super(IWLADisplayReferersDiff, self).__init__(iwla)
52 self.API_VERSION = 1
53 self.requires = ['IWLADisplayReferers']
54
55 def load(self):
56 if not self.iwla.getConfValue('create_all_key_phrases_page', True):
57 return False
58 month_stats = self.iwla.getMonthStats()
59 self.cur_key_phrases = {k:v for (k,v) in month_stats.get('key_phrases', {})}
60 return True
61
62 def hook(self):
63 display = self.iwla.getDisplay()
64 month_stats = self.iwla.getMonthStats()
65
66 filename = 'key_phrases.html'
67 path = self.iwla.getCurDisplayPath(filename)
68 page = display.getPage(path)
69 if not page: return
70 title = self.iwla._(u'All key phrases')
71 referers_block = page.getBlock(title)
72
73 kp_diff = {}
74 for (k, v) in month_stats['key_phrases'].items():
75 new_value = self.cur_key_phrases.get(k, 0)
76 if new_value:
77 if new_value != v:
78 kp_diff[k] = 'iwla_update'
79 else:
80 kp_diff[k] = 'iwla_new'
81
82 for (idx, row) in enumerate(referers_block.rows):
83 if row[0] in kp_diff.keys():
84 referers_block.setCellCSSClass(idx, 0, kp_diff[row[0]])

Archive Download this file

Branches

Tags