From 973562b1e6260f69c8d42d66f24b2cda23e56f15 Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Mon, 10 Dec 2018 13:35:13 +0000 Subject: [PATCH] publish muk_utils - 11.0 --- muk_utils/__manifest__.py | 2 +- muk_utils/i18n/de.po | 139 ++++++++++++++++++--------------- muk_utils/i18n/muk_utils.pot | 100 ++++++++++++++---------- muk_utils/models/res_groups.py | 4 +- muk_utils/tools/__init__.py | 5 +- muk_utils/tools/cache.py | 53 +++++++++++++ muk_utils/tools/file.py | 57 ++++++++++++++ muk_utils/tools/json.py | 45 +++++++++++ 8 files changed, 296 insertions(+), 109 deletions(-) create mode 100644 muk_utils/tools/cache.py create mode 100644 muk_utils/tools/file.py create mode 100644 muk_utils/tools/json.py diff --git a/muk_utils/__manifest__.py b/muk_utils/__manifest__.py index bd4ccdb..bade4e6 100644 --- a/muk_utils/__manifest__.py +++ b/muk_utils/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Utils", "summary": """Utility Features""", - "version": '11.0.1.0.14', + "version": '11.0.1.0.15', "category": 'Extra Tools', "license": "AGPL-3", "website": "https://www.mukit.at", diff --git a/muk_utils/i18n/de.po b/muk_utils/i18n/de.po index d8b517e..d56e5a1 100644 --- a/muk_utils/i18n/de.po +++ b/muk_utils/i18n/de.po @@ -1,108 +1,123 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * muk_utils +# * muk_utils # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 11.0\n" +"Project-Id-Version: Odoo Server 11.0-20181126\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-06-07 14:50+0000\n" -"PO-Revision-Date: 2018-06-07 14:50+0000\n" +"POT-Creation-Date: 2018-12-10 12:59+0000\n" +"PO-Revision-Date: 2018-12-10 14:12+0100\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: \n" +"Content-Transfer-Encoding: 8bit\n" "Plural-Forms: \n" +"Language: de\n" +"X-Generator: Poedit 2.1.1\n" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_create_uid -msgid "Created by" -msgstr "Erstellt von" +#: model:ir.model,name:muk_utils.model_res_groups +msgid "Access Groups" +msgstr "Berechtigungsgruppen" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_create_date -msgid "Created on" -msgstr "Erstellt am" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_child_groups +msgid "Child Groups" +msgstr "Geerbte Gruppen" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_base_display_name -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_display_name -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_locking_display_name -msgid "Display Name" -msgstr "Anzeigename" +#: model:ir.actions.server,name:muk_utils.cron_utils_update_groups_ir_actions_server +#: model:ir.cron,cron_name:muk_utils.cron_utils_update_groups +#: model:ir.cron,name:muk_utils.cron_utils_update_groups +msgid "Cron job to update the Groups" +msgstr "Cron-Job zum aktualisieren der Gruppen" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_base_id -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_id -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_locking_id -msgid "ID" -msgstr "ID" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_departments +msgid "Departments" +msgstr "Abteilungen" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_base___last_update -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock___last_update -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_locking___last_update -msgid "Last Modified on" -msgstr "Zuletzt geändert am" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_display_name +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_model_display_name +msgid "Display Name" +msgstr "Anzeigename" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_write_uid -msgid "Last Updated by" -msgstr "Zuletzt aktualisiert durch" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_explicit_users +msgid "Explicit Users" +msgstr "Zusätzliche Benutzer" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_write_date -msgid "Last Updated on" -msgstr "Zuletzt aktualisiert am" +#: model:ir.model.fields,field_description:muk_utils.field_muk_quality_docs_groups_name +#: model:ir.model.fields,field_description:muk_utils.field_muk_security_groups_name +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_name +msgid "Group Name" +msgstr "Gruppenname" #. module: muk_utils -#: model:ir.model,name:muk_utils.model_muk_utils_lock -msgid "Lock" -msgstr "Lock" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_groups +msgid "Groups" +msgstr "Gruppen" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_locked_by -msgid "Locked by" -msgstr "Locked by" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_id +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_model_id +msgid "ID" +msgstr "ID" #. module: muk_utils -#: model:ir.model,name:muk_utils.model_muk_utils_base -msgid "MuK Base Model" -msgstr "MuK Base Model" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_jobs +msgid "Jobs" +msgstr "Stellen" #. module: muk_utils -#: model:ir.model,name:muk_utils.model_muk_utils_locking -msgid "MuK Locking Model" -msgstr "MuK Locking Model" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups___last_update +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_model___last_update +msgid "Last Modified on" +msgstr "Zuletzt geändert am" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_name -msgid "Name" -msgstr "Name" +#: model:ir.model.fields,field_description:muk_utils.field_muk_quality_docs_groups_parent_left +#: model:ir.model.fields,field_description:muk_utils.field_muk_security_groups_parent_left +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_parent_left +msgid "Left Parent" +msgstr "Left Parent" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_lock_ref -msgid "Object Reference" -msgstr "Object Reference" +#: model:ir.model,name:muk_utils.model_muk_utils_model +msgid "MuK Base Model" +msgstr "MuK Base Model" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_operation -msgid "Operation" -msgstr "Operation" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_parent_group +msgid "Parent Group" +msgstr "Übergeordnete Gruppe" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_token -msgid "Token" -msgstr "Token" +#: model:ir.model.fields,field_description:muk_utils.field_muk_quality_docs_groups_parent_right +#: model:ir.model.fields,field_description:muk_utils.field_muk_security_groups_parent_right +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_parent_right +msgid "Right Parent" +msgstr "Right Parent" #. module: muk_utils -#: selection:muk_utils.lock,locked_by_ref:0 -msgid "User" -msgstr "User" +#: sql_constraint:muk_utils.groups:0 +msgid "The name of the group must be unique!" +msgstr "Der Gruppenname muss eindeutig sein!" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_locked_by_ref -msgid "User Reference" -msgstr "User Reference" +#: model:ir.model,name:muk_utils.model_res_users +#: model:ir.model.fields,field_description:muk_utils.field_muk_quality_docs_groups_count_users +#: model:ir.model.fields,field_description:muk_utils.field_muk_security_groups_count_users +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_count_users +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_users +msgid "Users" +msgstr "Benutzer" +#. module: muk_utils +#: model:ir.model,name:muk_utils.model_muk_utils_groups +msgid "muk_utils.groups" +msgstr "muk_utils.groups" diff --git a/muk_utils/i18n/muk_utils.pot b/muk_utils/i18n/muk_utils.pot index bacbfb9..b0b70a7 100644 --- a/muk_utils/i18n/muk_utils.pot +++ b/muk_utils/i18n/muk_utils.pot @@ -4,10 +4,10 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 11.0\n" +"Project-Id-Version: Odoo Server 11.0-20181126\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-06-07 14:50+0000\n" -"PO-Revision-Date: 2018-06-07 14:50+0000\n" +"POT-Creation-Date: 2018-12-10 12:57+0000\n" +"PO-Revision-Date: 2018-12-10 12:57+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -16,93 +16,107 @@ msgstr "" "Plural-Forms: \n" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_create_uid -msgid "Created by" +#: model:ir.model,name:muk_utils.model_res_groups +msgid "Access Groups" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_create_date -msgid "Created on" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_child_groups +msgid "Child Groups" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_base_display_name -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_display_name -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_locking_display_name -msgid "Display Name" +#: model:ir.actions.server,name:muk_utils.cron_utils_update_groups_ir_actions_server +#: model:ir.cron,cron_name:muk_utils.cron_utils_update_groups +#: model:ir.cron,name:muk_utils.cron_utils_update_groups +msgid "Cron job to update the Groups" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_base_id -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_id -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_locking_id -msgid "ID" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_departments +msgid "Departments" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_base___last_update -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock___last_update -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_locking___last_update -msgid "Last Modified on" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_display_name +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_model_display_name +msgid "Display Name" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_write_uid -msgid "Last Updated by" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_explicit_users +msgid "Explicit Users" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_write_date -msgid "Last Updated on" +#: model:ir.model.fields,field_description:muk_utils.field_muk_quality_docs_groups_name +#: model:ir.model.fields,field_description:muk_utils.field_muk_security_groups_name +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_name +msgid "Group Name" msgstr "" #. module: muk_utils -#: model:ir.model,name:muk_utils.model_muk_utils_lock -msgid "Lock" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_groups +msgid "Groups" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_locked_by -msgid "Locked by" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_id +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_model_id +msgid "ID" msgstr "" #. module: muk_utils -#: model:ir.model,name:muk_utils.model_muk_utils_base -msgid "MuK Base Model" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_jobs +msgid "Jobs" msgstr "" #. module: muk_utils -#: model:ir.model,name:muk_utils.model_muk_utils_locking -msgid "MuK Locking Model" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups___last_update +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_model___last_update +msgid "Last Modified on" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_name -msgid "Name" +#: model:ir.model.fields,field_description:muk_utils.field_muk_quality_docs_groups_parent_left +#: model:ir.model.fields,field_description:muk_utils.field_muk_security_groups_parent_left +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_parent_left +msgid "Left Parent" +msgstr "" + +#. module: muk_utils +#: model:ir.model,name:muk_utils.model_muk_utils_model +msgid "MuK Base Model" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_lock_ref -msgid "Object Reference" +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_parent_group +msgid "Parent Group" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_operation -msgid "Operation" +#: model:ir.model.fields,field_description:muk_utils.field_muk_quality_docs_groups_parent_right +#: model:ir.model.fields,field_description:muk_utils.field_muk_security_groups_parent_right +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_parent_right +msgid "Right Parent" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_token -msgid "Token" +#: sql_constraint:muk_utils.groups:0 +msgid "The name of the group must be unique!" msgstr "" #. module: muk_utils -#: selection:muk_utils.lock,locked_by_ref:0 -msgid "User" +#: model:ir.model,name:muk_utils.model_res_users +#: model:ir.model.fields,field_description:muk_utils.field_muk_quality_docs_groups_count_users +#: model:ir.model.fields,field_description:muk_utils.field_muk_security_groups_count_users +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_count_users +#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_groups_users +msgid "Users" msgstr "" #. module: muk_utils -#: model:ir.model.fields,field_description:muk_utils.field_muk_utils_lock_locked_by_ref -msgid "User Reference" +#: model:ir.model,name:muk_utils.model_muk_utils_groups +msgid "muk_utils.groups" msgstr "" diff --git a/muk_utils/models/res_groups.py b/muk_utils/models/res_groups.py index e539a94..32298ac 100644 --- a/muk_utils/models/res_groups.py +++ b/muk_utils/models/res_groups.py @@ -62,7 +62,7 @@ class ResGroups(models.Model): model = self.env[model_name].sudo() if not model._abstract: model_recs[model_name] = model.search([['groups', 'in', self.mapped('id')]]) - result = super(ResGroups, self).unlink() + result = super(ResGroups, self).unlink(vals) for tuple in model_recs.items(): tuple[1].trigger_computation(['users']) - return result + return result \ No newline at end of file diff --git a/muk_utils/tools/__init__.py b/muk_utils/tools/__init__.py index 13a4a72..a847dfb 100644 --- a/muk_utils/tools/__init__.py +++ b/muk_utils/tools/__init__.py @@ -20,4 +20,7 @@ from . import helper from . import patch from . import parse_rst -from . import utils_os \ No newline at end of file +from . import utils_os +from . import cache +from . import file +from . import json \ No newline at end of file diff --git a/muk_utils/tools/cache.py b/muk_utils/tools/cache.py new file mode 100644 index 0000000..a68cab3 --- /dev/null +++ b/muk_utils/tools/cache.py @@ -0,0 +1,53 @@ +################################################################################### +# +# Copyright (C) 2018 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +import time + +class memoize(object): + _caches = {} + _timeouts = {} + + def __init__(self, timeout=2): + self.timeout = timeout + + def collect(self): + for func in self._caches: + cleaned_cache = {} + current_time = time.time() + for key in self._caches[func]: + if (current_time - self._caches[func][key][1]) < self._timeouts[func]: + cleaned_cache[key] = self._caches[func][key] + self._caches[func] = cleaned_cache + + def __call__(self, func): + self.cache = self._caches[func] = {} + self._timeouts[func] = self.timeout + def wrapper(*args, **kwargs): + current_time = time.time() + kw = sorted(kwargs.items()) + key = (args, tuple(kw)) + try: + value = self.cache[key] + if (current_time - value[1]) > self.timeout: + raise KeyError + except KeyError: + value = self.cache[key] = (func(*args,**kwargs), current_time) + return value[0] + wrapper.func_name = func.__name__ + return wrapper \ No newline at end of file diff --git a/muk_utils/tools/file.py b/muk_utils/tools/file.py new file mode 100644 index 0000000..0ba24db --- /dev/null +++ b/muk_utils/tools/file.py @@ -0,0 +1,57 @@ +################################################################################### +# +# Copyright (C) 2018 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +import os +import io +import base64 +import shutil +import urllib +import logging +import tempfile +import mimetypes + +from odoo.tools.mimetypes import guess_mimetype + +_logger = logging.getLogger(__name__) + +def unique_name(name, names, escape_suffix=False): + def compute_name(name, suffix, escape_suffix): + if escape_suffix: + name, extension = os.path.splitext(name) + return "%s(%s)%s" % (name, suffix, extension) + else: + return "%s(%s)" % (name, suffix) + if not name in names: + return name + else: + suffix = 1 + name = compute_name(name, suffix, escape_suffix) + while name in names: + suffix += 1 + name = compute_name(name, suffix, escape_suffix) + return name + +def guess_extension(filename=None, mimetype=None, binary=None): + extension = filename and os.path.splitext(filename)[1][1:].strip().lower() + if not extension and mimetype: + extension = mimetypes.guess_extension(mimetype)[1:].strip().lower() + if not extension and binary: + mimetype = guess_mimetype(binary, default="") + extension = mimetypes.guess_extension(mimetype)[1:].strip().lower() + return extension \ No newline at end of file diff --git a/muk_utils/tools/json.py b/muk_utils/tools/json.py new file mode 100644 index 0000000..7ca8c21 --- /dev/null +++ b/muk_utils/tools/json.py @@ -0,0 +1,45 @@ +################################################################################### +# +# Copyright (C) 2018 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +import json +import logging +import datetime + +from odoo import models, tools + +_logger = logging.getLogger(__name__) + +class ResponseEncoder(json.JSONEncoder): + + def default(self, obj): + if isinstance(obj, datetime.date): + return obj.strftime(tools.DEFAULT_SERVER_DATE_FORMAT) + if isinstance(obj, datetime.datetime): + return obj.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) + if isinstance(obj, (bytes, bytearray)): + return obj.decode() + return json.JSONEncoder.default(self, obj) + +class RecordEncoder(ResponseEncoder): + + def default(self, obj): + if isinstance(obj, models.BaseModel): + return obj.name_get() + return ResponseEncoder.default(self, obj) + \ No newline at end of file