Rename context_get to get_context

issue5965
review25751002
This commit is contained in:
Xavier Codinas 2016-12-15 10:29:45 +01:00
parent 7212652281
commit 988c41a682
10 changed files with 47 additions and 47 deletions

View file

@ -41,7 +41,7 @@ def update_completion(entry, record, field, model, domain=None):
return False
if domain is None:
domain = field.domain_get(record)
context = field.context_get(record)
context = field.get_context(record)
domain = [('rec_name', 'ilike', '%' + search_text + '%'), domain]
def callback(results):

View file

@ -61,7 +61,7 @@ class SelectionMixin(object):
self.init_selection(value)
self.filter_selection(domain, record, field)
else:
context = field.context_get(record)
context = field.get_context(record)
domain_cache_key = (freeze_value(domain), freeze_value(context))
if domain_cache_key in self._domain_cache:
self.selection = self._domain_cache[domain_cache_key]

View file

@ -58,10 +58,10 @@ class Field(object):
def validation_domains(self, record, pre_validate=None):
return concat(*self.domains_get(record, pre_validate))
def context_get(self, record):
context = record.context_get().copy()
def get_context(self, record):
context = record.get_context().copy()
if record.parent:
context.update(record.parent.context_get())
context.update(record.parent.get_context())
context.update(record.expr_eval(self.attrs.get('context', {})))
return context
@ -229,7 +229,7 @@ class DateTimeField(Field):
return common.timezoned_date(value)
def date_format(self, record):
context = self.context_get(record)
context = self.get_context(record)
return context.get('date_format', '%x')
def time_format(self, record):
@ -248,7 +248,7 @@ class DateField(Field):
force_change=force_change)
def date_format(self, record):
context = self.context_get(record)
context = self.get_context(record)
return context.get('date_format', '%x')
@ -427,8 +427,8 @@ class M2OField(Field):
record.value[self.name + '.rec_name'] = rec_name
record.value[self.name] = value
def context_get(self, record):
context = super(M2OField, self).context_get(record)
def get_context(self, record):
context = super(M2OField, self).get_context(record)
if self.attrs.get('datetime_field'):
context['_datetime'] = record.get_eval(
)[self.attrs.get('datetime_field')]
@ -591,7 +591,7 @@ class O2MField(Field):
mode = 'list values'
if mode == 'list values':
context = self.context_get(record)
context = self.get_context(record)
field_names = set(f for v in value for f in v
if f not in group.fields and '.' not in f)
if field_names:
@ -676,7 +676,7 @@ class O2MField(Field):
return
if value and (value.get('add') or value.get('update')):
context = self.context_get(record)
context = self.get_context(record)
fields = record.value[self.name].fields
values = chain(value.get('update', []),
(d for _, d in value.get('add', [])))
@ -837,8 +837,8 @@ class ReferenceField(Field):
record.value[self.name] = ref_model, ref_id
record.value[self.name + '.rec_name'] = rec_name
def context_get(self, record):
context = super(ReferenceField, self).context_get(record)
def get_context(self, record):
context = super(ReferenceField, self).get_context(record)
if self.attrs.get('datetime_field'):
context['_datetime'] = record.get_eval(
)[self.attrs.get('datetime_field')]
@ -912,7 +912,7 @@ class BinaryField(Field):
(basestring, bytes, bytearray)):
if record.id < 0:
return ''
context = record.context_get()
context = record.get_context()
try:
values, = RPCExecute('model', record.model_name, 'read',
[record.id], [self.name], context=context)
@ -945,7 +945,7 @@ class DictField(Field):
attr_domain)
def date_format(self, record):
context = self.context_get(record)
context = self.get_context(record)
return context.get('date_format', '%x')
def time_format(self, record):

View file

