예제 #1
0
 def test_subobject_w_post_copy_hook(self):
     from zope.copy.interfaces import ICopyHook
     from zope.location.location import Location
     from zope.location.location import locate
     from zope.copy.examples import Subobject
     o = Location()
     s = Subobject()
     o.subobject = s
     locate(s, o, 'subobject')
     self.assertTrue(s.__parent__ is o)
     self.assertEqual(o.subobject(), 0)
     self.assertEqual(o.subobject(), 1)
     self.assertEqual(o.subobject(), 2)
     class Hook(object):
         def __init__(self, context):
             self.context = context
         def __call__(self, obj, register):
             obj = Subobject()
             def reparent(translate):
                 obj.__parent__ = translate(self.context.__parent__)
             register(reparent)
             return obj
     def _adapt(iface, obj):
         if iface is ICopyHook and isinstance(obj, Subobject):
             return Hook(obj)
     _registerAdapterHook(_adapt)
     c = self._callFUT(o)
     self.assertTrue(c.subobject.__parent__ is c)
     self.assertEqual(c.subobject(), 0)
     self.assertEqual(o.subobject(), 3)
예제 #2
0
 def getEvaluationsOfEvaluator(self, evaluator):
     """See interfaces.IEvaluations"""
     result = [(name, ev) for name, ev in self.items()
               if ev.evaluator == evaluator]
     result = Evaluations(result)
     location.locate(result, getParent(self), getName(self))
     return result
예제 #3
0
 def getEvaluationsForRequirement(self, req, recurse=True):
     """See interfaces.IEvaluations"""
     requirements = getRequirementList(req, recurse)
     result = [(name, ev) for name, ev in self.items()
               if ev.requirement in requirements]
     result = Evaluations(result)
     location.locate(result, getParent(self), getName(self))
     return result
예제 #4
0
def getEvaluations(context):
    """Adapt an ``IHaveEvaluations`` object to ``IEvaluations``."""
    annotations = IAnnotations(removeAllProxies(context))
    try:
        return annotations[EVALUATIONS_KEY]
    except KeyError:
        evaluations = Evaluations()
        annotations[EVALUATIONS_KEY] = evaluations
        location.locate(evaluations, removeAllProxies(context),
                        '++evaluations++')
        return evaluations
예제 #5
0
 def test_subobject_wo_post_copy_hook(self):
     from zope.location.location import Location
     from zope.location.location import locate
     from zope.copy.examples import Subobject
     o = Location()
     s = Subobject()
     o.subobject = s
     locate(s, o, 'subobject')
     self.assertTrue(s.__parent__ is o)
     self.assertEqual(o.subobject(), 0)
     self.assertEqual(o.subobject(), 1)
     self.assertEqual(o.subobject(), 2)
     c = self._callFUT(o)
     self.assertTrue(c.subobject.__parent__ is c)
     self.assertEqual(c.subobject(), 3)
     self.assertEqual(o.subobject(), 3)
예제 #6
0
def setUpDefaultDemographics(app):
    dfs = DemographicsFields()
    app['schooltool.basicperson.demographics_fields'] = dfs
    locate(dfs, app, 'schooltool.basicperson.demographics_fields')
    dfs['ID'] = TextFieldDescription('ID', _('ID'))
    dfs['ethnicity'] = EnumFieldDescription('ethnicity', _('Ethnicity'))
    dfs['ethnicity'].items = [
        _('American Indian or Alaska Native'),
        _('Asian'),
        _('Black or African American'),
        _('Native Hawaiian or Other Pacific Islander'),
        _('White')
    ]
    dfs['language'] = TextFieldDescription('language', _('Language'))
    dfs['placeofbirth'] = TextFieldDescription('placeofbirth',
                                               _('Place of birth'))
    dfs['citizenship'] = TextFieldDescription('citizenship', _('Citizenship'))
예제 #7
0
 def _callFUT(self, obj, *args, **kw):
     from zope.location.location import locate
     return locate(obj, *args, **kw)
예제 #8
0
 def __init__(self, title):
     self.title = title
     self.states = OrderedContainer()
     locate(self.states, self, 'states')
     self.system_titles = OrderedContainer()
     locate(self.system_titles, self, 'system_titles')
예제 #9
0
 def __call__(self, *args, **kwargs):
     """See interfaces.IEvaluationsQuery"""
     result = Evaluations(self._query(*args, **kwargs))
     location.locate(result, getParent(self.context), getName(self.context))
     return result
예제 #10
0
 def _callFUT(self, obj, *args, **kw):
     from zope.location.location import locate
     return locate(obj, *args, **kw)
예제 #11
0
 def __init__(self, title):
     self.title = title
     self.states = OrderedContainer()
     locate(self.states, self, 'states')
     self.system_titles = OrderedContainer()
     locate(self.system_titles, self, 'system_titles')