Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / vigiboard_plugin / shn.py @ c49defb8

History | View | Annotate | Download (2.32 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4: 
3
"""
4
Plugin SHN : High level service
5
"""
6

    
7
from vigiboard.controllers.vigiboard_plugin import \
8
        VigiboardRequestPlugin
9
from vigiboard.model import DBSession, EventsAggregate#, HighLevelService
10
from pylons.i18n import gettext as _
11
from tg import tmpl_context, url
12
from tw.jquery.ui_dialog import JQueryUIDialog
13

    
14
class PluginSHN(VigiboardRequestPlugin):
15

    
16
    """
17
    Plugin permettant de rajouter le nombre de SHNs impactés à
18
    l'affichage et d'obtenir une liste détaillée de ces SHNs.
19
    """
20

    
21
    def __init__(self):
22
        super(PluginSHN, self).__init__(
23
            name = _(u'Impacted HLS'),
24
            style = {'title': _(u'Impacted High-Level Services'),
25
                'style': 'text-align:center'},
26
            object_name = "shn"
27
        )
28
    
29
    def show(self, aggregate):
30
        """Fonction d'affichage"""
31
        dico = {
32
            'baseurl': url('/'),
33
            'idaggregate': aggregate.idaggregate,
34
            'impacted_hls': len(aggregate.high_level_services),
35
        }
36
        # XXX Il faudrait échapper l'URL contenue dans baseurl
37
        # pour éviter des attaques de type XSS.
38
        res = ('<a href="javascript:vigiboard_shndialog(' + \
39
                '\'%(baseurl)s\',\'%(idaggregate)s\')" ' + \
40
                'class="SHNLien">%(impacted_hls)d</a>') % dico
41
        return res
42

    
43
    def context(self, context):
44
        """Fonction de context"""
45

    
46
        # On ajoute 10 espaces insécables pour éviter un bug de JQueryUIDialog:
47
        # le calcul de la taille de la boîte de dialogue ne tient pas compte
48
        # de l'espace occupé par la croix permettant de fermer le dialogue.
49
        # Du coup, elle se retrouve superposée au titre de la boîte.
50
        tmpl_context.shndialog = JQueryUIDialog(id='SHNDialog',
51
                autoOpen=False, title='%s%s' % (_(u'High-Level Service'),
52
                '&#160;' * 10))
53
        context.append([tmpl_context.shndialog, self.object_name])
54

    
55
    def controller(self, *argv, **krgv):
56
        """Ajout de fonctionnalités au contrôleur"""
57
        idaggregate = krgv['idaggregate']
58
        aggregate = DBSession.query(EventsAggregate) \
59
                .filter(EventsAggregate.idaggregate == idaggregate).one()
60
        shns = aggregate.highlevel
61

    
62
        return dict(shns=[shn.servicename for shn in shns]) 
63