@ -247,10 +247,10 @@ class Group(SignalEvent, list):
def context(self):
ctx = self._context.copy()
if self.parent:
ctx.update(self.parent.context_get())
ctx.update(self.parent.get_context())
if self.child_name in self.parent.group.fields:
field = self.parent.group.fields[self.child_name]
ctx.update(field.context_get(self.parent))
ctx.update(field.get_context(self.parent))
ctx.update(self._context)
if self.parent_datetime_field:
ctx['_datetime'] = self.parent.get_eval(

View file

@ -72,7 +72,7 @@ class Record(SignalEvent):
fnames.append('rec_name')
fnames.append('_timestamp')
record_context = self.context_get()
record_context = self.get_context()
if loading == 'eager':
limit = int(CONFIG['client.limit'] / len(fnames))
@ -84,7 +84,7 @@ class Record(SignalEvent):
and record.id not in id2record
and ((record.group == self.group)
# Don't compute context for same group
or (record.context_get() == record_context)))
or (record.get_context() == record_context)))
if self.parent and self.parent.model_name == self.model_name:
group = sum(self.parent.group.children, [])
@ -299,7 +299,7 @@ class Record(SignalEvent):
values = self._get_on_change_args(self.modified_fields)
try:
RPCExecute('model', self.model_name, 'pre_validate', values,
context=self.context_get())
context=self.get_context())
except RPCException:
return False
return True
@ -310,7 +310,7 @@ class Record(SignalEvent):
value = self.get()
try:
res, = RPCExecute('model', self.model_name, 'create',
[value], context=self.context_get())
[value], context=self.get_context())
except RPCException:
return False
old_id = self.id
@ -319,7 +319,7 @@ class Record(SignalEvent):
elif self.modified:
value = self.get()
if value:
context = self.context_get()
context = self.get_context()
context = context.copy()
context['_timestamp'] = self.get_timestamp()
try:
@ -365,7 +365,7 @@ class Record(SignalEvent):
def default_get(self, rec_name=None):
if len(self.group.fields):
context = self.context_get()
context = self.get_context()
context.setdefault('default_rec_name', rec_name)
try:
vals = RPCExecute('model', self.model_name, 'default_get',
@ -391,7 +391,7 @@ class Record(SignalEvent):
def rec_name(self):
try:
return RPCExecute('model', self.model_name, 'read', [self.id],
['rec_name'], context=self.context_get())[0]['rec_name']
['rec_name'], context=self.get_context())[0]['rec_name']
except RPCException:
return ''
@ -422,7 +422,7 @@ class Record(SignalEvent):
invalid_fields = property(_get_invalid_fields)
def context_get(self):
def get_context(self):
return self.group.context
def set_default(self, val, signal=True, validate=True):
@ -514,7 +514,7 @@ class Record(SignalEvent):
return expr
ctx = rpc.CONTEXT.copy()
ctx['context'] = ctx.copy()
ctx['context'].update(self.context_get())
ctx['context'].update(self.get_context())
ctx.update(self.get_eval())
ctx['active_model'] = self.model_name
ctx['active_id'] = self.id
@ -550,7 +550,7 @@ class Record(SignalEvent):
if values:
try:
changes = RPCExecute('model', self.model_name, 'on_change',
values, fieldnames, context=self.context_get())
values, fieldnames, context=self.get_context())
except RPCException:
return
for change in changes:
@ -581,7 +581,7 @@ class Record(SignalEvent):
if fieldnames:
try:
result = RPCExecute('model', self.model_name, 'on_change_with',
values, list(fieldnames), context=self.context_get())
values, list(fieldnames), context=self.get_context())
except RPCException:
return
self.set_on_change(result)
@ -592,7 +592,7 @@ class Record(SignalEvent):
try:
result = RPCExecute('model', self.model_name,
'on_change_with_' + fieldname, values,
context=self.context_get())
context=self.get_context())
except RPCException:
return
self.group.fields[fieldname].set_on_change(self, result)
@ -610,7 +610,7 @@ class Record(SignalEvent):
args = self._get_on_change_args(autocomplete)
try:
res = RPCExecute('model', self.model_name, 'autocomplete_' +
fieldname, args, context=self.context_get())
fieldname, args, context=self.get_context())
except RPCException:
# ensure res is a list
res = []
@ -635,7 +635,7 @@ class Record(SignalEvent):
'search_count', [
('resource', '=',
'%s,%s' % (self.model_name, self.id)),
], context=self.context_get())
], context=self.get_context())
except RPCException:
return 0
return self.attachment_count
@ -650,7 +650,7 @@ class Record(SignalEvent):
('resource', '=',
'%s,%s' % (self.model_name, self.id)),
('unread', '=', True),
], context=self.context_get())
], context=self.get_context())
except RPCException:
return 0
return self.unread_note

View file

@ -381,7 +381,7 @@ class DictWidget(Widget):
self._sig_add()
def _sig_add(self, *args):
context = self.field.context_get(self.record)
context = self.field.get_context(self.record)
value = self.wid_text.get_text().decode('utf-8')
domain = self.field.domain_get(self.record)
@ -396,7 +396,7 @@ class DictWidget(Widget):
win.show()
def add_new_keys(self, ids):
context = self.field.context_get(self.record)
context = self.field.get_context(self.record)
self.send_modified()
try:
new_fields = RPCExecute('model', self.schema_model,
@ -494,7 +494,7 @@ class DictWidget(Widget):
self.buttons[key] = remove_but
def add_keys(self, keys):
context = self.field.context_get(self.record)
context = self.field.get_context(self.record)
domain = self.field.domain_get(self.record)
batchlen = min(10, CONFIG['client.limit'])
for i in xrange(0, len(keys), batchlen):

View file

@ -141,7 +141,7 @@ class Many2Many(Widget):
add_remove = self.record.expr_eval(self.attrs.get('add_remove'))
if add_remove:
domain = [domain, add_remove]
context = self.field.context_get(self.record)
context = self.field.get_context(self.record)
value = self.wid_text.get_text().decode('utf-8')
self.focus_out = False
@ -174,7 +174,7 @@ class Many2Many(Widget):
add_remove = self.record.expr_eval(self.attrs.get('add_remove'))
if add_remove:
domain = [domain, add_remove]
context = self.field.context_get(self.record)
context = self.field.get_context(self.record)
view_ids = self.attrs.get('view_ids', '').split(',')
if view_ids:
# Remove the first tree view as mode is form only

View file

@ -121,7 +121,7 @@ class Many2One(Widget):
or self.field.get_state_attrs(
self.record)['required'])):
domain = self.field.domain_get(self.record)
context = self.field.context_get(self.record)
context = self.field.get_context(self.record)
text = self.wid_text.get_text().decode('utf-8')
def callback(result):
@ -151,7 +151,7 @@ class Many2One(Widget):
def get_screen(self):
domain = self.field.domain_get(self.record)
context = self.field.context_get(self.record)
context = self.field.get_context(self.record)
return Screen(self.get_model(), domain=domain, context=context,
mode=['form'], view_ids=self.attrs.get('view_ids', '').split(','),
views_preload=self.attrs.get('views', {}), readonly=self._readonly,
@ -209,7 +209,7 @@ class Many2One(Widget):
return
if not self._readonly:
domain = self.field.domain_get(self.record)
context = self.field.context_get(self.record)
context = self.field.get_context(self.record)
text = self.wid_text.get_text().decode('utf-8')
def callback(result):

View file

@ -338,7 +338,7 @@ class One2Many(Widget):
def _new_single(self):
ctx = {}
ctx.update(self.field.context_get(self.record))
ctx.update(self.field.get_context(self.record))
sequence = None
for view in self.screen.views:
if view.view_type == 'tree':
@ -377,7 +377,7 @@ class One2Many(Widget):
search_set()
domain = field.domain_get(first)
context = field.context_get(first)
context = field.get_context(first)
def callback(result):
if result:
@ -451,7 +451,7 @@ class One2Many(Widget):
return
self.view.set_value()
domain = self.field.domain_get(self.record)
context = self.field.context_get(self.record)
context = self.field.get_context(self.record)
domain = [domain, self.record.expr_eval(self.attrs.get('add_remove'))]
removed_ids = self.field.get_removed_ids(self.record)
domain = ['OR', domain, ('id', 'in', removed_ids)]

View file

@ -562,7 +562,7 @@ class M2O(GenericText):
relation = record[self.attrs['name']].attrs['relation']
domain = record[self.attrs['name']].domain_get(record)
context = record[self.attrs['name']].context_get(record)
context = record[self.attrs['name']].get_context(record)
win = self.search_remote(record, relation, text, domain=domain,
context=context, callback=callback)
if len(win.screen.group) == 1:
@ -583,7 +583,7 @@ class M2O(GenericText):
return
domain = field.domain_get(record)
context = field.context_get(record)
context = field.get_context(record)
if create:
obj_id = None
elif not changed:
@ -715,7 +715,7 @@ class O2M(GenericText):
group = record.value[self.attrs['name']]
field = record.group.fields[self.attrs['name']]
relation = field.attrs['relation']
context = field.context_get(record)
context = field.get_context(record)
access = common.MODELACCESS[relation]
if not access['read']:
@ -741,7 +741,7 @@ class M2M(O2M):
group = record.value[self.attrs['name']]
field = record.group.fields[self.attrs['name']]
relation = field.attrs['relation']
context = field.context_get(record)
context = field.get_context(record)
domain = field.domain_get(record)
screen = Screen(relation, mode=['tree', 'form'],