def test_static_buildtree(self): from memphis.view.resources import buildTree abspath, pkg = view.path('memphis.view.tests:static/dir2') self.assertEqual(buildTree(abspath), {'style.css': 1, 'text.txt': 1}) # do not include not allowed files abspath, pkg = view.path('memphis.view.tests:static/dir2') self.assertTrue('~test.html' not in buildTree(abspath)) # subtrees abspath, pkg = view.path('memphis.view.tests:static') self.assertEqual(buildTree(abspath), {'dir1/style.css': 1, 'dir1/subdir/text.txt': 1, 'dir1/text2.txt': 1, 'dir2/style.css': 1, 'dir2/text.txt': 1})
from zope.publisher.interfaces.browser import IDefaultBrowserLayer from Acquisition import Implicit from AccessControl import Unauthorized, getSecurityManager from Products.CMFCore.interfaces import ISiteRoot from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from memphis import config, view, form from memphis.controlpanel.interfaces import IConfiglet view.registerLayout( '', IConfiglet, klass = view.ZopeLayout, template = ViewPageTemplateFile( view.path('memphis.controlpanel:templates/layout-prefs.pt')) ) def CheckPermission(factory): def callView(context, request): if getSecurityManager().checkPermission(context.permission, context): return factory(context, request) raise Unauthorized() return callView class LocationProxy(LocationProxy, Implicit): """ location proxy with acquisition """
def initialize(ev): pconfig = ev.config pconfig.add_route('test-welcome', '/welcome.html') pconfig.add_view(route_name='test-welcome', renderer='devapp:welcome.pt') # mount cms to /second/ pconfig.add_route( 'second-app', '/second/*traverse', factory = ptah_cms.ApplicationFactory( '/second/', 'second', 'Test subpath CMS'), use_global_views = True) # mount cms to /third/cms/ pconfig.add_route( 'third-app', '/third/cms/*traverse', factory = ptah_cms.ApplicationFactory( '/third/cms/', 'third-app', 'CMS'), use_global_views = True) # mount cms to /cms/ factory = ptah_cms.ApplicationFactory('/cms/', 'root', 'Ptah CMS') pconfig.add_route( 'root-app', '/cms/*traverse', factory = factory, use_global_views = True) # mount same 'root' application to '/' location factory = ptah_cms.ApplicationFactory( '/', 'root', 'Ptah CMS', policy=ApplicationPolicy) pconfig.add_route( 'root-app2', '/*traverse', factory = factory, use_global_views = True) # some more setup root = factory(None) # admin user user = Session.query(CrowdUser).first() if user is None: user = CrowdUser('Ptah admin','admin','*****@*****.**','12345') Session.add(user) ApplicationPolicy.__local_roles__ = {user.uri: ['role:manager']} # give manager role to admin #if user.uuid not in root.__local_roles__: # root.__local_roles__[user.uuid] = ['role:manager'] #if 'simple-map' not in root.__permissions__: # root.__permissions__ = ['simple-map'] # create default page if 'front-page' not in root.keys(): page = Page(title=u'Welcome to Ptah') page.text = open( view.path('devapp:welcome.pt')[0], 'rb').read() Session.add(page) config.notify(ptah_cms.events.ContentCreatedEvent(page)) root['front-page'] = page # create folder in root if 'folder' not in root.keys(): folder = Folder(title='Test folder') root['folder'] = folder Session.add(folder) config.notify(ptah_cms.events.ContentCreatedEvent(folder)) page = Page(title=u'Welcome to Ptah') page.text = open( view.path('devapp:welcome.pt')[0], 'rb').read() Session.add(page) config.notify(ptah_cms.events.ContentCreatedEvent(page)) folder['front-page'] = page # set default view for folder folder.view = page.__uri__
""" test for static assets api """ import unittest from memphis import config, view from memphis.view import resources from memphis.view.base import View from memphis.view.resources import buildTree from memphis.view.resources import StaticView from base import Base abspath1, pkg1 = view.path('memphis.view.tests:static/dir1') abspath2, pkg2 = view.path('memphis.view.tests:static/dir2') dirinfo1 = buildTree(abspath1) dirinfo2 = buildTree(abspath2) class TestStaticManagement(Base): def _setup_memphis(self): pass def test_static_registration_errors(self): self.assertRaises( ValueError, view.static, 'tests', 'memphis.view.tests:static/unknown---asdad') self.assertRaises( ValueError, view.static, 'tests', 'memphis.view.tests:static/dir1/style.css') def test_static_register(self):
""" $Id: 2007-12-12 12:27:02Z fafhrd $ """ from memphis import view, content from Products.CMFCore.interfaces import ISiteRoot, ITypeInformation from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile view.registerLayout( '', ISiteRoot, klass = view.ZopeLayout, template = ViewPageTemplateFile( view.path('memphis.content:templates/layout-contentcore.pt')) ) view.registerLayout( '', ITypeInformation, klass = view.ZopeLayout, template = ViewPageTemplateFile( view.path('memphis.content:templates/layout-content.pt')) ) view.registerLayout( 'body', content.IContent, klass = view.ZopeLayout, template = ViewPageTemplateFile( view.path('memphis.content:templates/layout-body.pt')) )