Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(181)

Delta Between Two Patch Sets: flask_tryton.py

Issue 558820043: flask_tryton: Add support for 5.2 series (Closed)
Left Patch Set: Created 5 years, 10 months ago
Right Patch Set: Fix remarks Created 5 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « CHANGELOG ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of flask_tryton. The COPYRIGHT file at the top level of 1 # This file is part of flask_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 3
4 from functools import wraps 4 from functools import wraps
5 5
6 from flask import request, current_app 6 from flask import request, current_app
7 from werkzeug.routing import BaseConverter 7 from werkzeug.routing import BaseConverter
8 from werkzeug.exceptions import BadRequest 8 from werkzeug.exceptions import BadRequest
9 9
10 try: 10 try:
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 def instanciate(value): 86 def instanciate(value):
87 if isinstance(value, _BaseProxy): 87 if isinstance(value, _BaseProxy):
88 return value() 88 return value()
89 return value 89 return value
90 90
91 def decorator(func): 91 def decorator(func):
92 @wraps(func) 92 @wraps(func)
93 def wrapper(*args, **kwargs): 93 def wrapper(*args, **kwargs):
94 tryton = current_app.extensions['Tryton'] 94 tryton = current_app.extensions['Tryton']
95 database = current_app.config['TRYTON_DATABASE'] 95 database = current_app.config['TRYTON_DATABASE']
96 if trytond_version >= (5, 1): 96 if (5, 1) > trytond_version >= (3, 3):
97 with Transaction().start(database, 0) as transaction:
98 Cache.sync(transaction)
ced 2019/07/18 08:03:11 It is not needed the Cache is sync by the Transact
99 elif trytond_version >= (3, 3):
100 with Transaction().start(database, 0): 97 with Transaction().start(database, 0):
101 Cache.clean(database) 98 Cache.clean(database)
102 else: 99 elif trytond_version < (3, 3):
103 Cache.clean(database) 100 Cache.clean(database)
104 101
105 if user is None: 102 if user is None:
106 transaction_user = get_value( 103 transaction_user = get_value(
107 int(current_app.config['TRYTON_USER'])) 104 int(current_app.config['TRYTON_USER']))
108 else: 105 else:
109 transaction_user = get_value(user) 106 transaction_user = get_value(user)
110 107
111 if readonly is None: 108 if readonly is None:
112 is_readonly = get_value(tryton._readonly) 109 is_readonly = get_value(tryton._readonly)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 raise 141 raise
145 except Exception, e: 142 except Exception, e:
146 if hasattr(transaction, 'cursor'): 143 if hasattr(transaction, 'cursor'):
147 transaction.cursor.rollback() 144 transaction.cursor.rollback()
148 if isinstance(e, ( 145 if isinstance(e, (
149 UserError, 146 UserError,
150 UserWarning, 147 UserWarning,
151 ConcurrencyException)): 148 ConcurrencyException)):
152 raise BadRequest(e.message) 149 raise BadRequest(e.message)
153 raise 150 raise
154 if trytond_version >= (5, 1): 151 if (5, 1) > trytond_version >= (3, 3):
155 Cache.rollback(transaction)
ced 2019/07/18 08:03:11 We should not rollback the cache on succeed. Indee
156 elif trytond_version >= (3, 3):
157 Cache.resets(database) 152 Cache.resets(database)
153 if hasattr(transaction, 'tasks'):
154 from trytond.worker import run_task
155 while transaction.tasks:
156 task_id = transaction.tasks.pop()
157 run_task(tryton.pool, task_id)
158 if trytond_version < (3, 3): 158 if trytond_version < (3, 3):
159 Cache.resets(database) 159 Cache.resets(database)
160 return result 160 return result
161 return wrapper 161 return wrapper
162 return decorator 162 return decorator
163 163
164
164 tryton_transaction = Tryton.transaction 165 tryton_transaction = Tryton.transaction
165 166
166 167
167 class _BaseProxy(object): 168 class _BaseProxy(object):
168 pass 169 pass
169 170
170 171
171 class _RecordsProxy(_BaseProxy): 172 class _RecordsProxy(_BaseProxy):
172 def __init__(self, model, ids): 173 def __init__(self, model, ids):
173 self.model = model 174 self.model = model
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 219
219 def __init__(self, map, model): 220 def __init__(self, map, model):
220 super(RecordsConverter, self).__init__(map) 221 super(RecordsConverter, self).__init__(map)
221 self.model = model 222 self.model = model
222 223
223 def to_python(self, value): 224 def to_python(self, value):
224 return _RecordsProxy(self.model, map(int, value.split(','))) 225 return _RecordsProxy(self.model, map(int, value.split(',')))
225 226
226 def to_url(self, value): 227 def to_url(self, value):
227 return ','.join(map(int, value)) 228 return ','.join(map(int, value))
LEFTRIGHT
« CHANGELOG ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b