1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2004-2008 Tiny SPRL (http://tiny.be) All Rights Reserved.
8
# WARNING: This program as such is intended to be used by professional
9
# programmers who take the whole responsability of assessing all potential
10
# consequences resulting from its eventual inadequacies and bugs
11
# End users who are looking for a ready-to-use solution with commercial
12
# garantees and support are strongly adviced to contract a Free Software
15
# This program is Free Software; you can redistribute it and/or
16
# modify it under the terms of the GNU General Public License
17
# as published by the Free Software Foundation; either version 2
18
# of the License, or (at your option) any later version.
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
# GNU General Public License for more details.
25
# You should have received a copy of the GNU General Public License
26
# along with this program; if not, write to the Free Software
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
###############################################################################
29
from osv import fields, osv
32
from mx import DateTime
36
from service import security
37
from service import web_services
39
class game_scenario_step(osv.osv):
40
_name="game.scenario.step"
42
'name':fields.char('Name',size=64, required=True),
43
'description' : fields.text('Description'),
44
'menu_id' : fields.many2one('ir.ui.menu', 'Menu', required=True),
45
'accepted_users' : fields.one2many('res.users', 'user_id', 'User'),
46
'tip' : fields.text('Tip'),
47
'error' : fields.text('Error'),
48
'pre_process_object' : fields.char('Preprocess Object', size=64),
49
'pre_process_method' : fields.char('Preprocess Method', size=64),
50
'pre_process_args' : fields.text('Preprocess Args'),
51
'post_process_object' : fields.char('Postprocess Object', size=64),
52
'post_process_method' : fields.char('Postprocess Method', size=64),
53
'post_process_args' : fields.text('Postprocess Args')
57
class game_scenario(osv.osv):
60
'name':fields.char('Name',size=64, required=True),
61
'note':fields.text('Note'),
62
'step_ids':fields.many2many('game.scenario.step', 'game_scenario_step_rel', 'scenario_id', 'scenario_step_id', 'Steps'),
63
'state' : fields.selection([('draft','Draft'), ('running','Running'), ('done','Done'), ('cancel','Cancel')], 'State')
66
'state' : lambda *a : 'running',
73
'user_id' : fields.many2one('game.scenario.step', 'accepted_users',)
77
class scenario_objects_proxy(web_services.objects_proxy):
79
def execute(self, db, uid, passwd, object, method, *args):
80
security.check(db, uid, passwd)
81
service = netsvc.LocalService("object_proxy")
82
cr = pooler.get_db_only(db).cursor()
83
pool = pooler.get_pool(cr.dbname)
84
step_obj=pool.get('game.scenario.step')
85
cr.execute("select scenario_step_id from game_scenario_step_rel rel left join game_scenario s on s.id=rel.scenario_id where s.state='running' ")
86
step_ids=map(lambda x:x[0],cr.fetchall())
88
for step in step_obj.browse(cr,uid,step_ids):
89
pre_process_object = step.pre_process_object
90
pre_process_method = step.pre_process_method
92
res = service.execute(db, uid, pre_process_object, pre_process_method, *args)
94
except AttributeError:
95
step_obj.write(cr,uid,step_ids,{'error': AttributeError.__dict__['__doc__']})
99
res = service.execute(db, uid, object, method, *args)
101
post_process_object = step.post_process_object
102
post_process_method = step.post_process_method
103
res = service.execute(db, uid, object, method, *args)
104
res = service.execute(db, uid, post_process_object, post_process_method, *args)
108
scenario_objects_proxy()