From 97c0f772513f4e0fe8f7abe69f4f973d129c80cf Mon Sep 17 00:00:00 2001 From: Korbinian Preisler Date: Tue, 12 May 2009 16:14:48 +0200 Subject: [PATCH] add cache on ir.lang for issue 1025 --- trytond/ir/lang.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/trytond/ir/lang.py b/trytond/ir/lang.py index 2e10cea10f..e05bfd460a 100644 --- a/trytond/ir/lang.py +++ b/trytond/ir/lang.py @@ -1,10 +1,11 @@ #This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. "Lang" from trytond.model import ModelView, ModelSQL, fields +from trytond.model.cacheable import Cacheable import time -class Lang(ModelSQL, ModelView): +class Lang(ModelSQL, ModelView, Cacheable): "Language" _name = "ir.lang" _description = __doc__ @@ -103,6 +104,36 @@ class Lang(ModelSQL, ModelView): def check_xml_record(self, cursor, user, ids, values, context=None): return True + def get_translatable_languages(self, cursor, user, context=None): + if not self.get(cursor, 'translatable_languages'): + lang_ids = self.search(cursor, user, [ + ('translatable', '=', True), + ], context=context) + self.add(cursor, 'translatable_languages', [x.code for x in \ + self.browse(cursor, user, lang_ids, context=context)]) + return self.get(cursor, 'translatable_languages') + + def create(self, cursor, user, vals, context=None): + # Clear cache + if self.get(cursor, 'translatable_languages'): + self.invalidate(cursor, 'translatable_languages') + return super(Lang, self).create(cursor, user, vals, + context=context) + + def write(self, cursor, user, ids, vals, context=None): + # Clear cache + if self.get(cursor, 'translatable_languages'): + self.invalidate(cursor, 'translatable_languages') + return super(Lang, self).write(cursor, user, ids, vals, + context=context) + + def delete(self, cursor, user, ids, context=None): + # Clear cache + if self.get(cursor, 'translatable_languages'): + self.invalidate(cursor, 'translatable_languages') + return super(Lang, self).delete(cursor, user, ids, + context=context) + def _group(self, lang, s, monetary=False): # Code from _group in locale.py if monetary: