[IMP] Fix the error for on login and clean up to remove extra code.

bzr revid: jra@tinyerp.com-20110609054834-02sdc00g4x2krefj
This commit is contained in:
Jiten Rangwala (OpenERP) 2011-06-09 11:18:34 +05:30
parent 46933a8e64
commit 3e74d5d6bc
3 changed files with 8 additions and 296 deletions

View File

@ -58,37 +58,6 @@ class Xml2Json:
class MOBILE(openerpweb.Controller):
_cp_path = "/web_mobile/mobile"
def manifest_glob(self, addons, key):
files = []
for addon in addons:
globlist = openerpweb.addons_manifest.get(addon, {}).get(key, [])
files.extend([
resource_path[len(openerpweb.path_addons):]
for pattern in globlist
for resource_path in glob.glob(os.path.join(
openerpweb.path_addons, addon, pattern))
])
return files
def concat_files(self, file_list):
""" Concatenate file content
return (concat,timestamp)
concat: concatenation of file content
timestamp: max(os.path.getmtime of file_list)
"""
root = openerpweb.path_root
files_content = []
files_timestamp = 0
for i in file_list:
fname = os.path.join(root, i)
ftime = os.path.getmtime(fname)
if ftime > files_timestamp:
files_timestamp = ftime
files_content = open(fname).read()
files_concat = "".join(files_content)
return files_concat
@openerpweb.jsonrequest
def db_list(self, req):
return req.session.proxy('db').list()
@ -96,240 +65,12 @@ class MOBILE(openerpweb.Controller):
@openerpweb.jsonrequest
def sc_list(self, req):
return req.session.model('ir.ui.view_sc').get_sc(req.session._uid, "ir.ui.menu", {})
@openerpweb.jsonrequest
def logout(self,req):
req.session._uid =False
@openerpweb.jsonrequest
def login(self, req, db, login, password):
req.session.login(db, login, password)
req.session_id = False
req.session._uid = False
return {
"session_id": req.session_id,
"uid": req.session._uid,
}
@openerpweb.jsonrequest
def modules(self, req):
return {"modules": [name
for name, manifest in openerpweb.addons_manifest.iteritems()
if manifest.get('active', True)]}
@openerpweb.jsonrequest
def csslist(self, req, mods='base'):
return {'files': self.manifest_glob(mods.split(','), 'css')}
@openerpweb.jsonrequest
def jslist(self, req, mods='base'):
return {'files': self.manifest_glob(mods.split(','), 'js')}
def css(self, req, mods='base,base_hello'):
files = self.manifest_glob(mods.split(','), 'css')
concat = self.concat_files(files)[0]
# TODO request set the Date of last modif and Etag
return concat
css.exposed = True
def js(self, req, mods='base,base_hello'):
files = self.manifest_glob(mods.split(','), 'js')
concat = self.concat_files(files)[0]
# TODO request set the Date of last modif and Etag
return concat
js.exposed = True
@openerpweb.jsonrequest
def eval_domain_and_context(self, req, contexts, domains,
group_by_seq=None):
""" Evaluates sequences of domains and contexts, composing them into
a single context, domain or group_by sequence.
:param list contexts: list of contexts to merge together. Contexts are
evaluated in sequence, all previous contexts
are part of their own evaluation context
(starting at the session context).
:param list domains: list of domains to merge together. Domains are
evaluated in sequence and appended to one another
(implicit AND), their evaluation domain is the
result of merging all contexts.
:param list group_by_seq: list of domains (which may be in a different
order than the ``contexts`` parameter),
evaluated in sequence, their ``'group_by'``
key is extracted if they have one.
:returns:
a 3-dict of:
context (``dict``)
the global context created by merging all of
``contexts``
domain (``list``)
the concatenation of all domains
group_by (``list``)
a list of fields to group by, potentially empty (in which case
no group by should be performed)
"""
context = req.session.eval_contexts(contexts)
domain = req.session.eval_domains(domains, context)
group_by_sequence = []
for candidate in (group_by_seq or []):
ctx = req.session.eval_context(candidate, context)
group_by = ctx.get('group_by')
if not group_by:
continue
elif isinstance(group_by, basestring):
group_by_sequence.append(group_by)
else:
group_by_sequence.extend(group_by)
return {
'context': context,
'domain': domain,
'group_by': group_by_sequence
}
@openerpweb.jsonrequest
def save_session_action(self, req, the_action):
"""
This method store an action object in the session object and returns an integer
identifying that action. The method get_session_action() can be used to get
back the action.
:param the_action: The action to save in the session.
:type the_action: anything
:return: A key identifying the saved action.
:rtype: integer
"""
saved_actions = cherrypy.session.get('saved_actions')
if not saved_actions:
saved_actions = {"next":0, "actions":{}}
cherrypy.session['saved_actions'] = saved_actions
# we don't allow more than 10 stored actions
if len(saved_actions["actions"]) >= 10:
del saved_actions["actions"][min(saved_actions["actions"].keys())]
key = saved_actions["next"]
saved_actions["actions"][key] = the_action
saved_actions["next"] = key + 1
return key
@openerpweb.jsonrequest
def get_session_action(self, req, key):
"""
Gets back a previously saved action. This method can return None if the action
was saved since too much time (this case should be handled in a smart way).
:param key: The key given by save_session_action()
:type key: integer
:return: The saved action or None.
:rtype: anything
"""
saved_actions = cherrypy.session.get('saved_actions')
if not saved_actions:
return None
return saved_actions["actions"].get(key)
def load_actions_from_ir_values(req, key, key2, models, meta, context):
Values = req.session.model('ir.values')
actions = Values.get(key, key2, models, meta, context)
for _, _, action in actions:
clean_action(action, req.session)
return actions
def clean_action(action, session):
# values come from the server, we can just eval them
if isinstance(action['context'], basestring):
action['context'] = eval(
action['context'],
session.evaluation_context()) or {}
if isinstance(action['domain'], basestring):
action['domain'] = eval(
action['domain'],
session.evaluation_context(
action['context'])) or []
fix_view_modes(action)
def fix_view_modes(action):
""" For historical reasons, OpenERP has weird dealings in relation to
view_mode and the view_type attribute (on window actions):
* one of the view modes is ``tree``, which stands for both list views
and tree views
* the choice is made by checking ``view_type``, which is either
``form`` for a list view or ``tree`` for an actual tree view
This methods simply folds the view_type into view_mode by adding a
new view mode ``list`` which is the result of the ``tree`` view_mode
in conjunction with the ``form`` view_type.
TODO: this should go into the doc, some kind of "peculiarities" section
:param dict action: an action descriptor
:returns: nothing, the action is modified in place
"""
if action.pop('view_type') != 'form':
return
action['view_mode'] = ','.join(
mode if mode != 'tree' else 'list'
for mode in action['view_mode'].split(','))
action['views'] = [
[id, mode if mode != 'tree' else 'list']
for id, mode in action['views']
]
class Menu(openerpweb.Controller):
_cp_path = "/web_mobile/menu"
@openerpweb.jsonrequest
def load(self, req):
return {'data': self.do_load(req)}
def do_load(self, req):
""" Loads all menu items (all applications and their sub-menus).
:param req: A request object, with an OpenERP session attribute
:type req: < session -> OpenERPSession >
:return: the menu root
:rtype: dict('children': menu_nodes)
"""
Menus = req.session.model('ir.ui.menu')
# menus are loaded fully unlike a regular tree view, cause there are
# less than 512 items
menu_ids = Menus.search([])
menu_items = Menus.read(menu_ids, ['name', 'sequence', 'parent_id'])
menu_root = {'id': False, 'name': 'root', 'parent_id': [-1, '']}
menu_items.append(menu_root)
# make a tree using parent_id
menu_items_map = dict((menu_item["id"], menu_item) for menu_item in menu_items)
for menu_item in menu_items:
if menu_item['parent_id']:
parent = menu_item['parent_id'][0]
else:
parent = False
if parent in menu_items_map:
menu_items_map[parent].setdefault(
'children', []).append(menu_item)
# sort by sequence a tree using parent_id
for menu_item in menu_items:
menu_item.setdefault('children', []).sort(
key=lambda x:x["sequence"])
return menu_root
@openerpweb.jsonrequest
def action(self, req, menu_id):
actions = load_actions_from_ir_values(req,'action', 'tree_but_open',
[('ir.ui.menu', menu_id)], False, {})
return {"action": actions}
class DataSet(openerpweb.Controller):
_cp_path = "/web_mobile/dataset"
@ -536,14 +277,6 @@ class View(openerpweb.Controller):
openerpweb.nonliterals.Context(
session, context_string))
class FormView(View):
_cp_path = "/web_mobile/formview"
@openerpweb.jsonrequest
def load(self, req, model, view_id, toolbar=False):
fields_view = self.fields_view_get(req, model, view_id, 'form', toolbar=toolbar)
return {'fields_view': fields_view}
class ListView(View):
_cp_path = "/web_mobile/listview"
@ -624,26 +357,3 @@ class ListView(View):
elif len(color) == 1:
return color[0]
return 'maroon'
class SearchView(View):
_cp_path = "/web_mobile/searchview"
@openerpweb.jsonrequest
def load(self, req, model, view_id):
fields_view = self.fields_view_get(req, model, view_id, 'search')
return {'fields_view': fields_view}
class Action(openerpweb.Controller):
_cp_path = "/web_mobile/action"
@openerpweb.jsonrequest
def load(self, req, action_id, context={}):
Actions = req.session.model('ir.actions.actions')
value = False
action_type = Actions.read([action_id], ['type'], context)
if action_type:
action = req.session.model(action_type[0]['type']).read([action_id], False, context)
if action:
value = action[0]
return {'result': value}

