diff --git a/browser/loops/auth.py b/browser/loops/auth.py index 4e94834..d9e8c1b 100644 --- a/browser/loops/auth.py +++ b/browser/loops/auth.py @@ -41,8 +41,8 @@ class LoopsSessionCredentialsPlugin(SessionCredentialsPlugin): if not IHTTPRequest.providedBy(request): return False site = hooks.getSite() - #camefrom = request.getURL() # wrong when object is not viewable - camefrom = request.getApplicationURL() + request['PATH_INFO'] + camefrom = request.getURL() # wrong when object is not viewable + #camefrom = request.getApplicationURL() + request['PATH_INFO'] if 'login' in camefrom: camefrom = '/'.join(camefrom.split('/')[:-1]) url = '%s/@@%s?%s' % (zapi.absoluteURL(site, request), diff --git a/browser/main.pt b/browser/main.pt index 26070f5..b554bef 100644 --- a/browser/main.pt +++ b/browser/main.pt @@ -1,9 +1,10 @@ - + diff --git a/browser/view.py b/browser/view.py index 6542a80..4af67b9 100644 --- a/browser/view.py +++ b/browser/view.py @@ -57,7 +57,7 @@ class GenericView(object): # make the (one and only controller) available via the request viewAnnotations = self.request.annotations.setdefault('cybertools.browser', {}) viewAnnotations['controller'] = controller - if getattr(controller, 'skinName', None): + if getattr(controller, 'skinName', None) and controller.skinName.value: self.setSkin(controller.skinName.value) controller.skin = self.skin # this is the place to register special macros with the controller: @@ -75,8 +75,12 @@ class GenericView(object): # self.setupController() def __call__(self, *args, **kw): + # this is useful for a top-level page only return self.index(*args, **kw) + def setupSubviews(self): + pass + #def render(self, *args, **kw): # return self.index(*args, **kw) diff --git a/relation/registry.py b/relation/registry.py index 0b70bae..3180783 100644 --- a/relation/registry.py +++ b/relation/registry.py @@ -25,17 +25,18 @@ $Id$ from persistent import Persistent from persistent.interfaces import IPersistent from zope import component +from zope.component import adapts from zope.interface import Interface, Attribute, implements -from zope.app import zapi -from zope.app.catalog.catalog import Catalog +from zope.app.catalog.catalog import Catalog, ResultSet from zope.app.catalog.field import FieldIndex from zope.app.intid.interfaces import IIntIds from zope.location.interfaces import ILocation from zope.event import notify from zope.component.interfaces import ObjectEvent from zope.security.proxy import removeSecurityProxy +from zope.traversing.api import getName, getParent -from interfaces import IRelationRegistry, IRelationInvalidatedEvent +from interfaces import IRelationRegistry, IRelationInvalidatedEvent, IRelation class DummyRelationRegistry(object): @@ -123,25 +124,35 @@ class RelationRegistry(Catalog): if getattr(relation, '__parent__', None) is None: # Allow the IntIds utility to get a DB connection: relation.__parent__ = self - self.index_doc(zapi.getUtility(IIntIds).register(relation), relation) + self.index_doc(component.getUtility(IIntIds).register(relation), relation) def unregister(self, relation): - self.unindex_doc(zapi.getUtility(IIntIds).getId(relation)) + self.unindex_doc(component.getUtility(IIntIds).getId(relation)) notify(RelationInvalidatedEvent(relation)) def getUniqueIdForObject(self, obj): if obj == '*': # wild card return '*' - return zapi.getUtility(IIntIds).queryId(obj) + return component.getUtility(IIntIds).queryId(obj) + + def apply(self, criteria): + for k in criteria: + # set min, max + value = criteria[k] + if k == 'relationship' and value.endswith('*'): + criteria[k] = (value[:-1], value[:-1] + '\x7f') + else: + criteria[k] = (value, value) + return super(RelationRegistry, self).apply(criteria) def query(self, example=None, **kw): - intIds = zapi.getUtility(IIntIds) + intids = component.getUtility(IIntIds) criteria = {} if example is not None: for attr in ('first', 'second', 'third',): value = getattr(example, attr, None) if value is not None: - criteria[attr] = intIds.getId(value) + criteria[attr] = intids.getId(value) pn = example.getPredicateName() if pn: criteria['relationship'] = pn @@ -150,15 +161,9 @@ class RelationRegistry(Catalog): if k == 'relationship': criteria[k] = kw[k].getPredicateName() else: - criteria[k] = intIds.getId(kw[k]) - for k in criteria: - # set min, max - value = criteria[k] - if k == 'relationship' and value.endswith('*'): - criteria[k] = (value[:-1], value[:-1] + '\x7f') - else: - criteria[k] = (value, value) - return self.searchResults(**criteria) + criteria[k] = intids.getId(kw[k]) + results = self.apply(criteria) + return ResultSet(results, intids) class IIndexableRelation(Interface): @@ -173,6 +178,7 @@ class IndexableRelationAdapter(object): """ implements(IIndexableRelation) + adapts(IRelation) def __init__(self, context): self.context = context @@ -184,7 +190,7 @@ class IndexableRelationAdapter(object): def __getattr__(self, attr): value = getattr(self.context, attr) if IPersistent.providedBy(value): - return zapi.getUtility(IIntIds).getId(value) + return component.getUtility(IIntIds).getId(value) else: return value @@ -226,7 +232,7 @@ def getRelationSingle(obj=None, relationship=None, forSecond=True): return None if len(rels) > 1: raise ValueError('Multiple hits when only one relation expected: ' - '%s, relationship: %s' % (zapi.getName(obj), + '%s, relationship: %s' % (getName(obj), relationship.getPredicateName())) return list(rels)[0] @@ -237,7 +243,7 @@ def setRelationSingle(relation, forSecond=True): """ first = relation.first second = relation.second - registry = zapi.getUtility(IRelationRegistry) + registry = component.getUtility(IRelationRegistry) if forSecond: rels = list(registry.query(second=second, relationship=relation)) else: @@ -261,7 +267,7 @@ def invalidateRelations(context, event): # if not IRelatable.providedBy(event.object): # return relations = [] - registries = zapi.getAllUtilitiesRegisteredFor(IRelationRegistry) + registries = component.getAllUtilitiesRegisteredFor(IRelationRegistry) for registry in registries: for attr in ('first', 'second', 'third'): try: @@ -277,10 +283,10 @@ def removeRelation(context, event): from its container (if appropriate) and the IntIds utility. """ if ILocation.providedBy(context): - parent = zapi.getParent(context) + parent = getParent(context) if parent is not None: del parent[context] - intids = zapi.getUtility(IIntIds) + intids = component.getUtility(IIntIds) intids.unregister(context) def setupIndexes(context, event):