vigiboard / vigiboard / controllers / plugins / groups.py @ 180b869a
History | View | Annotate | Download (2.86 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4:
|
3 |
################################################################################
|
4 |
#
|
5 |
# Copyright (C) 2007-2011 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 les groupes
|
23 |
d'éléments supervisés auxquels appartient l'objet associé
|
24 |
à l'événement corrélé.
|
25 |
"""
|
26 |
import tw.forms as twf |
27 |
from pylons.i18n import lazy_ugettext as l_ |
28 |
|
29 |
from vigiboard.controllers.plugins import VigiboardRequestPlugin |
30 |
from vigilo.models.session import DBSession |
31 |
from vigilo.models.tables.group import Group |
32 |
from vigilo.models.tables.grouphierarchy import GroupHierarchy |
33 |
|
34 |
from repoze.what.predicates import in_group |
35 |
from tg import request |
36 |
|
37 |
class GroupSelector(twf.InputField): |
38 |
params = ["choose_text", "text_value", "clear_text"] |
39 |
choose_text = l_('Choose')
|
40 |
clear_text = l_('Clear')
|
41 |
text_value = ''
|
42 |
|
43 |
template = """
|
44 |
<div xmlns="http://www.w3.org/1999/xhtml"
|
45 |
xmlns:py="http://genshi.edgewall.org/" py:strip="">
|
46 |
<input type="hidden" name="${name}" class="${css_class}"
|
47 |
id="${id}.value" value="${value}" py:attrs="attrs" />
|
48 |
<input type="text" class="${css_class}" id="${id}.ui"
|
49 |
value="${text_value}" readonly="readonly" py:attrs="attrs" />
|
50 |
<input type="button" class="${css_class}" id="${id}"
|
51 |
value="${choose_text}" py:attrs="attrs" />
|
52 |
<input type="button" class="${css_class}" id="${id}.clear"
|
53 |
value="${clear_text}" py:attrs="attrs" />
|
54 |
</div>
|
55 |
"""
|
56 |
|
57 |
def update_params(self, d): |
58 |
super(GroupSelector, self).update_params(d) |
59 |
text_value = DBSession.query(Group.name).filter( |
60 |
Group.idgroup == d.value).scalar() |
61 |
if not text_value: |
62 |
d.value = ''
|
63 |
else:
|
64 |
d.text_value = text_value |
65 |
|
66 |
|
67 |
class PluginGroups(VigiboardRequestPlugin): |
68 |
"""
|
69 |
Affiche les groupes d'éléments supervisés auxquels
|
70 |
appartient l'événement corrélé.
|
71 |
"""
|
72 |
def get_search_fields(self): |
73 |
return [
|
74 |
GroupSelector( |
75 |
'supitemgroup',
|
76 |
label_text=l_('Group'),
|
77 |
validator=twf.validators.Int(if_invalid=None, if_missing=None), |
78 |
) |
79 |
] |
80 |
|
81 |
def handle_search_fields(self, query, search): |
82 |
pass
|