Skip to content

Commit

Permalink
Fix controller: The response is wrapped by the decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
lmignon committed Sep 5, 2016
1 parent 9edc5de commit f8912b8
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 12 deletions.
8 changes: 1 addition & 7 deletions cmis/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
# -*- coding: utf-8 -*-
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
import json
import werkzeug
from openerp import http
from openerp.addons.web.controllers import main


class CmisController(http.Controller):

@http.route('/web/cmis/field/create_value', type='json', methods=['POST'],
auth="user")
@main.serialize_exception
def create_field_value(self, model_name, res_id, field_name):
model_inst = http.request.env[model_name].browse(int(res_id))
model_inst._fields[field_name].create_value(model_inst)
value = getattr(model_inst, field_name)
response = werkzeug.Response(json.dumps(
{'value': value}), mimetype='application/json')
return response
return {'value': value}
2 changes: 1 addition & 1 deletion cmis/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _create_in_cmis(self, records, backend):
for record in records:
name = names[record.id]
parent = parents[record.id]
props = properties[record.id]
props = properties[record.id] or {}
value = repo.createFolder(
parent, name, props)
self.__set__(record, value.getObjectId())
Expand Down
2 changes: 1 addition & 1 deletion cmis/models/cmis_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def write(self, vals):
self._clear_caches()
return super(CmisBackend, self).write(vals)

@tools.cache()
@api.multi
@tools.cache()
def get_cmis_client(self):
"""
Get an initialized CmisClient for the using the CMISBrowserBinding
Expand Down
3 changes: 1 addition & 2 deletions cmis/tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ def test_init_field_value(self):
val = controller.create_field_value(
self.cmis_test_model_inst._name, self.cmis_test_model_inst.id,
'cmis_folder2')
self.assertEquals(val.status_code, 200)
self.assertEquals(val.data, '{"value": "_create_method"}')
self.assertDictEqual(val, {"value": "_create_method"})
2 changes: 1 addition & 1 deletion cmis/tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_cmis_folder_default_create(self):
# the one returned by the name_get method on the record and the
# parent directory, the one returned by the method getObjectByPath
mocked_cmis_repository.createFolder.assert_called_once_with(
'root_id', 'folder_name', None)
'root_id', 'folder_name', {})
# a second call to the create_value must raise a UserError since
# the value is already initialized
with self.assertRaises(UserError):
Expand Down

0 comments on commit f8912b8

Please sign in to comment.