Add get_eval function to have simple value for expr eval in on_change,

states, ...
Add signal record changed when removing model from group
This commit is contained in:
Cédric Krier committed 2008-08-01 12:38:42 +02:00
1 parent 8c8e74b5ff
commit d5698c0afc
3 files changed
+30 -2

No files matched your search

@@ -70,6 +70,10 @@ class CharField(object):
def get(self, model, check_load=True, readonly=True, modified=False):
return model.value.get(self.name, False) or False
def get_eval(self, model, check_load=True):
return self.get(model, check_load=check_load, readonly=True,
modified=False)
def set_client(self, model, value, test_state=True, force_change=False):
internal = model.value.get(self.name, False)
self.set(model, value, test_state)
@@ -278,6 +282,10 @@ class M2MField(CharField):
def get(self, model, check_load=True, readonly=True, modified=False):
return [('set', model.value[self.name] or [])]
def get_eval(self, model, check_load=True):
return self.get(model, check_load=check_load, readonly=True,
modified=False)[0][1]
def get_client(self, model):
return model.value[self.name] or []
@@ -346,6 +354,14 @@ class O2MField(CharField):
result.append(('delete', model.value[self.name].model_deleted))
return result
def get_eval(self, model, check_load=True):
result = []
if not model.value[self.name]:
return []
for model2 in model.value[self.name].models:
result.append(model2.get_eval(check_load=check_load))
return result
def set(self, model, value, test_state=False, modified=False):
from group import ModelRecordGroup
mod = ModelRecordGroup(self.attrs['relation'], {}, model.window,
+4 -1
View File
@@ -285,7 +285,7 @@ class ModelRecordGroup(SignalEvent):
return None
return self.models[self.current_idx]
def remove(self, model, remove=False):
def remove(self, model, remove=False, modified=True):
idx = self.models.index(model)
if self.models[idx].id:
if remove:
@@ -294,7 +294,10 @@ class ModelRecordGroup(SignalEvent):
self.model_deleted.append(self.models[idx].id)
if model.parent:
model.parent.modified = True
if modified:
model.modified = True
self.models.remove(self.models[idx])
model.signal('record-changed', model.parent)
def add_fields_custom(self, fields, models):
to_add = []
+10 -1
View File
@@ -123,6 +123,15 @@ class ModelRecord(SignalEvent):
value['id'] = self.id
return value
def get_eval(self, check_load=True):
if check_load:
self._check_load()
value = {}
for name, mfield in self.mgroup.mfields.items():
value[name] = mfield.get_eval(self, check_load=check_load)
value['id'] = self.id
return value
def cancel(self):
self._loaded = False
self.reload()
@@ -271,7 +280,7 @@ class ModelRecord(SignalEvent):
self._check_load()
ctx = rpc.CONTEXT.copy()
for name, mfield in self.mgroup.mfields.items():
ctx[name] = mfield.get(self, check_load=check_load)
ctx[name] = mfield.get_eval(self, check_load=check_load)
ctx['current_date'] = datetime.datetime.today()
ctx['time'] = time