English 中文(简体)
我怎样才能改变由波罗内地延伸制成的物体的URL。
原标题:How can I change the URL of an object serverd by Dexterity in Plone

我根据Plone Dexterity界定了一些内容类型,我希望任何内容类型都有自己的身份证。 因此,我使用了zope.schema。 同上。

class IArticle(form.Schema, IImageScaleTraversable):
    """
    Article
    """

    form.model("models/article.xml")

    id = schema.Id(
        title=_(u"Identifier"),
        description=_(u"The unique identifier of object."),
        required=False
    )

当我制造新的物品时,该物品会作罚款,但当我想修改一个存在的条款时,它总是显示我的错误:

 { args : (<MultiContentTreeWidget  form.widgets.IRelatedItems.relatedItems >,),
  context : <Article at /dev/articles/this-is-another-articles>,
  default : <object object at 0x100266b20>,
  loop : {},
  nothing : None,
  options : {},
  repeat : {},
  request : <HTTPRequest, URL=http://localhost:8083/dev/articles/this-is-another-article/@@edit>,
  template : <zope.browserpage.viewpagetemplatefile.ViewPageTemplateFile object at 0x10588ecd0>,
  view : <MultiContentTreeWidget  form.widgets.IRelatedItems.relatedItems >,
  views : <zope.browserpage.viewpagetemplatefile.ViewMapper object at 0x10b309f50>}
 .......
 .......
 .......
Module zope.tales.expressions, line 217, in __call__
Module zope.tales.expressions, line 211, in _eval
Module plone.formwidget.contenttree.widget, line 147, in render_tree
Module plone.app.layout.navigation.navtree, line 186, in buildFolderTree
Module Products.CMFPlone.CatalogTool, line 427, in searchResults
Module Products.ZCatalog.ZCatalog, line 604, in searchResults
Module Products.ZCatalog.Catalog, line 907, in searchResults
Module Products.ZCatalog.Catalog, line 656, in search
Module Products.ZCatalog.Catalog, line 676, in sortResults
Module plone.app.folder.nogopip, line 104, in documentToKeyMap
Module plone.folder.ordered, line 102, in getObjectPosition
Module plone.folder.default, line 130, in getObjectPosition
ValueError: No object with id "this-is-another-articles" exists.
问题回答

我不认为这是Edit股票形式的使用案例。 您可重新命名包含该项目的夹件目录中的项目。 如果你想从ed的形式来做:

  • You may need to use a custom edit form (subclass the existing form);
  • name your id field something other than id , perhaps target_id or shortname
  • have the __call__() method of the form update / save the form, and only on success rename the item within its container.
  • __call__() should redirect to the new item s URL after edit that triggers a name change.

或许像(完全没有测试):

from plone.dexterity.browser.edit import DefaultEditForm as BaseForm
from Products.statusmessages.interfaces import IStatusMessages

class RenameEnabledEditForm(BaseForm):
    def __call__(self, *args, **kwargs):
         self.update(*args, **kwargs)
         data, errors = self.extractData()
         existing, newid = self.context.getId(), data.get( target_id )
         if not errors and existing != newid:
             parent_folder = self.context.__parent__
             if newid in parent_folder.objectIds():
                 raise RuntimeError( Duplicate object id )  # collision!
             parent_folder.manage_renameObject(existing, newid)
             newurl = parent_folder[newid].absolute_url()
             IStatusMessages(self.context).addStatusMessage(
                 u Renamed item from "%s" to "%s" in folder  % (existing, newid),
                 type= info ,
                 )
             self.request.response.redirect(newurl)
         else:
             return self.index(*args, **kwargs)

我用习惯添加表格实现了这一目的,只有添加形式包括id-field和edit形式t(通过更名为“行动”或从多重内容观点进行老调)。

一些锅炉:

from five import grok

from zope import schema

from plone.directives import form
from plone.directives import dexterity


class IMyContent(form.Schema):
    """Schema of MyContent"""


class NotValidId(schema.ValidationError):
    """Id is not valid."""


def isValidId(value):
    """Validates id for new MyContent objects"""
    # raise NotValidId(value)
    return True


class IMyContentAddForm(IMyContent):
    """Schema of MyContent Add Form"""

    form.order_before(id="*")
    id = schema.ASCIILine(
        title=u"Id",
        constraint=isValidId,
        required=True
        )


class MyContentAddForm(dexterity.AddForm):
    """Add Form for new MyContent objects"""
    grok.name("my.app.mycontent")

    label = u"Add New"
    schema = IMyContentAddForm

    def create(self, data):
        """Creates a new object with the given (validated) id"""
        id = data.pop("id")
        obj = super(MyContentAddForm, self).create(data)
        obj.id = id
        return obj

还有 开放问题及其初步工作,使Dexterity-types支持标准“关于内容的 Name?”-feature。

适用于精度含量类型,即改装@spdupton 回答(在进口中装上打字)和自变。 自我保护的背景。 请求

from Products.statusmessages.interfaces import IStatusMessage

class EditForm(dexterity.EditForm):
    grok.context(IPics)


    def applyChanges(self, data):    
        existing = self.context.getId()
        data, errors = self.extractData()
        super(EditForm, self).applyChanges(data)


        newid = str(data.get( picName ))

        print  existing, newid = , existing, newid
        if not errors and existing != newid:
            parent_folder = self.context.__parent__
            if newid in parent_folder.objectIds():
                raise RuntimeError( Duplicate object id )  页: 1 collision!
            parent_folder.manage_renameObject(existing, newid)
            newurl = parent_folder[newid].absolute_url()
            IStatusMessage(self.request).addStatusMessage(
                u Renamed item from "%s" to "%s"  % (existing, newid),
                type= info ,
                )
            self.request.response.redirect(newurl)

页: 1





相关问题
XmlDocument.Validate ignore properties without [XmlIgnore]

I have a object that has a number of properties that aren t present in the xsd file. When doing XmlDocument.Validate is there a way I can tell it to ignore properties that are not present in the xsd ...

FOSS version of SQLCompare or something similar?

Actually, free is good enough, it doesn t have to be open source :) I m currently using the Schema Compare utility of VS2008, but it doesn t have a command line interface and has some other ...

How does Doctrine handle changes to the database schema?

In brief, what happens when you add a column to a table? What happens when you remove one? In more details, suppose you have the following: class User extends Doctrine_Record { public function ...

摘自XML Schema

我想要把复杂的XML化学仪编成册,并出口到C#文档中。

Using a schema other than dbo in LinqToSql Designer

Is there a way to specify in a data connection or the LinqToSql Designer a schema? Whenever I go to setup a data connection for LinqToSql there doesn t seem to be anyway to specify a schema and I ...

热门标签