85 lines
2.3 KiB
Python
85 lines
2.3 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
# Copyright Grégory Soutadé 2015
|
||
|
|
||
|
# 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 *
|
||
|
|
||
|
"""
|
||
|
Display hook
|
||
|
|
||
|
Enlight new and updated key phrases in in all_key_phrases.html
|
||
|
|
||
|
Plugin requirements :
|
||
|
display/referers
|
||
|
|
||
|
Conf values needed :
|
||
|
None
|
||
|
|
||
|
Output files :
|
||
|
None
|
||
|
|
||
|
Statistics creation :
|
||
|
None
|
||
|
|
||
|
Statistics update :
|
||
|
None
|
||
|
|
||
|
Statistics deletion :
|
||
|
None
|
||
|
"""
|
||
|
|
||
|
class IWLADisplayReferersDiff(IPlugin):
|
||
|
def __init__(self, iwla):
|
||
|
super(IWLADisplayReferersDiff, self).__init__(iwla)
|
||
|
self.API_VERSION = 1
|
||
|
self.requires = ['IWLADisplayReferers']
|
||
|
|
||
|
def load(self):
|
||
|
if not self.iwla.getConfValue('create_all_key_phrases_page', True):
|
||
|
return False
|
||
|
month_stats = self.iwla.getMonthStats()
|
||
|
self.cur_key_phrases = {k:v for (k,v) in month_stats.get('key_phrases', {})}
|
||
|
return True
|
||
|
|
||
|
def hook(self):
|
||
|
display = self.iwla.getDisplay()
|
||
|
month_stats = self.iwla.getMonthStats()
|
||
|
|
||
|
filename = 'key_phrases.html'
|
||
|
path = self.iwla.getCurDisplayPath(filename)
|
||
|
page = display.getPage(path)
|
||
|
if not page: return
|
||
|
title = self.iwla._(u'All key phrases')
|
||
|
referers_block = page.getBlock(title)
|
||
|
|
||
|
kp_diff = {}
|
||
|
for (k, v) in month_stats['key_phrases'].items():
|
||
|
new_value = self.cur_key_phrases.get(k, 0)
|
||
|
if new_value:
|
||
|
if new_value != v:
|
||
|
kp_diff[k] = 'iwla_update'
|
||
|
else:
|
||
|
kp_diff[k] = 'iwla_new'
|
||
|
|
||
|
for (idx, row) in enumerate(referers_block.rows):
|
||
|
if row[0] in kp_diff.keys():
|
||
|
referers_block.setCellCSSClass(idx, 0, kp_diff[row[0]])
|