~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to game_scenario/game_scenario.py

  • Committer: Priyesh
  • Date: 2008-10-20 14:24:03 UTC
  • mto: This revision was merged to the branch mainline in revision 3303.
  • Revision ID: solanki.priyesh@gmail.com-20081020142403-mc6gnm35a1ybqvyx
made new module named game_scenario

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2004-2008 Tiny SPRL (http://tiny.be) All Rights Reserved.
 
5
#
 
6
# $Id$
 
7
#
 
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
 
13
# Service Company
 
14
#
 
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.
 
19
#
 
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.
 
24
#
 
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
 
30
import pooler
 
31
import time
 
32
from mx import DateTime
 
33
import datetime
 
34
 
 
35
import netsvc
 
36
from service import security
 
37
from service import web_services
 
38
 
 
39
class game_scenario_step(osv.osv):
 
40
    _name="game.scenario.step"
 
41
    _columns = {
 
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')
 
54
        }
 
55
game_scenario_step()
 
56
 
 
57
class game_scenario(osv.osv):
 
58
    _name="game.scenario"
 
59
    _columns = {
 
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')
 
64
    }
 
65
    _defaults = {
 
66
        'state' : lambda *a : 'running',       
 
67
        }
 
68
game_scenario()
 
69
 
 
70
class users(osv.osv):
 
71
    _inherit="res.users"
 
72
    _columns={
 
73
        'user_id' : fields.many2one('game.scenario.step', 'accepted_users',)      
 
74
        }
 
75
users()
 
76
 
 
77
class scenario_objects_proxy(web_services.objects_proxy):
 
78
    
 
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())
 
87
       
 
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
 
91
            try:
 
92
                res = service.execute(db, uid, pre_process_object, pre_process_method, *args)
 
93
               
 
94
            except AttributeError:
 
95
                step_obj.write(cr,uid,step_ids,{'error': AttributeError.__dict__['__doc__']})
 
96
                cr.commit()
 
97
            
 
98
            if not res:
 
99
                res = service.execute(db, uid, object, method, *args)
 
100
            else:
 
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)
 
105
 
 
106
        return res
 
107
            
 
108
scenario_objects_proxy()
 
109
 
 
110