扩展Plone-Controlpanel表格

时间:2016-11-14 09:45:51

标签: plone z3c.form

是否可以使用每个插件扩展Controlpanel-View?

例如
ca.db.core - >为DB连接设置制作基本字段集/选项卡 ca.db.person - >如果已安装,则向“核心”设置添加针对人员特定字段/设置的新字段集/选项卡 ca.db.schema - >如果已安装,还会为schema.org字段

添加新的字段集/选项卡

1 个答案:

答案 0 :(得分:3)

是的,有可能,我曾经和一个写过bda.plone.shop插件的家伙讨论过这个问题。

他们遇到了同样的问题,并通过使用ContextProxy对象解决了这个问题,该对象将不同的模式定义放在一个代理对象中。

使用代理是恕我直言,但我不知道更好的解决方案。

代理,尝试从模式列表中获取/设置属性。 请注意,您需要处理冲突的名称,这意味着如果您在多个架构中具有相同的字段名称。

private animalClass[] fileToAnimalArray(String fileName)
    {
        // read the number of lines in the file and declare animal array with exact number needed
        int lineCount = File.ReadLines(fileName).Count();
        animalClass[] animalArray = new animalClass[lineCount];

        //declare temp variables to hold a single read out from the file and a string array to hold the split up string
        String line;
        String[] lineArray = new String[10];

        // open up file in prepartion to read file
        StreamReader file = new StreamReader(fileName);

        // start loop in order to extract each line of the file
        for (int i = 0; i < lineCount; i++)
        {
            // read line and spllit it
            line = file.ReadLine();
            lineArray = line.Split(',');
            string temp = lineArray[0];
            // assign split string into each property of the animal array casting if needed.
            animalArray[i].aClass = lineArray[0];  // *error thrown here*
            animalArray[i].aOrder = lineArray[1];
            animalArray[i].aFamily = lineArray[2];
            animalArray[i].aGenus = lineArray[3];
            animalArray[i].aName = lineArray[4];
            animalArray[i].aLength = Convert.ToDouble(lineArray[5]);
            animalArray[i].aWeight = Convert.ToDouble(lineArray[6]);
            animalArray[i].extState = lineArray[7];
            animalArray[i].recordCreationDate = Convert.ToDateTime(lineArray[8]);
            animalArray[i].recordLastEdit = Convert.ToDateTime(lineArray[9]);

        }

        // close the file
        file.Close();

        // return the array
        return animalArray;
    }

现在您需要在ControlPanel表单中使用代理。 我假设您使用的是来自class ContextProxy(object): def __init__(self, interfaces): self.__interfaces = interfaces alsoProvides(self, *interfaces) def __setattr__(self, name, value): if name.startswith('__') or name.startswith('_ContextProxy__'): return object.__setattr__(self, name, value) registry = getUtility(IRegistry) for interface in self.__interfaces: proxy = registry.forInterface(interface) try: getattr(proxy, name) except AttributeError: pass else: return setattr(proxy, name, value) raise AttributeError(name) def __getattr__(self, name): if name.startswith('__') or name.startswith('_ContextProxy__'): return object.__getattr__(self, name) registry = getUtility(IRegistry) for interface in self.__interfaces: proxy = registry.forInterface(interface) try: return getattr(proxy, name) except AttributeError: pass raise AttributeError(name) 的{​​{1}}:

RegistryEditForm

您可以找到完整的代码here