Ejemplo n.º 1
0
    def test_obstinatenamechooser(self):
        container = TestContainer()
        container[u'foobar'] = Contained()
        renamer = IContainerItemRenamer(container)

        renamer.renameItem(u'foobar', u'newname')
        self.assertEqual(list(container), [u'foobar'])
    def test_obstinatenamechooser(self):
        container = TestContainer()
        container[u'foobar'] = Contained()
        renamer = IContainerItemRenamer(container)

        renamer.renameItem(u'foobar', u'newname')
        self.assertEqual(list(container), [u'foobar'])
Ejemplo n.º 3
0
    def update(self):
        super(ContentsNameColumn, self).update()

        # Given a sequence of tuples of old, new ids we rename
        if 'applyButton' in self.table.environ:
            ids = self.table.environ['activeIds']
            newids = self.request.get("newIds", ())

            renamed = False
            renamer = IContainerItemRenamer(
                removeAllProxies(self.table.context))
            for oldid, newid in zip(ids, newids):
                if newid != oldid:
                    try:
                        # Exclude incorrect characters from new id
                        validchars = "-_.%s%s" % (
                            string.lowercase, string.digits)
                        newid = ''.join(
                            c for c in newid.lower() if c in validchars)
                        renamer.renameItem(oldid, newid)
                    except DuplicationError:
                        IStatusMessage(self.request).add(
                            _('Item with this name already exists.'), 'error')
                        return

                    renamed = True
                    ids[ids.index(oldid)] = newid

            if renamed:
                IStatusMessage(self.request).add(_('Items have been renamed.'))
Ejemplo n.º 4
0
    def handleApply(self, action):
        context = self.context
        request = self.request

        data, errors = self.extractData()
        if errors:
            errors = [error for error in errors
                      if not error.error.__class__ == ContentNameError]

            IStatusMessage(self.request).add(
                [self.formErrorsMessage] + errors, 'formError')
        else:
            changes = self.applyChanges(data)

            if self.allowRename():
                newName = self.getName()
                if newName != context.__name__:
                    renamer = IContainerItemRenamer(context.__parent__)
                    renamer.renameItem(context.__name__, newName)
                    changes = True

            if changes:
                IStatusMessage(request).add(self.successMessage)
            else:
                IStatusMessage(request).add(self.noChangesMessage)

            nextURL = self.nextURL()
            if nextURL:
                self.redirect(nextURL)
Ejemplo n.º 5
0
    def renameObjects(self):
        """Given a sequence of tuples of old, new ids we rename"""
        request = self.request
        ids = request.get("rename_ids")
        newids = request.get("new_value")

        renamer = IContainerItemRenamer(self.context)
        for oldid, newid in zip(ids, newids):
            if newid != oldid:
                renamer.renameItem(oldid, newid)
Ejemplo n.º 6
0
    def renameObjects(self):
        """Given a sequence of tuples of old, new ids we rename"""
        request = self.request
        ids = request.get("rename_ids")
        newids = request.get("new_value")

        renamer = IContainerItemRenamer(self.context)
        for oldid, newid in zip(ids, newids):
            if newid != oldid:
                renamer.renameItem(oldid, newid)
Ejemplo n.º 7
0
    def handleApply(self, action):
        context = self.context
        request = self.request

        data, errors = self.extractData()
        if errors:
            errors = [error for error in errors
                      if not isinstance(error.error, NameError)]

            IStatusMessage(self.request).add(
                [self.formErrorsMessage] + errors, 'formError')
            return

        if not self.step.isComplete():
            return

        if 'shortname' in data:
            shortname = data['shortname']
            if shortname != context.__name__:
                valid_chars = "-.%s%s" % (string.lowercase, string.digits)
                shortname = shortname.lower()
                shortname = ''.join(c for c in shortname if c in valid_chars)
                data['shortname'] = shortname
                if shortname != context.__name__:
                    renamer = IContainerItemRenamer(
                        removeAllProxies(context.__parent__))
                    renamer.renameItem(context.__name__, shortname)
                    event.notify(ObjectModifiedEvent(context))

                context = context.__parent__[shortname]
                if '<div class="statusMessage">No changes were applied.</div>\n' in IStatusMessage(self.request).messages()[0] \
                    and len(IStatusMessage(self.request).messages()) == 1:
                    IStatusMessage(self.request).clear()
                IStatusMessage(self.request).add(
                    _('Short name have been changed')
                )
                self.redirect(
                    '%s/%s/' % (
                        absoluteURL(context.__parent__, request),
                        self.__name__
                    )
                )
Ejemplo n.º 8
0
 def handlerRename(self, action):
     changed = False
     errorMessages = {}
     renameCol = self.columnByName.get('renameColumn')
     if renameCol:
         for item in list(self.values):
             if item in self.selectedItems:
                 errorMsg = None
                 oldName = renameCol.getItemValue(item)
                 newName = renameCol.getRenameValue(item)
                 if newName is not None and oldName != newName:
                     try:
                         container = removeSecurityProxy(self.context)
                         renamer = IContainerItemRenamer(container)
                         renamer.renameItem(oldName, newName)
                         changed = True
                     except DuplicationError:
                         errorMsg = self.renameDuplicationMessage
                         changed = True
                     except ItemNotFoundError:
                         errorMsg = self.renameItemNotFoundMessage
                         changed = True
                 elif newName is None:
                     errorMsg = _('No name given')
                 elif newName is not None and oldName == newName:
                     errorMsg = _('No new name given')
                 if errorMsg is not None:
                     key = renameCol.getItemKey(item)
                     errorMessages[key] = zope.i18n.translate(
                         errorMsg, context=self.request)
     if changed:
         self.status = self.renameErrorMessage
         # update the table rows before we start with rendering
         self.updateAfterActionExecution()
         # and set error message back to the new rename column
         renameCol = self.columnByName.get('renameColumn')
         if renameCol:
             renameCol.errorMessages = errorMessages
Ejemplo n.º 9
0
    def changeShortName(self, name):
        if self.space.__name__ != name:
            INameChooser(self.manager).checkName(name, self.space)

            renamer = IContainerItemRenamer(self.manager)
            renamer.renameItem(self.space.__name__, name)