2008-02-28

interfaces.py

  2008-02-28 00:30

...

### -*- coding: utf-8 -*- #############################################
#######################################################################
"""Interfaces for the Zope 3 based product package

$Id: interfaces.py 50071 2008-01-13 21:25:58Z cray $
"""
__author__  = "SergeyAlembekov, 2007"
__license__ = "GPL"
__version__ = "$Revision: 50071 $"
 
from zope.interface import Interface

from zope.schema import Text, TextLine, Field, Bool, Datetime, Int, Choice
from zope.app.container.interfaces import IContained, IContainer
from zope.app.container.constraints import ItemTypePrecondition
from zope.app.container.constraints import ContainerTypesConstraint
from zope.app.zapi import getUtility
from zope.app.zapi import queryUtility
from zope.app.keyreference.interfaces import IKeyReference


class IRegistryTextLine(Interface):
        data = TextLine(
                title = u'Value of textual parameter',
                description = u'',
                default = u'',
                required = False)
                            
class IRegistryInt(Interface):
        data = Int(
                title = u'Value of int parameter',
                description = u'',
                default = 0,
                required = False)

def check_id(name, check_list=set()) :
        if name is None :
            return True
        else :   
            ob = getUtility(IRegistry, name=name)
            iob=IKeyReference(ob)
            if iob in check_list :
                return False
            else :
                return check_id(ob.next, check_list | set([iob]))

#
# Ларчик открывался на удивление просто: расчет начинался с текущего
# объекта, но при этом текущий объект не заносился в список пройденных
# объектов, так как его еще "как бы не было", в результате заносимое имя
# давало ошибку только на втором коммите (когда оно уже было в объекте и
# создавало цикл). Я исправил ошибку, но такое требование означает, что
# передать констрайнт как параметр нельзя: он не получит доступа к объекту
#

class SafeChoice(Choice):
        def constraint(self, name):
                return check_id(name, set([IKeyReference(self.context)]))

class IRegistry(Interface):
        """A registry object"""

# 
# Поставили required=False, так как поле может быть пустым
#
        next = SafeChoice(
                vocabulary='RegistryVocabulary',
                title=u"Parent",
                required=False)
        
        def param(name, default):
                """ Return from container value of name """

class IRegistryContent(Interface):
        """ Iterface that specify permission of object that can be content
                of notebook """
        __parent__ = Field(constraint = ContainerTypesConstraint(IRegistry))
        

class IRegistryContainer(IContainer, IRegistry):
        """Registry Container"""

        def __setitem__(name, object):
                pass

        __setitem__.precondition = ItemTypePrecondition(IRegistryContent)



Официальный сайт Zope3 Московская группа изучения реактивного движения The Dream Bot Site noooxml