[gen] Added wrapper.createFrom, similar to wrapper.create, but allows to create an object with data from another object (kind of 'duplicate' functionality).
This commit is contained in:
parent
400158a0a1
commit
4d12293dc8
7 changed files with 70 additions and 34 deletions
|
@ -533,6 +533,11 @@ class Field:
|
|||
return self.default
|
||||
return value
|
||||
|
||||
def getCopyValue(self, obj):
|
||||
'''Gets the value of this field on p_obj as with m_getValue above. But
|
||||
if this value is mutable, get a copy of it.'''
|
||||
return self.getValue(obj)
|
||||
|
||||
def getFormattedValue(self, obj, value, showChanges=False, language=None):
|
||||
'''p_value is a real p_obj(ect) value from a field from this type. This
|
||||
method returns a pretty, string-formatted version, for displaying
|
||||
|
|
|
@ -331,6 +331,7 @@ class File(Field):
|
|||
name = requestName or self.name
|
||||
return obj.REQUEST.get('%s_file' % name)
|
||||
|
||||
def getCopyValue(self, obj): raise Exception('Not implemented yet.')
|
||||
def getDefaultLayouts(self): return {'view':'l-f','edit':'lrv-f'}
|
||||
|
||||
def isEmptyValue(self, obj, value):
|
||||
|
|
|
@ -786,6 +786,14 @@ class Ref(Field):
|
|||
if someObjects: return res
|
||||
return res.objects
|
||||
|
||||
def getCopyValue(self, obj):
|
||||
'''Here, as "value ready-to-copy", we return the list of tied object
|
||||
UIDs, because m_store on the destination object can store tied
|
||||
objects based on such a list.'''
|
||||
res = getattr(obj.aq_base, self.name, ())
|
||||
# Return a copy: it can be dangerous to give the real database value.
|
||||
if res: return list(res)
|
||||
|
||||
def getPossibleValues(self, obj, startNumber=None, someObjects=False,
|
||||
removeLinked=False):
|
||||
'''This method returns the list of all objects that can be selected
|
||||
|
|
|
@ -155,6 +155,7 @@ class String(Field):
|
|||
multilingual=len(languages) > 1;
|
||||
mLayout=multilingual and field.getLanguagesLayout('view');
|
||||
mayAjaxEdit=not showChanges and field.inlineEdit and \
|
||||
(layoutType != 'cell') and \
|
||||
zobj.mayEdit(field.writePermission)">
|
||||
<x if="field.isSelect">
|
||||
<span if="not value" class="smaller">-</span>
|
||||
|
@ -518,6 +519,13 @@ class String(Field):
|
|||
value = list(value)
|
||||
return value
|
||||
|
||||
def getCopyValue(self, obj):
|
||||
'''If the value is mutable (ie, a dict for a multilingual field), return
|
||||
a copy of it instead of the value stored in the database.'''
|
||||
res = self.getValue(obj)
|
||||
if isinstance(res, dict): res = res.copy()
|
||||
return res
|
||||
|
||||
def valueIsInRequest(self, obj, request, name):
|
||||
languages = self.getAttribute(obj, 'languages')
|
||||
if len(languages) == 1:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue