1
#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
2
from trytond.netsvc import Service, LocalService
3
from trytond import security
4
from threading import Lock
5
from random import randint
7
from trytond.tools import Cache
10
class Wizard(Service):
12
def __init__(self, name='wizard'):
13
Service.__init__(self, name)
14
Service.join_group(self, 'web-service')
15
Service.export_method(self, self.execute)
16
Service.export_method(self, self.create)
17
Service.export_method(self, self.delete)
23
def _execute(self, database, user, wiz_id, datas, action, context):
24
self.wiz_datas[wiz_id].update(datas)
25
wiz = LocalService('wizard_proxy')
26
return wiz.execute(database, user, self.wiz_name[wiz_id],
27
self.wiz_datas[wiz_id], action, context)
29
def create(self, database, user, passwd, wiz_name, datas=None):
30
security.check(database, user, passwd)
35
wiz_id = randint(0, maxint)
36
if wiz_id not in self.wiz_name:
38
self.wiz_datas[wiz_id] = {}
39
self.wiz_name[wiz_id] = wiz_name
40
self.wiz_uid[wiz_id] = user
42
Cache.resets(database)
45
def execute(self, database, user, passwd, wiz_id, datas, *args):
46
security.check(database, user, passwd)
48
if wiz_id in self.wiz_uid:
49
if self.wiz_uid[wiz_id] == user:
50
res = self._execute(database, user, wiz_id, datas, *args)
51
Cache.resets(database)
54
raise Exception, 'AccessDenied'
56
raise Exception, 'WizardNotFound'
58
def delete(self, database, user, passwd, wiz_id):
59
security.check(database, user, passwd)
61
if wiz_id in self.wiz_uid:
62
if self.wiz_uid[wiz_id] == user:
64
del self.wiz_datas[wiz_id]
65
del self.wiz_name[wiz_id]
66
del self.wiz_uid[wiz_id]
68
Cache.resets(database)
71
raise Exception, 'AccessDenied'
73
raise Exception, 'WizardNotFound'