本文整理汇总了Python中zope.container.contained.notifyContainerModified函数的典型用法代码示例。如果您正苦于以下问题:Python notifyContainerModified函数的具体用法?Python notifyContainerModified怎么用?Python notifyContainerModified使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了notifyContainerModified函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _delObject
def _delObject(self, id, dp=1, suppress_events=False):
"""Delete an object from this container.
Also sends IObjectWillBeRemovedEvent and IObjectRemovedEvent.
"""
ob = self._getOb(id)
compatibilityCall('manage_beforeDelete', ob, ob, self)
if not suppress_events:
notify(ObjectWillBeRemovedEvent(ob, self, id))
self._objects = tuple([i for i in self._objects
if i['id'] != id])
self._delOb(id)
# Indicate to the object that it has been deleted. This is
# necessary for object DB mount points. Note that we have to
# tolerate failure here because the object being deleted could
# be a Broken object, and it is not possible to set attributes
# on Broken objects.
try:
ob._v__object_deleted__ = 1
except:
pass
if not suppress_events:
notify(ObjectRemovedEvent(ob, self, id))
notifyContainerModified(self)
示例2: move
def move(self, pos, fieldset_index):
""" AJAX method to change field position within its schema.
The position is relative to the fieldset.
"""
schema = IEditableSchema(self.schema)
fieldname = self.field.__name__
pos = int(pos)
fieldset_index = int(fieldset_index)
fieldset_index -= 1 # index 0 is default fieldset
fieldsets = self.schema.queryTaggedValue(FIELDSETS_KEY, [])
new_fieldset = fieldset_index >= 0 and fieldsets[
fieldset_index] or None
schema.changeFieldFieldset(fieldname, new_fieldset)
ordered_field_ids = [info[0] for info in sortedFields(self.schema)]
if new_fieldset:
old_field_of_position = new_fieldset.fields[pos]
new_absolute_position = ordered_field_ids.index(
old_field_of_position)
else:
new_absolute_position = pos
# if fieldset changed, update fieldsets
schema.moveField(fieldname, new_absolute_position)
notifyContainerModified(self.schema)
notify(SchemaModifiedEvent(self.__parent__.__parent__))
示例3: mover
def mover(self):
any_moves = False
def do_move(from_container, content):
from_identifier = content.getId()
to_identifier = self.__make_id('move', from_identifier)
content = self.__move(
content, from_container, from_identifier, to_identifier)
content.manage_changeOwnershipType(explicit=0)
notifyContainerModified(from_container)
return content
content = yield
while content is not None:
result = self.__verify_moveable(content)
if result is None:
from_container = aq_parent(aq_inner(content))
if (aq_base(from_container) is not aq_base(self.context)):
result = do_move(from_container, content)
any_moves = True
else:
result = ContainerError(
_(u"Content already in the target container."),
content)
content = yield result
if any_moves:
notifyContainerModified(self.context)
示例4: move
def move(self, pos):
""" AJAX method to change field position within its schema.
The position is relative to the fieldset.
"""
schema = IEditableSchema(self.schema)
fieldname = self.field.__name__
pos = int(pos)
ordered_field_ids = [name for (name, field) in sortedFields(self.schema)]
for fieldset in self.schema.getTaggedValue(FIELDSETS_KEY):
# if we are in a fieldset, pos is the position relative to the fieldset
if fieldname in fieldset.fields:
old_field_of_position = fieldset.fields[pos]
absolute_position = ordered_field_ids.index(old_field_of_position)
break
else:
# in default fieldset, the relative position == the absolute position
fieldset = None
absolute_position = pos
schema.moveField(fieldname, absolute_position)
# if field is in a fieldset, also reorder fieldset tagged value
ordered_field_ids = [name for (name, field) in sortedFields(self.schema)]
if fieldset is not None:
fieldset.fields = sorted(fieldset.fields,
key=lambda x: ordered_field_ids.index(x))
notifyContainerModified(self.schema)
notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
示例5: __setitem__
def __setitem__(self, key, value):
if not key:
raise ValueError("empty names are not allowed")
object, event = containedEvent(value, self, key)
self._setitemf(key, value)
if event:
notify(event)
notifyContainerModified(self)
示例6: _delObject
def _delObject(self, id):
object = self._getOb(id)
notify(ObjectWillBeRemovedEvent(object, self, id))
if hasattr(aq_base(object), 'manage_beforeDelete'):
object.manage_beforeDelete(object, self)
self._delOb(id)
notify(ObjectRemovedEvent(object, self, id))
notifyContainerModified(self)
示例7: move
def move(self, pos):
""" AJAX method to change field position within its schema.
"""
schema = IEditableSchema(self.schema)
fieldname = self.field.__name__
schema.moveField(fieldname, int(pos))
notifyContainerModified(self.schema)
notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
示例8: set_container_order
def set_container_order(self, order):
if not isinstance(order, ListType) and \
not isinstance(order, TupleType):
raise TypeError('order must be a tuple or a list.')
for i in order:
if i not in self:
raise ValueError('order item not in container.')
self._container_order = PersistentList(order)
notifyContainerModified(self)
示例9: do_move
def do_move(from_container, content):
from_identifier = content.getId()
to_identifier = self.__make_id('move', from_identifier)
content = self.__move(
content, from_container, from_identifier, to_identifier)
content.manage_changeOwnershipType(explicit=0)
notifyContainerModified(from_container)
return content
示例10: moveObjectsByDelta
def moveObjectsByDelta(
self,
ids,
delta,
subset_ids=None,
suppress_events=False
):
"""Move specified sub-objects by delta."""
if isinstance(ids, basestring):
ids = (ids,)
min_position = 0
objects = list(self._objects)
if subset_ids is None:
subset_ids = self.getIdsSubset(objects)
else:
subset_ids = list(subset_ids)
# unify moving direction
if delta > 0:
ids = list(ids)
ids.reverse()
subset_ids.reverse()
counter = 0
for id in ids:
old_position = subset_ids.index(id)
new_position = max(old_position - abs(delta), min_position)
if new_position == min_position:
min_position += 1
if not old_position == new_position:
subset_ids.remove(id)
subset_ids.insert(new_position, id)
counter += 1
if counter > 0:
if delta > 0:
subset_ids.reverse()
obj_dict = {}
for obj in objects:
obj_dict[obj['id']] = obj
pos = 0
for i in range(len(objects)):
if objects[i]['id'] in subset_ids:
try:
objects[i] = obj_dict[subset_ids[pos]]
pos += 1
except KeyError:
raise ValueError('The object with the id "%s" does '
'not exist.' % subset_ids[pos])
self._objects = tuple(objects)
if not suppress_events:
notifyContainerModified(self)
return counter
示例11: change
def change(self, fieldset_index):
""" AJAX method to change the fieldset of a field
"""
fieldset_index = int(fieldset_index)
fieldsets = self.schema.getTaggedValue(FIELDSETS_KEY)
field_name = self.field.__name__
# get current fieldset
fieldset_fields = []
current_fieldset = None
for fieldset in fieldsets:
if field_name in fieldset.fields:
current_fieldset = fieldset
fieldset_fields.extend(fieldset.fields)
# get future fieldset
if len(sortedFields(self.schema)) != len(fieldset_fields):
# we have a default fieldset
fieldset_index -= 1
if fieldset_index >= 0:
# the field has not been moved into default
next_fieldset = fieldsets[fieldset_index]
else:
next_fieldset = None
# computing new Position, which is the last position of the new fieldset
ordered_field_ids = [name for (name, field) in sortedFields(self.schema)]
if next_fieldset is None:
# if this is the default,
new_position = ordered_field_ids.index(fieldset_fields[0])
else:
# first we get the first of the fieldsets after the new one
new_position = None
for fieldset in fieldsets[fieldsets.index(next_fieldset)+1:]:
if len(fieldset.fields) > 0:
new_position = ordered_field_ids.index(fieldset.fields[0]) - 1
break
else:
new_position = len(ordered_field_ids) - 1
schema = IEditableSchema(self.schema)
schema.moveField(field_name, new_position)
# move field
if next_fieldset is not None:
next_fieldset.fields.append(field_name)
if current_fieldset is not None:
current_fieldset.fields.remove(field_name)
notifyContainerModified(self.schema)
notify(SchemaModifiedEvent(self.aq_parent.aq_parent))
示例12: _setObject
def _setObject(self, id, object, suppress_events=False):
if not suppress_events:
notify(ObjectWillBeAddedEvent(object, self, id))
self._setOb(id, object)
object = self._getOb(id)
if hasattr(aq_base(object), 'manage_afterAdd'):
object.manage_afterAdd(object, self)
if not suppress_events:
notify(ObjectAddedEvent(object, self, id))
notifyContainerModified(self)
return object
示例13: moveObjectsByDelta
def moveObjectsByDelta(self, ids, delta, subset_ids=None, # noqa: C901 FIXME
suppress_events=False):
"""Move the specified ids (a sequence, or a single string id) by the
given delta (a positive or negative number). By default, this moves the
objects within the whole set of sub-items in the context container, but
if subset_ids is specified, it gives a subset of ids to consider.
Should return the number of objects that changed position.
"""
# changes for reverse ordering are marked with "# reversed"
delta = -delta # reversed
order = self._order()
pos = self._pos()
min_position = 0
if isinstance(ids, basestring):
ids = [ids]
if subset_ids is None:
# delegate to default implementation
subset_ids = super(ReversedOrdering, self).idsInOrder() # reversed
elif not isinstance(subset_ids, list):
subset_ids = list(subset_ids)
subset_ids.reverse() # reversed
if delta > 0: # unify moving direction
ids = reversed(ids)
subset_ids.reverse()
counter = 0
for id in ids:
try:
old_position = subset_ids.index(id)
except ValueError:
continue
new_position = max(old_position - abs(delta), min_position)
if new_position == min_position:
min_position += 1
if not old_position == new_position:
subset_ids.remove(id)
subset_ids.insert(new_position, id)
counter += 1
if counter > 0:
if delta > 0:
subset_ids.reverse()
idx = 0
for i in range(len(order)):
if order[i] in subset_ids:
id = subset_ids[idx]
try:
order[i] = id
pos[id] = i
idx += 1
except KeyError:
raise ValueError('No object with id "{0}" exists.'.format(id))
if not suppress_events:
notifyContainerModified(self.context)
return counter
示例14: move_compromisso_para_agendadiaria
def move_compromisso_para_agendadiaria(event, obj=None):
""" Toda vez que um tipo compromisso for criado ou tiver sua
data alterada
ele sera movido para dentro de uma agenda diaria
"""
if not obj:
obj = event.object
if not ICompromisso.providedBy(obj): # nao eh um compromisso
return
start_date = getattr(obj, 'start_date', None)
if not start_date:
return
formatted_date = start_date.strftime(AGENDADIARIAFMT)
origin = aq_parent(obj)
agenda = _get_agenda(origin)
old_id = obj.getId()
destination_id = formatted_date
destination = _get_destination(agenda, obj, origin, destination_id)
if not IAgendaDiaria.providedBy(destination):
logger.warn('Objeto %s nao foi movido' % str(obj))
# Reindexamos o SearchableText de origin
origin.reindexObject(idxs=['SearchableText', ])
return None
new_id = _generate_id(destination, old_id)
# Prepare to move object
notify(ObjectWillBeMovedEvent(obj, origin, old_id, destination, new_id))
obj.manage_changeOwnershipType(explicit=1)
# Remove object from origin
origin._delObject(old_id, suppress_events=True)
obj = aq_base(obj)
# Set new_id -- which is unique on destination
obj._setId(new_id)
# Persist object in destination
destination._setObject(new_id, obj, set_owner=0, suppress_events=True)
obj = destination._getOb(new_id)
notify(ObjectMovedEvent(obj, origin, old_id, destination, new_id))
notifyContainerModified(origin)
notifyContainerModified(destination)
obj._postCopy(destination, op=1)
# try to make ownership implicit if possible
obj.manage_changeOwnershipType(explicit=0)
# Reindexamos o SearchableText de destination
destination.reindexObject(idxs=['SearchableText', ])
示例15: __iter__
def __iter__(self):
# Store positions in a mapping containing an id to position mapping for
# each parent path {parent_path: {item_id: item_pos}}.
positions_mapping = {}
for item in self.previous:
keys = item.keys()
pathkey = self.pathkey(*keys)[0]
poskey = self.poskey(*keys)[0]
if not (pathkey and poskey):
yield item
continue
item_id = item[pathkey].split('/')[-1]
parent_path = '/'.join(item[pathkey].split('/')[:-1])
if parent_path not in positions_mapping:
positions_mapping[parent_path] = {}
positions_mapping[parent_path][item_id] = item[poskey]
yield item
# Set positions on every parent
for path, positions in positions_mapping.items():
# Normalize positions
ordered_keys = sorted(positions.keys(), key=lambda x: positions[x])
normalized_positions = {}
for pos, key in enumerate(ordered_keys):
normalized_positions[key] = pos
# TODO: After the new collective.transmogrifier release (>1.4), the
# utils.py provides a traverse method.
# from collective.transmogrifier.utils import traverse
# parent = traverse(self.context, path)
parent = self.context.unrestrictedTraverse(path.lstrip('/'))
if not parent:
continue
parent_base = aq_base(parent)
if hasattr(parent_base, 'getOrdering'):
ordering = parent.getOrdering()
# Only DefaultOrdering of p.folder is supported
if (not hasattr(ordering, '_order')
and not hasattr(ordering, '_pos')):
continue
order = ordering._order()
pos = ordering._pos()
order.sort(key=lambda x: normalized_positions.get(x,
pos.get(x, self.default_pos)))
for i, id_ in enumerate(order):
pos[id_] = i
notifyContainerModified(parent)