Browse Source

publish muk_utils - 11.0

pull/6/head
MuK IT GmbH 6 years ago
parent
commit
973562b1e6
  1. 2
      muk_utils/__manifest__.py
  2. 137
      muk_utils/i18n/de.po
  3. 100
      muk_utils/i18n/muk_utils.pot
  4. 2
      muk_utils/models/res_groups.py
  5. 3
      muk_utils/tools/__init__.py
  6. 53
      muk_utils/tools/cache.py
  7. 57
      muk_utils/tools/file.py
  8. 45
      muk_utils/tools/json.py

2
muk_utils/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Utils", "name": "MuK Utils",
"summary": """Utility Features""", "summary": """Utility Features""",
"version": '11.0.1.0.14',
"version": '11.0.1.0.15',
"category": 'Extra Tools', "category": 'Extra Tools',
"license": "AGPL-3", "license": "AGPL-3",
"website": "https://www.mukit.at", "website": "https://www.mukit.at",

137
muk_utils/i18n/de.po

@ -4,105 +4,120 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Project-Id-Version: Odoo Server 11.0-20181126\n"
"Report-Msgid-Bugs-To: \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" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n" "Plural-Forms: \n"
"Language: de\n"
"X-Generator: Poedit 2.1.1\n"
#. module: muk_utils #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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 #. 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"

100
muk_utils/i18n/muk_utils.pot

@ -4,10 +4,10 @@
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Project-Id-Version: Odoo Server 11.0-20181126\n"
"Report-Msgid-Bugs-To: \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" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -16,93 +16,107 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""
#. module: muk_utils #. 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 "" msgstr ""

2
muk_utils/models/res_groups.py

@ -62,7 +62,7 @@ class ResGroups(models.Model):
model = self.env[model_name].sudo() model = self.env[model_name].sudo()
if not model._abstract: if not model._abstract:
model_recs[model_name] = model.search([['groups', 'in', self.mapped('id')]]) 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(): for tuple in model_recs.items():
tuple[1].trigger_computation(['users']) tuple[1].trigger_computation(['users'])
return result return result

3
muk_utils/tools/__init__.py

@ -21,3 +21,6 @@ from . import helper
from . import patch from . import patch
from . import parse_rst from . import parse_rst
from . import utils_os from . import utils_os
from . import cache
from . import file
from . import json

53
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 <http://www.gnu.org/licenses/>.
#
###################################################################################
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

57
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 <http://www.gnu.org/licenses/>.
#
###################################################################################
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

45
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 <http://www.gnu.org/licenses/>.
#
###################################################################################
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)
Loading…
Cancel
Save