def setUp(self):
        from collective.routes import addRoute
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        addRoute('foobar',
                 '/{effective:year}/{effective:month}/{effective:day}',
                 defaultQuery={'portal_type': 'News Item'})
        addRoute('foobar1',
                 '/foobar1/{effective:year}/{effective:month}/{effective:day}',
                 defaultQuery={'portal_type': 'News Item'})
        addRoute('foobar2',
                 '/foobar2/{Subject}',
                 defaultQuery={'portal_type': 'News Item'})
        folder = createObject(self.portal, 'Folder', 'folder')
        createObject(folder, 'News Item', 'test1',
            title="Test 1", effectiveDate="2010/10/10")
        createObject(folder, 'News Item', 'test2',
            title="Test 2", effectiveDate="2010/10/09", subject=('foobar',))
        self.activateRoutes()

        transaction.commit()
        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        browserLogin(self.portal, self.browser)
Esempio n. 2
0
from collective.routes import addRoute
from psusymp.traversingdjango.models import Person
from django.core.exceptions import ObjectDoesNotExist
from psusymp.traversingplone.content import CustomContent
from psusymp.traversingplone.content import DjangoContent


def customFinder(context, **kwargs):
    query = context.query
    if 'name' in query and query['name'] in ['foobar', 'testing', 'hello']:
        return CustomContent(context, context.request, query['name'])

addRoute('Custom Content', '/customcontent/{name}',
         objectFinder=customFinder)


def customDjangoFinder(context, **kwargs):
    query = context.query
    if 'name' in query:
        try:
            obj = Person.objects.get(id=query['name'])
            return DjangoContent(context, context.request, obj)
        except ObjectDoesNotExist:
            return

addRoute('Django Content', '/djangocontent/{name}',
         objectFinder=customDjangoFinder)
    def setUp(self):
        from collective.routes import addRoute

        self.portal = self.layer["portal"]
        self.request = self.layer["request"]
        addRoute(
            "foobar",
            "/{effective:year}/{effective:month}/{effective:day}",
            defaultQuery={"portal_type": "News Item"},
            allowPartialMatch=True,
        )
        addRoute(
            "foobar1",
            "/foobar1/{effective:year}/{effective:month}/{effective:day}",
            defaultQuery={"portal_type": "News Item"},
        )
        addRoute("foobar2", "/foobar2/{Subject}", defaultQuery={"portal_type": "News Item"})
        addRoute(
            "customBreadcrumbs",
            "/foobar3",
            defaultQuery={"portal_type": "News Item", "effectiveDate": "2010/10/10"},
            breadcrumbFactory=customBreadcrumbFactory,
        )
        addRoute(
            "customPredicate",
            "/customPredicate",
            defaultQuery={"portal_type": "News Item", "effectiveDate": "2010/10/10"},
            customPredicates=customPredicate,
        )
        addRoute(
            "foobar4",
            "/foobar4/{effective:year}/{effective:month}/{effective:day}",
            defaultQuery={"portal_type": "News Item"},
            allowPartialMatch=False,
        )
        folder = createObject(self.portal, "Folder", "folder")
        createObject(folder, "News Item", "test1", title="Test 1", effectiveDate="2010/10/10")
        createObject(folder, "News Item", "test2", title="Test 2", effectiveDate="2010/10/09", subject=("foobar",))
        self.activateRoutes()

        transaction.commit()
        self.browser = Browser(self.layer["app"])
        self.browser.handleErrors = False
        browserLogin(self.portal, self.browser)
    def setUp(self):
        from collective.routes import addRoute
        self.portal = self.layer['portal']
        self.request = self.layer['request']
        addRoute('foobar',
                 '/{effective:year}/{effective:month}/{effective:day}',
                 defaultQuery={'portal_type': 'News Item'},
                 allowPartialMatch=True)
        addRoute('foobar1',
                 '/foobar1/{effective:year}/{effective:month}/{effective:day}',
                 defaultQuery={'portal_type': 'News Item'})
        addRoute('foobar2',
                 '/foobar2/{Subject}',
                 defaultQuery={'portal_type': 'News Item'})
        addRoute('customBreadcrumbs', '/foobar3',
                 defaultQuery={'portal_type': 'News Item',
                               'effectiveDate': '2010/10/10'},
                 breadcrumbFactory=customBreadcrumbFactory)
        addRoute('customPredicate', '/customPredicate',
                 defaultQuery={'portal_type': 'News Item',
                               'effectiveDate': '2010/10/10'},
                 customPredicates=customPredicate)
        addRoute('foobar4',
                 '/foobar4/{effective:year}/{effective:month}/{effective:day}',
                 defaultQuery={'portal_type': 'News Item'},
                 allowPartialMatch=False)
        folder = createObject(self.portal, 'Folder', 'folder')
        createObject(folder, 'News Item', 'test1',
            title="Test 1", effectiveDate="2010/10/10")
        createObject(folder, 'News Item', 'test2',
            title="Test 2", effectiveDate="2010/10/09", subject=('foobar',))
        self.activateRoutes()

        transaction.commit()
        self.browser = Browser(self.layer['app'])
        self.browser.handleErrors = False
        browserLogin(self.portal, self.browser)