View File

@ -37,7 +37,7 @@ openerp.web_mobile.MobileWebClient = openerp.base.Controller.extend({
this.login = login;
this.password = password;
var params = { db: this.db, login: this.login, password: this.password };
this.rpc("/web_mobile/mobile/login", params, function(result) {
this.rpc("/base/session/login", params, function(result) {
self.session_id = result.session_id;
self.uid = result.uid;
self.session_save();
@ -106,7 +106,7 @@ openerp.base.ListView = openerp.base.Controller.extend({
this.list_id = list_id;
},
start: function() {
this.rpc('/web_mobile/menu/action', {'menu_id': this.list_id},
this.rpc('/base/menu/action', {'menu_id': this.list_id},
this.on_menu_action_loaded);
},
on_menu_action_loaded: function(data) {
@ -180,7 +180,7 @@ openerp.base.Menu = openerp.base.Controller.extend({
this.menu = false;
},
start: function() {
this.rpc("/web_mobile/menu/load", {}, this.on_loaded);
this.rpc("/base/menu/load", {}, this.on_loaded);
},
on_loaded: function(data) {
this.data = data;

View File

@ -4,6 +4,8 @@
<meta charset="utf-8" />
<title>Login Page OpenERP mobile</title>
<link rel="stylesheet" href="/web_mobile/static/src/css/OpenERP.css" />
<script type="text/javascript" src="/base/static/lib/LABjs/LAB.js"></script>
<script type="text/javascript" src="/base/static/lib/jquery/jquery-1.5.2.js"></script>
<script type="text/javascript" src="/web_mobile/static/lib/jquery_mobile/jquery.mobile-1.0a4.1.js"></script>
<script type="text/javascript" src="/base/static/lib/jquery.ba-bbq/jquery.ba-bbq.js"></script>