Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmis_field/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

{
"name": "Alfodoo CMIS Field",
"version": "16.0.1.0.0",
"version": "18.0.0.1",
"summary": "Specialized field to work with a CMIS server",
"category": "Document Management",
"author": "ACSONE SA/NV ",
"website": "https://alfodoo.org",
"license": "AGPL-3",
"depends": ["cmis"],
"data": ["views/cmis_backend_view.xml"],
"installable": False,
"installable": True,
"images": [
"static/description/main_icon.png",
],
Expand Down
17 changes: 10 additions & 7 deletions cmis_field/fields/cmis_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

from cmislib.exceptions import ObjectNotFoundException

from odoo import SUPERUSER_ID, _, api, fields, registry
from odoo import SUPERUSER_ID, api, fields
from odoo.exceptions import UserError
from odoo.modules.registry import Registry
from odoo.tools.sql import pg_varchar

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -105,16 +106,18 @@ def _description_backend(self, env):
# into the list.
backend = backend[:1]
else:
msg = _("Too many backend found. " "Please check your configuration.")
msg = self.env._("Too many backend found. " "Please check your configuration.")
return {"backend_error": msg}
if not backend:
if self.backend_name:
msg = (
_("Backend named %s not found. " "Please check your configuration.")
% self.backend_name
self.env._(
"Backend named %s not found. " "Please check your configuration.",
self.backend_name
)
)
else:
msg = _("No backend found. Please check your configuration.")
msg = self.env._("No backend found. Please check your configuration.")
return {"backend_error": msg}
return backend.get_web_description()[backend.id]

Expand Down Expand Up @@ -172,7 +175,7 @@ def _create_in_cmis(self, records, backend):
value = repo.createFolder(parent, name, props)

def clean_up_folder(cmis_object_id, backend_id, dbname):
db_registry = registry(dbname)
db_registry = Registry(dbname)
with db_registry.cursor() as cr:
env = api.Environment(cr, SUPERUSER_ID, {})
backend = env["cmis.backend"].browse(backend_id)
Expand Down Expand Up @@ -203,7 +206,7 @@ def clean_up_folder(cmis_object_id, backend_id, dbname):
def _check_null(self, record, raise_exception=True):
val = self.__get__(record, record)
if val and raise_exception:
raise UserError(_("A value is already assigned to %s") % self)
raise UserError(self.env._("A value is already assigned to %s", self))
return val

def get_create_names(self, records, backend):
Expand Down
29 changes: 16 additions & 13 deletions cmis_field/models/cmis_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ def _check_sanitize_replace_char(self):
rc = rec.sanitize_replace_char
if rc and re.findall(CMIS_NAME_INVALID_CHARS_RX, rc):
raise ValidationError(
_("The character to use as replacement can not be one of" "'%s'")
% CMIS_NAME_INVALID_CHARS
_(
"The character to use as replacement can not be one of" "'%s'",
CMIS_NAME_INVALID_CHARS,
)
)

enable_sanitize_cmis_name = fields.Boolean(
Expand Down Expand Up @@ -72,12 +74,13 @@ def get_by_name(self, name, raise_if_not_found=True):
backend = self.search(domain)
if len(backend) != 1 and raise_if_not_found:
if name:
msg = _("Expected 1 backend named %(name)s, %(number)s found") % {
"name": name,
"number": len(backend),
}
msg = self.env._(
"Expected 1 backend named %(name)s, %(number)s found",
name=name,
number=len(backend),
)
else:
msg = _("No backend found")
msg = self.env._("No backend found")
raise UserError(msg)
return backend

Expand All @@ -92,7 +95,7 @@ def is_valid_cmis_name(self, name, raise_if_invalid=False):
if not raise_if_invalid:
return False
raise UserError(
_(
self.env._(
"%(name)s is not a valid name.\n"
"The following chars are not allowed %(invalid_chars)s and"
"the name can not ends with a space or a '.'"
Expand Down Expand Up @@ -145,20 +148,20 @@ def get_unique_folder_name(self, name, parent, conflict_handler=None):
conflict_handler = conflict_handler or self.folder_name_conflict_handler
cmis_qry = (
"SELECT cmis:objectId FROM cmis:folder WHERE "
"IN_FOLDER('%s') AND cmis:name='%s'"
% (parent.getObjectId(), name.replace("'", "\\'"))
"IN_FOLDER('%s') AND cmis:name='%s'",
[parent.getObjectId(), name.replace("'", "\\'")]
)
rs = parent.repository.query(cmis_qry)
num_found_items = rs.getNumItems()
if num_found_items > 0:
if conflict_handler == "error":
raise ValidationError(_('Folder "%s" already exists in CMIS') % (name))
raise ValidationError(_('Folder "%s" already exists in CMIS', name))
if conflict_handler == "increment":
testname = name + "_(%)"
cmis_qry = (
"SELECT * FROM cmis:folder WHERE "
"IN_FOLDER('%s') AND cmis:name like '%s'"
% (parent.getObjectId(), testname.replace("'", "\\'"))
"IN_FOLDER('%s') AND cmis:name like '%s'",
[parent.getObjectId(), testname.replace("'", "\\'")]
)
rs = parent.repository.query(cmis_qry)
names = [r.name for r in rs]
Expand Down
2 changes: 1 addition & 1 deletion cmis_field/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUpClass(cls):
cls.cmis_backend.initial_directory_write = "/odoo"

def setUp(self):
super(BaseTestCmis, self).setUp()
super().setUp()

# global patch

Expand Down
2 changes: 1 addition & 1 deletion cmis_field/tests/test_cmis_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class TestCmisBackend(common.TransactionCase):
def setUp(self):
super(TestCmisBackend, self).setUp()
super().setUp()
self.cmis_backend = self.env["cmis.backend"]
self.backend_instance = self.env.ref("cmis.cmis_backend_alfresco")

Expand Down
2 changes: 1 addition & 1 deletion cmis_field/tests/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def mock_http_request_env(env):
class TestCmisController(common.BaseTestCmis):
@classmethod
def setUpClass(cls):
super(TestCmisController, cls).setUpClass()
super().setUpClass()
cls.cmis_test_model_inst = cls.env["cmis.test.model"].create(
{"name": "folder_name"}
)
Expand Down
14 changes: 5 additions & 9 deletions cmis_field/views/cmis_backend_view.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="cmis_backend_form_view" model="ir.ui.view">
<field name="name">cmis.backend.form (cmis_field)</field>
<field name="model">cmis.backend</field>
<field name="inherit_id" ref="cmis.cmis_backend_form_view" />
<field name="inherit_id" ref="cmis.cmis_backend_form_view"/>
<field name="arch" type="xml">
<group name="cmis_left" position="inside">
<field name="enable_sanitize_cmis_name" />
<field name="enable_sanitize_cmis_name"/>
</group>
<group name="cmis_right" position="inside">
<field
name="sanitize_replace_char"
attrs="{'invisible': [('enable_sanitize_cmis_name', '=', False)]}"
/>
<field name="folder_name_conflict_handler" />
<field name="sanitize_replace_char" invisible="enable_sanitize_cmis_name == False"/>
<field name="folder_name_conflict_handler"/>
</group>
</field>
</record>

</odoo>
</odoo>