OLD | NEW |
1 #This file is part of Tryton. The COPYRIGHT file at the top level of | 1 #This file is part of Tryton. The COPYRIGHT file at the top level of |
2 #this repository contains the full copyright notices and license terms. | 2 #this repository contains the full copyright notices and license terms. |
3 from __future__ import with_statement | 3 from __future__ import with_statement |
4 import contextlib | 4 import contextlib |
5 import base64 | 5 import base64 |
6 try: | 6 try: |
7 import cStringIO as StringIO | 7 import cStringIO as StringIO |
8 except ImportError: | 8 except ImportError: |
9 import StringIO | 9 import StringIO |
10 import zipfile | 10 import zipfile |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 model = fields.Function(fields.Char('Model'), 'get_model', | 58 model = fields.Function(fields.Char('Model'), 'get_model', |
59 searcher='search_model') | 59 searcher='search_model') |
60 | 60 |
61 def __init__(self): | 61 def __init__(self): |
62 super(Translation, self).__init__() | 62 super(Translation, self).__init__() |
63 self._sql_constraints += [ | 63 self._sql_constraints += [ |
64 ('translation_uniq', | 64 ('translation_uniq', |
65 'UNIQUE (name, res_id, lang, type, src, module)', | 65 'UNIQUE (name, res_id, lang, type, src, module)', |
66 'Translation must be unique'), | 66 'Translation must be unique'), |
67 ] | 67 ] |
| 68 self._constraints += [ |
| 69 ('check_unique_model', 'unique_model'), |
| 70 ] |
| 71 self._error_messages.update({ |
| 72 'unique_model': "Translation of type 'model' must be unique!", |
| 73 }) |
68 self._max_len = 10240 | 74 self._max_len = 10240 |
69 | 75 |
70 def init(self, module_name): | 76 def init(self, module_name): |
71 super(Translation, self).init(module_name) | 77 super(Translation, self).init(module_name) |
72 | 78 |
73 table = TableHandler(Transaction().cursor, self, module_name) | 79 table = TableHandler(Transaction().cursor, self, module_name) |
74 table.index_action(['lang', 'type', 'name'], 'add') | 80 table.index_action(['lang', 'type', 'name'], 'add') |
75 table.index_action(['lang', 'type', 'name', 'src'], 'add') | 81 table.index_action(['lang', 'type', 'name', 'src'], 'add') |
76 | 82 |
77 def default_fuzzy(self): | 83 def default_fuzzy(self): |
78 return False | 84 return False |
79 | 85 |
| 86 def check_unique_model(self, ids): |
| 87 "Check unique model" |
| 88 cursor = Transaction().cursor |
| 89 query = ('SELECT count(1) FROM "%s" ' |
| 90 'WHERE type = %%s ' |
| 91 'AND res_id != 0 ' |
| 92 'GROUP BY name, res_id, lang, type, src ' |
| 93 'HAVING count(1) > 1' % self._table) |
| 94 cursor.execute(query, ('model',)) |
| 95 rowcount = cursor.rowcount |
| 96 if rowcount == -1 or rowcount is None: |
| 97 rowcount = len(cursor.fetchall()) |
| 98 return not bool(rowcount) |
| 99 |
80 def get_model(self, ids, name): | 100 def get_model(self, ids, name): |
81 res = {} | 101 res = {} |
82 for translation in self.browse(ids): | 102 for translation in self.browse(ids): |
83 res[translation.id] = translation.name.split(',')[0] | 103 res[translation.id] = translation.name.split(',')[0] |
84 return res | 104 return res |
85 | 105 |
86 def search_model(self, name, clause): | 106 def search_model(self, name, clause): |
87 cursor = Transaction().cursor | 107 cursor = Transaction().cursor |
88 cursor.execute('SELECT id FROM "%s" ' | 108 cursor.execute('SELECT id FROM "%s" ' |
89 'WHERE split_part(name, \',\', 1) %s %%s' % | 109 'WHERE split_part(name, \',\', 1) %s %%s' % |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 for res_id in ids: | 181 for res_id in ids: |
162 if res_id not in translations: | 182 if res_id not in translations: |
163 self.add((lang, ttype, name, res_id), False) | 183 self.add((lang, ttype, name, res_id), False) |
164 translations[res_id] = False | 184 translations[res_id] = False |
165 return translations | 185 return translations |
166 | 186 |
167 def _set_ids(self, name, ttype, lang, ids, value): | 187 def _set_ids(self, name, ttype, lang, ids, value): |
168 model_fields_obj = self.pool.get('ir.model.field') | 188 model_fields_obj = self.pool.get('ir.model.field') |
169 model_obj = self.pool.get('ir.model') | 189 model_obj = self.pool.get('ir.model') |
170 | 190 |
| 191 if lang == 'en_US': |
| 192 return 0 |
| 193 |
171 model_name, field_name = name.split(',') | 194 model_name, field_name = name.split(',') |
172 if model_name in ('ir.model.field', 'ir.model'): | 195 if model_name in ('ir.model.field', 'ir.model'): |
173 if model_name == 'ir.model.field': | 196 if model_name == 'ir.model.field': |
174 if field_name == 'field_description': | 197 if field_name == 'field_description': |
175 ttype = 'field' | 198 ttype = 'field' |
176 else: | 199 else: |
177 ttype = 'help' | 200 ttype = 'help' |
178 records = model_fields_obj.browse(ids) | 201 records = model_fields_obj.browse(ids) |
179 else: | 202 else: |
180 ttype = 'model' | 203 ttype = 'model' |
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 'type': 'form', | 1171 'type': 'form', |
1149 'object': 'ir.translation.export.start', | 1172 'object': 'ir.translation.export.start', |
1150 'state': [ | 1173 'state': [ |
1151 ('end', 'Close', 'tryton-close'), | 1174 ('end', 'Close', 'tryton-close'), |
1152 ], | 1175 ], |
1153 }, | 1176 }, |
1154 }, | 1177 }, |
1155 } | 1178 } |
1156 | 1179 |
1157 TranslationExport() | 1180 TranslationExport() |
OLD | NEW |