Revision 20367931
Réorganisation du code (controllers, etc)
Mise en place d'un système de plugin pour ajouter des colonnes à la volée
Internationalisation complète
Création de quelques tests
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@274 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigiboard/model/vigiboard_bdd/eventhistory.py | ||
---|---|---|
1 | 1 |
# -*- coding: utf-8 -*- |
2 |
"""Model For EventHistory Table""" |
|
2 |
# vim:set expandtab tabstop=4 shiftwidth=4: |
|
3 |
"""Modèle pour la table EventHistory""" |
|
3 | 4 |
|
4 | 5 |
from sqlalchemy.orm import mapper, relation |
5 |
from sqlalchemy import Table, ForeignKeyConstraint, Column, Index
|
|
6 |
from sqlalchemy import ForeignKey, Table, Column, Index
|
|
6 | 7 |
from sqlalchemy.types import Integer, String, Text, DateTime |
7 | 8 |
|
8 | 9 |
from vigiboard.model import metadata |
9 | 10 |
|
10 | 11 |
from sqlalchemy.databases.mysql import MSEnum |
11 | 12 |
|
12 |
from tg import config
|
|
13 |
from vigiboard.config.vigiboard_config import vigiboard_config
|
|
13 | 14 |
|
14 | 15 |
from datetime import datetime |
15 | 16 |
|
16 | 17 |
# Generation par SQLAutoCode |
17 | 18 |
|
18 |
event_history = Table(config['vigiboard_bdd.basename'] + 'event_history', metadata, |
|
19 |
Column(u'idhistory', Integer(), primary_key=True, nullable=False),
|
|
20 |
Column(u'type_action', MSEnum('Nagios update state','Acknowlegement change state','New occurence','User comment','Ticket change','Oncall','Forced state'), primary_key=False, nullable=False),
|
|
21 |
Column(u'idevent', Integer(), primary_key=False, nullable=False),
|
|
22 |
Column(u'value', String(length=255, convert_unicode=False, assert_unicode=None), primary_key=False),
|
|
23 |
Column(u'text', Text(length=None, convert_unicode=False, assert_unicode=None), primary_key=False),
|
|
24 |
Column(u'timestamp', DateTime(timezone=False), default=datetime.now(),primary_key=False),
|
|
25 |
Column(u'username', String(length=255, convert_unicode=False, assert_unicode=None), primary_key=False),
|
|
26 |
ForeignKeyConstraint([u'idevent'], [config['vigiboard_bdd.basename'] + u'events.idevent'], name=u'actions_ibfk_1'),
|
|
27 |
|
|
19 |
event_history = Table(vigiboard_config['vigiboard_bdd.basename'] + 'event_history', metadata,
|
|
20 |
Column(u'idhistory', Integer(),primary_key=True, nullable=False,autoincrement=True),
|
|
21 |
Column(u'type_action', MSEnum('Nagios update state','Acknowlegement change state','New occurence','User comment','Ticket change','Oncall','Forced state'), primary_key=False, nullable=False),
|
|
22 |
Column(u'idevent', Integer(), ForeignKey(vigiboard_config['vigiboard_bdd.basename'] +'events.idevent'),index=True,primary_key=False, nullable=False),
|
|
23 |
Column(u'value', String(length=255, convert_unicode=True, assert_unicode=None), primary_key=False),
|
|
24 |
Column(u'text', Text(length=None, convert_unicode=True, assert_unicode=None), primary_key=False),
|
|
25 |
Column(u'timestamp', DateTime(timezone=False), default=datetime.now(),primary_key=False), |
|
26 |
Column(u'username', String(length=255, convert_unicode=True, assert_unicode=None), primary_key=False),
|
|
27 |
mysql_engine='InnoDB',
|
|
28 |
mysql_charset='utf8' |
|
28 | 29 |
) |
29 |
Index(u'idevent', event_history.c.idevent, unique=False) |
|
30 | 30 |
|
31 | 31 |
# Classe a mapper |
32 | 32 |
|
33 | 33 |
class EventHistory(object): |
34 |
def __init__(self,type_action,idevent,value,text,username): |
|
35 |
self.type_action = type_action |
|
36 |
self.idevent = idevent |
|
37 |
self.value = value |
|
38 |
self.text = text |
|
39 |
self.username = username |
|
34 |
""" |
|
35 |
Classe liée avec la table associée |
|
36 |
""" |
|
37 |
def __init__(self,type_action,idevent,value='',text='',username=''): |
|
38 |
|
|
39 |
""" |
|
40 |
Fonction d'initialisation, permet de faire un INSERT en une fonction |
|
41 |
|
|
42 |
@param type_action: Le type d'action effectué, peut être 'Nagios update state', |
|
43 |
'Acknowlegement change state', 'New occurence', 'User comment', 'Ticket change', |
|
44 |
'Oncall' ou 'Forced state' |
|
45 |
@param idevent: Identifiant de l'évènement |
|
46 |
@param value: Nouvelle sévérité |
|
47 |
@param text: Commentaire sur l'action effectuée |
|
48 |
@param username: Nom d'utilisateur de la personne effectuant l'action |
|
49 |
""" |
|
50 |
|
|
51 |
self.type_action = type_action |
|
52 |
self.idevent = idevent |
|
53 |
self.value = value |
|
54 |
self.text = text |
|
55 |
self.username = username |
|
40 | 56 |
|
41 | 57 |
mapper(EventHistory,event_history) |
42 |
|
Also available in: Unified diff