-
Notifications
You must be signed in to change notification settings - Fork 7
/
client.py
89 lines (72 loc) · 3.06 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from orm import models, tools, configuration, menu, data
from orm.client import init, init_compile
from javascript import JSON, Object, Error, asynchronous, function
if not configuration.server_url: configuration.server_url = ''
import sys
import orm
sys.modules['orm'] = orm
import modules
configuration.modules = modules
modules.load()
menu.check_menus()
tools.register_models()
from react.components.App import App
#from react.elements import div, text
@function
def set_server_url(resolve, url):
configuration.server_url = url.toString()
resolve.call()
@function
def set_user(resolve, id, login, password):
models.env.user.id = id.toString()
models.env.user.login = login.toString()
models.env.user.password = password.toString()
resolve.call()
@asynchronous
def get_user_name():
user_id = models.env['res.users'].browse(models.env.user.id).wait()
models.env.user.name = user_id.name
data.register(get_user_name)
@function(asynchronous=True)
def search(domain_args):
domain = []
for args in domain_args.toArray():
if args['length'].toInteger() != 3:
Error('Not sufficient')
domain += [(args['0'].toString(), args['1'].toString(), args['2'].toRef())]
records = models.env['res.users'].search(domain).wait()
print len(records)
for record in records:
print record.name
record.read().log()
css = '\n'.join(open(file, 'r').read() for file in ['./react/styles/menu.css', './react/styles/appbar.css', './react/styles/list.css', './react/styles/form.css'])
if not configuration.appbar_color:
css += "\n[class*='RaAppBar-toolbar-'] {padding-right: 50px!important}\n[class*='RaLayout-appFrame-'] > header.MuiAppBar-root {border-top: none; border-right: none; border-left: none;}\n@media only screen and (min-width: 342px) {#solu-appbar-icon {visibility: unset!important}}"
def mount_css():
document = Object.get('window', 'document')
style = document['createElement'].call('style')
style['innerHTML'] = css
document['querySelector'].call('head')['append'].call(style.toRef())
def main(argv):
mount_css()
url_promise, url_resolve = tools.create_promise()
user_promise, user_resolve = tools.create_promise()
promise = tools.Global()['Promise']['all'].call(JSON.fromList([url_promise.toRef(), user_promise.toRef()]))
ORM = tools.Global()['Object'].new()
ORM['set_server_url'] = Object.createClosure(set_server_url, url_resolve).toRef()
ORM['set_user'] = Object.createClosure(set_user, user_resolve).toRef()
ORM['search'] = JSON.fromFunction(search)
Module = Object.get('Module')
Module['orm'] = ORM.toRef()
Module['orm_resolve'].call()
init(promise, App().toObject()) #div([text('hello')]).toObject())
return 0
def target(*args):
if configuration.server_db.startswith('http'):
import os
url = os.path.split(configuration.server_db)
configuration.server_db = next(route for route in url[::-1] if route)
configuration.server_db_url = ""
init_compile()
models.env.user = models.env['res.users'].new()
return main, None