vigiboard / vigiboard / widgets / search_form.py @ 3b537383
History | View | Annotate | Download (3.83 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 |
"""Le formulaire de recherche/filtrage."""
|
22 |
|
23 |
from pylons.i18n import lazy_ugettext as l_ |
24 |
from tw.api import WidgetsList |
25 |
import tw.forms as twf |
26 |
from tg.i18n import get_lang |
27 |
import tg |
28 |
|
29 |
from vigilo.models.session import DBSession |
30 |
from vigilo.models.tables.group import Group |
31 |
|
32 |
__all__ = ( |
33 |
'SearchForm',
|
34 |
'create_search_form',
|
35 |
) |
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 |
class SearchForm(twf.TableForm): |
67 |
"""
|
68 |
Formulaire de recherche dans les événements
|
69 |
|
70 |
Affiche un champ texte pour l'hôte, le service, la sortie,
|
71 |
le ticket d'incidence, et la date.
|
72 |
|
73 |
Ce widget permet de répondre aux exigences suivantes :
|
74 |
- VIGILO_EXIG_VIGILO_BAC_0070
|
75 |
- VIGILO_EXIG_VIGILO_BAC_0100
|
76 |
"""
|
77 |
|
78 |
method = 'GET'
|
79 |
style = 'display: none'
|
80 |
|
81 |
class fields(WidgetsList): |
82 |
supitemgroup = GroupSelector(label_text=l_('Group'))
|
83 |
host = twf.TextField(label_text=l_('Host'))
|
84 |
service = twf.TextField(label_text=l_('Service'))
|
85 |
output = twf.TextField(label_text=l_('Output'))
|
86 |
trouble_ticket = twf.TextField(label_text=l_('Trouble Ticket'))
|
87 |
from_date = twf.CalendarDateTimePicker( |
88 |
label_text = l_('From'),
|
89 |
button_text = l_("Choose"),
|
90 |
not_empty = False)
|
91 |
to_date = twf.CalendarDateTimePicker( |
92 |
label_text = l_('To'),
|
93 |
button_text = l_("Choose"),
|
94 |
not_empty = False)
|
95 |
|
96 |
def get_calendar_lang(): |
97 |
# TODO: Utiliser le champ "language" du modèle pour cet utilisateur ?
|
98 |
# On récupère la langue du navigateur de l'utilisateur
|
99 |
lang = get_lang() |
100 |
if not lang: |
101 |
lang = tg.config['lang']
|
102 |
else:
|
103 |
lang = lang[0]
|
104 |
|
105 |
# TODO: Il faudrait gérer les cas où tout nous intéresse dans "lang".
|
106 |
# Si l'identifiant de langage est composé (ex: "fr_FR"),
|
107 |
# on ne récupère que la 1ère partie.
|
108 |
lang = lang.replace('_', '-') |
109 |
lang = lang.split('-')[0] |
110 |
return lang
|
111 |
|
112 |
create_search_form = SearchForm("search_form",
|
113 |
submit_text=l_('Search'), action=tg.url('/'), |
114 |
) |