def pasteObjects(self): """Paste ojects in the user clipboard to the container """ target = self.context clipboard = getPrincipalClipboard(self.request) items = clipboard.getContents() moved = False not_pasteable_ids = [] for item in items: duplicated_id = False try: obj = zapi.traverse(target, item['target']) except TraversalError: pass else: if item['action'] == 'cut': mover = IObjectMover(obj) try: mover.moveTo(target) moved = True except DuplicateIDError: duplicated_id = True elif item['action'] == 'copy': copier = IObjectCopier(obj) try: copier.copyTo(target) except DuplicateIDError: duplicated_id = True else: raise if duplicated_id: not_pasteable_ids.append(zapi.getName(obj)) if moved: # Clear the clipboard if we do a move, but not if we only do a copy clipboard.clearContents() if not_pasteable_ids != []: # Show the ids of objects that can't be pasted because # their ids are already taken. # TODO Can't we add a 'copy_of' or something as a prefix # instead of raising an exception ? raise UserError( _("The given name(s) %s is / are already being used" %( str(not_pasteable_ids))))
def getContextHelpTopic(self): """Retrieve a help topic based on the context of the help namespace. If the context is a view, try to find a matching help topic for the view and its context. If no help topic is found, try to get a help topic for the context only. If the context is not a view, try to retrieve a help topic based on the context. If nothing is found, return the onlinehelp root topic """ if self.topic is not None: return self.topic onlinehelp = self.context help_context = onlinehelp.context self.topic = None if IBrowserView.providedBy(help_context): # called from a view self.topic = getTopicFor( zapi.getParent(help_context), zapi.getName(help_context) ) if self.topic is None: # nothing found for view try context only self.topic = getTopicFor( zapi.getParent(help_context) ) else: # called without view self.topic = getTopicFor(help_context) if self.topic is None: self.topic = onlinehelp return self.topic
def evolve(context): """Evolve the ZODB from a Zope X3.0 to a X3.1 compatible format. - The Principal Annotation Service was replaced by the Principal Annotation Utility. Thus all service registrations have to be changed to utility registrations. - The Error Reporting Service was replaced by the Error Reporting Utility. Thus, all service registrations have to be changed to utility registrations. - Component-based registrations used to keep track of their components via the component's path. Now it stores the component directly. All registrations are updated to this new format. - Converts all service registrations to utility registrations providing IService, which is the method used to simulate the old service API. - Remove 'RegistrationManager' object from all site management folders. - Remove all local adapter and utility service instances. """ root = getRootFolder(context) for site in findObjectsProviding(root, ISite): sm = site.getSiteManager() # Remove old registration manager instances for rm in findObjectsProviding(sm, IRegistrationManager): # Make sure that we called the new registration manager # which will retrieve the old one, if necessary zapi.getParent(rm).registrationManager = rm # Do a hard core delete, because I want no whining and complaining container = zapi.getParent(rm) del container._SampleContainer__data[zapi.getName(rm)] # Make sure the new registration manager has the correct name: rm.__name__ = '++registrations++' rm.__parent__ = container for reg_container in findObjectsProviding(sm, IRegisterableContainer): manager = reg_container.registrationManager # Iterate through each registration and fix it up. for reg in tuple(manager.values()): # Regardless of registration type, we want to convert the # component path to component if ('_BBB_componentPath' in reg.__dict__ and reg._BBB_componentPath is not None): reg.component = reg.getComponent() del reg.__dict__['_BBB_componentPath'] # Fixup and convert service registrations if IServiceRegistration.providedBy(reg): if reg.name == 'ErrorLogging': fixupErrorLogging(reg_container, reg) elif reg.name == 'PrincipalAnnotation': fixupPrincipalAnnotation(reg_container, reg) elif reg.name in ('Utilities', 'Adapters'): # Delete the registration reg.status = InactiveStatus del manager[zapi.name(reg)] # Delete the component c = reg.component del zapi.getParent(c)[zapi.name(c)] else: # Handle all outstanding service registrations # Create a new utility registration new_reg = UtilityRegistration(reg.name, IService, reg.component) manager.addRegistration(new_reg) new_reg.status = ActiveStatus # Delete the old registration reg.status = InactiveStatus del manager[zapi.getName(reg)] # Fixup utility registrations else: # Getting the provided interface converts the utility # registration automatically from 'interface' -> 'provided' reg.provided # Now let's reactivate the utility, so it will be # available within the new framework orig = reg.status reg.status = InactiveStatus reg.status = orig
def render(self, name): schema = self.context.schema sourcename = getName(self.context) sourcepath = getPath(self.context) setUpWidgets(self, schema, IInputWidget, prefix=name+'.field') html = [] # add sub title for source search field html.append('<h4>%s</h4>' % sourcename) # start row for path display field html.append('<div class="row">') # for each source add path of source html.append(' <div class="label">') label = translate(source_label, context=self.request) title = translate(source_title, context=self.request) html.append(' <label for="%s" title="%s">' % (sourcename, title)) html.append(' %s' % label) html.append(' </label>') html.append(' </div>') html.append(' <div class="field">') html.append(' %s' % sourcepath) html.append(' </div>') html.append('</div>') # start row for search fields html.append('<div class="row">') for field_name, field in getFieldsInOrder(schema): widget = getattr(self, field_name+'_widget') # for each field add label... html.append(' <div class="label">') html.append(' <label for="%s" title="%s">' % (widget.name, widget.hint)) html.append(' %s' % widget.label) html.append(' </label>') html.append(' </div>') # ...and field widget html.append(' <div class="field">') html.append(' %s' % widget()) if widget.error(): html.append(' <div class="error">') html.append(' %s' % widget.error()) html.append(' </div>') html.append(' </div>') # end row html.append('</div>') # add search button for search fields html.append('<div class="row">') html.append(' <div class="field">') html.append(' <input type="submit" name="%s" value="%s" />' % (name+'.search', translate(search_label, context=self.request))) html.append(' </div>') html.append('</div>') return '\n'.join(html)
def render(self, name): schema = self.context.schema sourcename = getName(self.context) sourcepath = getPath(self.context) setUpWidgets(self, schema, IInputWidget, prefix=name + '.field') html = [] # add sub title for source search field html.append('<h4>%s</h4>' % sourcename) # start row for path display field html.append('<div class="row">') # for each source add path of source html.append(' <div class="label">') label = translate(source_label, context=self.request) title = translate(source_title, context=self.request) html.append(' <label for="%s" title="%s">' % (sourcename, title)) html.append(' %s' % label) html.append(' </label>') html.append(' </div>') html.append(' <div class="field">') html.append(' %s' % sourcepath) html.append(' </div>') html.append('</div>') # start row for search fields html.append('<div class="row">') for field_name, field in getFieldsInOrder(schema): widget = getattr(self, field_name + '_widget') # for each field add label... html.append(' <div class="label">') html.append(' <label for="%s" title="%s">' % (widget.name, widget.hint)) html.append(' %s' % widget.label) html.append(' </label>') html.append(' </div>') # ...and field widget html.append(' <div class="field">') html.append(' %s' % widget()) if widget.error(): html.append(' <div class="error">') html.append(' %s' % widget.error()) html.append(' </div>') html.append(' </div>') # end row html.append('</div>') # add search button for search fields html.append('<div class="row">') html.append(' <div class="field">') html.append( ' <input type="submit" name="%s" value="%s" />' % (name + '.search', translate(search_label, context=self.request))) html.append(' </div>') html.append('</div>') return '\n'.join(html)