Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / controllers / plugins / state.py @ 04e82857

History | View | Annotate | Download (2.66 KB)

1
# -*- coding: utf-8 -*-
2
# vim:set expandtab tabstop=4 shiftwidth=4:
3
################################################################################
4
#
5
# Copyright (C) 2007-2014 CS-SI
6
#
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License version 2 as
9
# published by the Free Software Foundation.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
################################################################################
20

    
21
"""
22
Un plugin pour VigiBoard qui ajoute une colonne avec l'état de l'alerte.
23
"""
24
import urllib
25
import tg
26
import tw.forms as twf
27
from pylons.i18n import lazy_ugettext as l_
28

    
29
from vigilo.models.tables import CorrEvent, Event, StateName
30
from vigilo.models.session import DBSession
31
from vigiboard.controllers.plugins import VigiboardRequestPlugin, ITEMS
32

    
33
class PluginState(VigiboardRequestPlugin):
34
    """
35
    Ajoute des colonnes permettant de voir le statut d'acquittement
36
    d'un événement corrélé et de modifier certaines de ses propriétés.
37
    """
38

    
39
    def get_search_fields(self):
40
        states = DBSession.query(StateName.idstatename, StateName.statename
41
                    ).order_by(StateName.order.asc()).all()
42
        options = [('', u'')] + \
43
                    [( str(s.idstatename), s.statename ) for s in states]
44
        return [
45
            twf.SingleSelectField(
46
                'state',
47
                label_text=l_('Current state'),
48
                options=options,
49
                validator=twf.validators.OneOf(
50
                    dict(options).keys(),
51
                    if_invalid=None,
52
                    if_missing=None,
53
                ),
54
            ),
55
        ]
56

    
57
    def handle_search_fields(self, query, search, state, subqueries):
58
        if state != ITEMS:
59
            return
60

    
61
        if search.get('state'):
62
            try:
63
                query.add_filter(Event.current_state == int(search['state']))
64
            except (ValueError, TypeError):
65
                # On ignore silencieusement le critère de recherche erroné.
66
                pass
67

    
68
    def get_data(self, event):
69
        cause = event[0].cause
70
        state = StateName.value_to_statename(cause.current_state)
71
        return {'state': state}
72

    
73
    def get_sort_criterion(self, query, column):
74
        return Event.current_state
75