[Checkins] SVN: grokapps/trajectrdbexample/ Initial import.
Martijn Faassen
faassen at startifact.com
Mon Jan 18 16:08:39 EST 2010
Log message for revision 108233:
Initial import.
Changed:
A grokapps/trajectrdbexample/
A grokapps/trajectrdbexample/trunk/
A grokapps/trajectrdbexample/trunk/bootstrap.py
A grokapps/trajectrdbexample/trunk/buildout.cfg
A grokapps/trajectrdbexample/trunk/etc/
A grokapps/trajectrdbexample/trunk/etc/README.txt
A grokapps/trajectrdbexample/trunk/etc/debug.ini.in
A grokapps/trajectrdbexample/trunk/etc/deploy.ini.in
A grokapps/trajectrdbexample/trunk/etc/site.zcml.in
A grokapps/trajectrdbexample/trunk/etc/zdaemon.conf.in
A grokapps/trajectrdbexample/trunk/etc/zope.conf.in
A grokapps/trajectrdbexample/trunk/setup.py
A grokapps/trajectrdbexample/trunk/src/
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/__init__.py
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app.py
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app.txt
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/departmentindex.pt
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/departmentsindex.pt
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/facultyindex.pt
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/trajectrdbexampleindex.pt
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/configure.zcml
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/db.py
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/ftesting.zcml
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/static/
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/static/README.txt
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/tests.py
A grokapps/trajectrdbexample/trunk/src/trajectrdbexample/url.py
A grokapps/trajectrdbexample/trunk/versions.cfg
-=-
Added: grokapps/trajectrdbexample/trunk/bootstrap.py
===================================================================
--- grokapps/trajectrdbexample/trunk/bootstrap.py (rev 0)
+++ grokapps/trajectrdbexample/trunk/bootstrap.py 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,84 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 85041 2008-03-31 15:57:30Z andreasjung $
+"""
+
+import os, shutil, sys, tempfile, urllib2, logging
+
+def remove_old_logger_handlers():
+ # zc.buildout installs a new log stream on every call of
+ # main(). We remove any leftover handlers to avoid multiple output
+ # of same content (doubled lines etc.)
+ root_logger = logging.getLogger()
+ if 'zc.buildout' in root_logger.manager.loggerDict.keys():
+ logger = logging.getLogger('zc.buildout')
+ for handler in logger.handlers:
+ logger.removeHandler(handler)
+ return
+
+
+tmpeggs = tempfile.mkdtemp()
+
+try:
+ import pkg_resources
+except ImportError:
+ ez = {}
+ exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+ import pkg_resources
+
+if sys.platform == 'win32':
+ def quote(c):
+ if ' ' in c:
+ return '"%s"' % c # work around spawn lamosity on windows
+ else:
+ return c
+else:
+ def quote (c):
+ return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws = pkg_resources.working_set
+assert os.spawnle(
+ os.P_WAIT, sys.executable, quote (sys.executable),
+ '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout',
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse('setuptools')).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+remove_old_logger_handlers()
+shutil.rmtree(tmpeggs)
+
+# grokproject specific addition to standard bootstrap.py:
+# Install eggbasket too. This should be verbose to give the user
+# information about what is happening, since this can take a while.
+zc.buildout.buildout.main(sys.argv[1:] + ['-v', 'install', 'eggbasket'])
+if sys.platform == 'win32':
+ print "Now you can run 'bin\buildout.exe'"
+else:
+ print "Now you can run 'bin/buildout'"
Added: grokapps/trajectrdbexample/trunk/buildout.cfg
===================================================================
--- grokapps/trajectrdbexample/trunk/buildout.cfg (rev 0)
+++ grokapps/trajectrdbexample/trunk/buildout.cfg 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,109 @@
+[buildout]
+develop = .
+parts =
+ eggbasket
+ app
+ i18n
+ test
+ mkdirs
+ zpasswd
+ zope_conf
+ site_zcml
+ zdaemon_conf
+ deploy_ini
+ debug_ini
+# For backward compatibility, telling buildout not to throw away
+# the data and log subdirectories from the parts directory.
+ data
+ log
+newest = false
+
+extends = versions.cfg
+# eggs will be installed in the default buildout location
+# (see .buildout/default.cfg in your home directory)
+# unless you specify an eggs-directory option here.
+
+versions = versions
+
+[app]
+recipe = zc.recipe.egg
+eggs = trajectrdbexample
+ z3c.evalexception>=2.0
+ Paste
+ PasteScript
+ PasteDeploy
+interpreter = python-console
+
+[mkdirs]
+recipe = z3c.recipe.mkdir
+paths =
+ ${zope_conf:filestorage}
+ ${zope_conf:logfiles}
+ ${zope_conf:blobstorage}
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = trajectrdbexample
+defaults = ['--tests-pattern', '^f?tests$', '-v']
+
+# this section named so that the i18n scripts are called bin/i18n...
+[i18n]
+recipe = z3c.recipe.i18n:i18n
+packages = trajectrdbexample
+eggs = trajectrdbexample
+domain = trajectrdbexample
+output = src/trajectrdbexample/locales
+zcml =
+
+# This section is named so that the zpasswd utility is
+# called `zpasswd`
+[zpasswd]
+recipe = z3c.recipe.dev:script
+eggs = trajectrdbexample
+module = zope.app.server.zpasswd
+method = main
+
+[zope_conf]
+recipe = collective.recipe.template
+input = etc/zope.conf.in
+output = ${buildout:parts-directory}/etc/zope.conf
+filestorage = ${buildout:directory}/var/filestorage
+blobstorage = ${buildout:directory}/var/blobstorage
+logfiles = ${buildout:directory}/var/log
+extra =
+# 'extra' is copied verbatim. Use it for product config sections and so.
+
+# The [data] and [log] parts are still in here to instruct buildout to not
+# unintentionally throw away the parts/data and parts/log subdirectories
+# that contain the Data.fs and the log files. These files should be
+# copied to the new locations. See the upgrade notes for more information.
+[data]
+recipe = zc.recipe.filestorage
+
+[log]
+recipe = zc.recipe.filestorage
+
+[site_zcml]
+recipe = collective.recipe.template
+input = etc/site.zcml.in
+output = ${buildout:parts-directory}/etc/site.zcml
+
+[zdaemon_conf]
+recipe = collective.recipe.template
+input = etc/zdaemon.conf.in
+output = ${buildout:parts-directory}/etc/zdaemon.conf
+
+[deploy_ini]
+recipe = collective.recipe.template
+input = etc/deploy.ini.in
+output = ${buildout:parts-directory}/etc/deploy.ini
+
+[debug_ini]
+recipe = collective.recipe.template
+input = etc/debug.ini.in
+output = ${buildout:parts-directory}/etc/debug.ini
+
+[eggbasket]
+recipe = z3c.recipe.eggbasket
+eggs = grok
+url = http://grok.zope.org/releaseinfo/grok-eggs-1.0.tgz
Added: grokapps/trajectrdbexample/trunk/etc/README.txt
===================================================================
--- grokapps/trajectrdbexample/trunk/etc/README.txt (rev 0)
+++ grokapps/trajectrdbexample/trunk/etc/README.txt 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,26 @@
+In this directory you can find templates which are used by
+``zc.buildout`` to create the configuration files in the parts/etc/ subdir
+of your project.
+
+If you modify files in this directory, you have to run::
+
+ $ bin/buildout
+
+afterwards to rebuild the configuration files in parts/etc/.
+
+In the templates you can use placesholders recognized by zc.buildout
+to name local paths, etc. A zc.buildout placeholder looks like this::
+
+ ${buildout:directory}
+
+which gives you the path of the project directory and will be
+substituted with the real path when you run buildout the next
+time. The set of available placeholders depends on your
+buildout.cfg.
+
+You can also modify files in parts/etc directly, but those changes
+will be overwritten after running bin/buildout the next time.
+
+To run your project you can do::
+
+ $ bin/paster serve parts/etc/deploy.ini
Added: grokapps/trajectrdbexample/trunk/etc/debug.ini.in
===================================================================
--- grokapps/trajectrdbexample/trunk/etc/debug.ini.in (rev 0)
+++ grokapps/trajectrdbexample/trunk/etc/debug.ini.in 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,67 @@
+# debug.ini
+#
+# Debugging configuration for use with paster/WSGI
+#
+
+[loggers]
+keys = root, wsgi
+
+[handlers]
+keys = console, accesslog
+
+[formatters]
+keys = generic, accesslog
+
+[formatter_generic]
+format = %(asctime)s %(levelname)s [%(name)s] %(message)s
+
+[formatter_accesslog]
+format = %(message)s
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[handler_accesslog]
+class = FileHandler
+args = (os.path.join(r'${zope_conf:logfiles}', 'access.log'),
+ 'a')
+level = INFO
+formatter = accesslog
+
+[logger_root]
+level = INFO
+handlers = console
+
+[logger_wsgi]
+level = INFO
+handlers = accesslog
+qualname = wsgi
+propagate = 0
+
+[filter:translogger]
+use = egg:Paste#translogger
+setup_console_handler = False
+logger_name = wsgi
+
+[filter-app:main]
+# Change the last part from 'ajax' to 'pdb' for a post-mortem debugger
+# on the console:
+use = egg:z3c.evalexception#ajax
+next = zope
+
+[app:zope]
+use = egg:trajectrdbexample#debug
+filter-with = translogger
+exempt-exceptions = zope.security.interfaces.IUnauthorized
+
+[server:main]
+use = egg:Paste#http
+host = 127.0.0.1
+port = 8080
+
+[DEFAULT]
+# set the name of the zope.conf file
+zope_conf = %(here)s/zope.conf
\ No newline at end of file
Added: grokapps/trajectrdbexample/trunk/etc/deploy.ini.in
===================================================================
--- grokapps/trajectrdbexample/trunk/etc/deploy.ini.in (rev 0)
+++ grokapps/trajectrdbexample/trunk/etc/deploy.ini.in 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,60 @@
+# deploy.ini
+#
+# Deployment configuration for use with paster/WSGI
+#
+
+[loggers]
+keys = root, wsgi
+
+[handlers]
+keys = console, accesslog
+
+[formatters]
+keys = generic, accesslog
+
+[logger_root]
+level = INFO
+handlers = console
+
+[logger_wsgi]
+level = INFO
+handlers = accesslog
+qualname = wsgi
+propagate = 0
+
+[handler_console]
+class = StreamHandler
+args = (sys.stderr,)
+level = NOTSET
+formatter = generic
+
+[handler_accesslog]
+class = FileHandler
+args = (os.path.join(r'${zope_conf:logfiles}', 'access.log'),
+ 'a')
+level = INFO
+formatter = accesslog
+
+[formatter_generic]
+format = %(asctime)s %(levelname)s [%(name)s] %(message)s
+
+[formatter_accesslog]
+format = %(message)s
+
+[filter:translogger]
+use = egg:Paste#translogger
+setup_console_handler = False
+logger_name = wsgi
+
+[app:main]
+use = egg:trajectrdbexample
+filter-with = translogger
+
+[server:main]
+use = egg:Paste#http
+host = 127.0.0.1
+port = 8080
+
+[DEFAULT]
+# set the name of the zope.conf file
+zope_conf = %(here)s/zope.conf
Added: grokapps/trajectrdbexample/trunk/etc/site.zcml.in
===================================================================
--- grokapps/trajectrdbexample/trunk/etc/site.zcml.in (rev 0)
+++ grokapps/trajectrdbexample/trunk/etc/site.zcml.in 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,36 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="trajectrdbexample">
+
+ <include package="trajectrdbexample" />
+
+ <configure i18n_domain="trajectrdbexample">
+
+ <unauthenticatedPrincipal id="zope.anybody"
+ title="Unauthenticated User" />
+ <unauthenticatedGroup id="zope.Anybody"
+ title="Unauthenticated Users" />
+ <authenticatedGroup id="zope.Authenticated"
+ title="Authenticated Users" />
+ <everybodyGroup id="zope.Everybody"
+ title="All Users" />
+ <principal id="zope.manager"
+ title="Manager"
+ login="admin"
+ password_manager="SHA1"
+ password="596fd15ed033e22ae348aeb5660fc2140aec35850c4da997"
+ />
+
+ <!-- Replace the following directive if you do not want
+ public access -->
+ <grant permission="zope.View"
+ principal="zope.Anybody" />
+ <grant permission="zope.app.dublincore.view"
+ principal="zope.Anybody" />
+
+ <role id="zope.Manager" title="Site Manager" />
+ <role id="zope.Member" title="Site Member" />
+ <grantAll role="zope.Manager" />
+ <grant role="zope.Manager"
+ principal="zope.manager" />
+ </configure>
+</configure>
Added: grokapps/trajectrdbexample/trunk/etc/zdaemon.conf.in
===================================================================
--- grokapps/trajectrdbexample/trunk/etc/zdaemon.conf.in (rev 0)
+++ grokapps/trajectrdbexample/trunk/etc/zdaemon.conf.in 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,8 @@
+<runner>
+ program bin/paster serve ${buildout:directory}/parts/etc/deploy.ini
+ daemon on
+ transcript ${zope_conf:logfiles}/zdaemon.log
+ socket-name ${zope_conf:logfiles}/zdaemonsock
+ # Enable this to run the child process as a different user
+ # user zope
+</runner>
Added: grokapps/trajectrdbexample/trunk/etc/zope.conf.in
===================================================================
--- grokapps/trajectrdbexample/trunk/etc/zope.conf.in (rev 0)
+++ grokapps/trajectrdbexample/trunk/etc/zope.conf.in 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,55 @@
+# Identify the component configuration used to define the site:
+site-definition ${site_zcml:output}
+
+<zodb>
+ # Standard blob storage
+ <blobstorage>
+ blob-dir ${zope_conf:blobstorage}
+ <filestorage>
+ path ${zope_conf:filestorage}/Data.fs
+ </filestorage>
+ </blobstorage>
+
+# Uncomment this if you want a blob-less standard file storage instead:
+# <filestorage>
+# path ${zope_conf:filestorage}
+# </filestorage>
+
+# Uncomment this if you want to connect to a ZEO server instead:
+# <zeoclient>
+# server localhost:8100
+# storage 1
+# # ZEO client cache, in bytes
+# cache-size 20MB
+# # Uncomment to have a persistent disk cache
+# #client zeo1
+# </zeoclient>
+
+</zodb>
+
+<eventlog>
+ # This sets up logging to a file.
+ # The "path" setting can be a relative or absolute
+ # filesystem path.
+
+ <logfile>
+ path ${zope_conf:logfiles}/z3.log
+ formatter zope.exceptions.log.Formatter
+ </logfile>
+
+ # This sets up logging to to standard output.
+ # The "path" setting can be the tokens STDOUT or STDERR
+
+# <logfile>
+# path STDOUT
+# formatter zope.exceptions.log.Formatter
+# </logfile>
+</eventlog>
+
+# Comment this line to disable developer mode. This should be done in
+# production
+devmode on
+
+# Extra configuration lines can be added to zope_conf's extra option. Put for
+# instance productconf sections in here.
+${zope_conf:extra}
Added: grokapps/trajectrdbexample/trunk/setup.py
===================================================================
--- grokapps/trajectrdbexample/trunk/setup.py (rev 0)
+++ grokapps/trajectrdbexample/trunk/setup.py 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,39 @@
+from setuptools import setup, find_packages
+
+version = '0.0'
+
+setup(name='trajectrdbexample',
+ version=version,
+ description="",
+ long_description="""\
+""",
+ # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
+ classifiers=[],
+ keywords="",
+ author="",
+ author_email="",
+ url="",
+ license="",
+ package_dir={'': 'src'},
+ packages=find_packages('src'),
+ include_package_data=True,
+ zip_safe=False,
+ install_requires=['setuptools',
+ 'grok',
+ 'grokui.admin',
+ 'z3c.testsetup',
+ 'grokcore.startup',
+ 'megrok.traject',
+ 'z3c.saconfig',
+ 'zope.schema',
+ # Add extra requirements here
+ ],
+ entry_points = """
+ [console_scripts]
+ trajectrdbexample-debug = grokcore.startup:interactive_debug_prompt
+ trajectrdbexample-ctl = grokcore.startup:zdaemon_controller
+ [paste.app_factory]
+ main = grokcore.startup:application_factory
+ debug = grokcore.startup:debug_application_factory
+ """,
+ )
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/__init__.py
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/__init__.py (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/__init__.py 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1 @@
+# this directory is a package
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app.py
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app.py (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app.py 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,125 @@
+"""This module sets up views for models to publish them to the web.
+
+We also define the non-persistent Departments object.
+
+See db.py for the relational database configuration,
+and url.py for the URL configuration.
+"""
+
+import grok
+from megrok import traject
+from z3c.saconfig import Session
+from zope.interface import Interface
+from zope import schema
+
+from trajectrdbexample import db
+
+class IFaculty(Interface):
+ title = schema.TextLine(title=u"Title")
+
+class IDepartment(Interface):
+ title = schema.TextLine(title=u"Title")
+
+class TrajectRDBExample(grok.Application, grok.Model):
+ pass
+
+class TrajectRDBExampleIndex(grok.View):
+ """The index page. This shows all faculties available.
+ """
+ grok.name('index')
+ grok.context(TrajectRDBExample)
+
+ def faculties(self):
+ session = Session()
+ site = grok.getSite()
+ for faculty in session.query(db.Faculty):
+ # we must locate the faculty before we can do
+ # security checks on it or get its URL.
+ # locating means it'll get a __parent__ and __name__
+ # attribute. See auto-locate adapter below though.
+ traject.locate(site, faculty, None)
+ yield faculty
+
+class AddFaculty(grok.AddForm):
+ grok.context(TrajectRDBExample)
+
+ form_fields = grok.Fields(IFaculty)
+
+ @grok.action('add')
+ def handle_add(self, *args, **kw):
+ faculty = db.Faculty(**kw)
+ session = Session()
+ session.add(faculty)
+ self.redirect(self.url(self.context))
+
+class FacultyIndex(grok.View):
+ """This is the default view for Faculty.
+ """
+ grok.name('index')
+ grok.context(db.Faculty)
+
+class Departments(grok.Context):
+ """This non-persistent object exists to attach views to it.
+
+ It could also grow knowledge about how to query and add departments.
+ """
+ def __init__(self, faculty_id):
+ self.faculty_id = faculty_id
+
+ def departments(self):
+ # we must locate again
+ # the context is the site object
+ site = grok.getSite()
+ for department in self.__parent__.departments:
+ traject.locate(site, department, None)
+ yield department
+
+class AddDepartment(grok.AddForm):
+ grok.context(Departments)
+
+ form_fields = grok.Fields(IDepartment)
+
+ @grok.action('add')
+ def handle_add(self, *args, **kw):
+ department = db.Department(**kw)
+ self.context.__parent__.departments.append(department)
+ # also could do:
+ # department.faculty_id = self.context.faculty_id
+
+ self.redirect(self.url(self.context))
+
+class DepartmentsIndex(grok.View):
+ grok.name('index')
+ grok.context(Departments)
+
+class DepartmentIndex(grok.View):
+ grok.name('index')
+ grok.context(db.Department)
+
+# Example of an adapter to auto-locate models.
+# this is one for db.Faculty.
+
+# If your models have a common base class or interface, you can
+# register an absolute URL adapter for all in one go.
+
+# Note that you'll still need to locate before doing security checks
+# on objects.
+
+# from zope.traversing.browser.interfaces import IAbsoluteURL
+# from zope.traversing.browser import AbsoluteURL
+# from zope.publisher.interfaces.http import IHTTPRequest
+
+# class TrajectAbsoluteURL(AbsoluteURL, grok.MultiAdapter):
+# """Make sure that our objects can have absolute URLs.
+
+# This can be done by using traject to locate them and then just
+# generating the URL as normal.
+# """
+# grok.provides(IAbsoluteURL)
+# grok.adapts(db.Faculty, IHTTPRequest)
+
+# def __str__(self):
+# traject.locate(grok.getSite(), self.context, None)
+# return super(TrajectAbsoluteURL, self).__str__()
+
+# __call__ = __str__
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app.txt
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app.txt (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app.txt 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,32 @@
+Do a functional doctest test on the app.
+========================================
+
+:Test-Layer: functional
+
+Let's first create an instance of Trajectrdbexample at the top level:
+
+ >>> from trajectrdbexample.app import Trajectrdbexample
+ >>> root = getRootFolder()
+ >>> root['app'] = Trajectrdbexample()
+
+
+Run tests in the testbrowser
+----------------------------
+
+The zope.testbrowser.browser module exposes a Browser class that
+simulates a web browser similar to Mozilla Firefox or IE. We use that
+to test how our application behaves in a browser. For more
+information, see http://pypi.python.org/pypi/zope.testbrowser.
+
+Create a browser and visit the instance you just created:
+
+ >>> from zope.testbrowser.testing import Browser
+ >>> browser = Browser()
+ >>> browser.open('http://localhost/app')
+
+Check some basic information about the page you visit:
+
+ >>> browser.url
+ 'http://localhost/app'
+ >>> browser.headers.get('Status').upper()
+ '200 OK'
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/departmentindex.pt
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/departmentindex.pt (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/departmentindex.pt 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,5 @@
+<html>
+<body>
+<h2>Department <span tal:content="context/title"></span></h2>
+</body>
+</html>
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/departmentsindex.pt
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/departmentsindex.pt (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/departmentsindex.pt 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,15 @@
+<html>
+<body>
+<h3>Departments of faculty <span tal:replace="context/__parent__/title"></span></h3>
+<ul>
+ <li tal:repeat="department context/departments">
+ <a tal:attributes="href python:view.url(department)"
+ tal:content="department/title"></a>
+ </li>
+</ul>
+
+<p>
+ <a tal:attributes="href python:view.url('@@adddepartment')">Add Department</a>
+</p>
+</body>
+</html>
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/facultyindex.pt
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/facultyindex.pt (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/facultyindex.pt 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,11 @@
+<html>
+<body>
+<h2>Faculty <span tal:content="context/title"></span></h2>
+<h3>Departments</h3>
+
+<p>
+ <a tal:attributes="href python:view.url('departments')">Departments</a>
+</p>
+
+</body>
+</html>
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/trajectrdbexampleindex.pt
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/trajectrdbexampleindex.pt (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/app_templates/trajectrdbexampleindex.pt 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,14 @@
+<html>
+<body>
+<h2>Traject RDB Example</h2>
+<h3>Faculty listing</h3>
+<ul>
+ <li tal:repeat="faculty view/faculties">
+ <a tal:attributes="href python:view.url(faculty)" tal:content="python:faculty.title"></a>
+ </li>
+</ul>
+<p>
+ <a tal:attributes="href python:view.url('@@addfaculty')">Add Faculty</a>
+</p>
+</body>
+</html>
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/configure.zcml
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/configure.zcml (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/configure.zcml 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,6 @@
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:grok="http://namespaces.zope.org/grok">
+ <include package="grok" />
+ <includeDependencies package="." />
+ <grok:grok package="." />
+</configure>
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/db.py
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/db.py (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/db.py 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,76 @@
+"""
+This module sets up the database, tables and models using SQLAlchemy
+and z3c.saconfig.
+"""
+
+# we don't need to depend on Grok, just on grokcore.component
+import grokcore.component as grok
+
+from sqlalchemy.schema import Table, Column, ForeignKey
+from sqlalchemy.types import Integer, String
+from sqlalchemy.orm import mapper, relation, backref
+from sqlalchemy import MetaData
+
+from z3c.saconfig import EngineFactory, GloballyScopedSession
+from z3c.saconfig.interfaces import IEngineCreatedEvent
+
+# we set up the engine factory and the session
+# we set them up as global utilities here. It is also possible to
+# use a local engine factory and a special locally scoped session
+# XXX for some reason it fails to work properly with a :memory: database
+TEST_DSN = 'sqlite:///test.db'
+
+engine_factory = EngineFactory(TEST_DSN)
+scoped_session = GloballyScopedSession()
+
+grok.global_utility(engine_factory, direct=True)
+grok.global_utility(scoped_session, direct=True)
+
+metadata = MetaData()
+
+ at grok.subscribe(IEngineCreatedEvent)
+def setUpDatabase(event):
+ # automatically create all tables if necessary as soon
+ # as we first try to contact the database
+ metadata.create_all(bind=event.engine)
+
+# we sketch out a fully explicit SQLAlchemy ORM mapping
+# the idea is to show that we can expose objects that are defined
+# without knowledge of how they will appear on the web, using megrok.traject
+
+faculty = Table(
+ 'faculty', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('title', String(50)))
+
+department = Table(
+ 'department', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('title', String(50), unique=True),
+ Column('faculty_id', Integer, ForeignKey('faculty.id')))
+
+# it is possible to make this work without depending on
+# grokcore.component (or Grok) at all. In this case, in a Grok application be
+# aware that the browser default view for non-Grok objects is
+# index.html, *not* index. You can turn your own objects into
+# using 'index' by the following ZCML:
+#
+# <browser:defaultView for="my.Model" name="index" />
+#
+# In addition, Grok won't auto-associate views with your model
+# and you have to use an explicit grok.context()
+
+class Faculty(grok.Context):
+ def __init__(self, title):
+ self.title = title
+
+class Department(grok.Context):
+ def __init__(self, title):
+ self.title = title
+
+mapper(Faculty, faculty, properties={
+ 'departments': relation(
+ Department, backref=backref('faculty')),
+ })
+
+mapper(Department, department)
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/ftesting.zcml
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/ftesting.zcml (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/ftesting.zcml 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,34 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="trajectrdbexample"
+ package="trajectrdbexample"
+ >
+
+ <include package="trajectrdbexample" />
+
+ <!-- Typical functional testing security setup -->
+ <securityPolicy
+ component="zope.securitypolicy.zopepolicy.ZopeSecurityPolicy"
+ />
+
+ <unauthenticatedPrincipal
+ id="zope.anybody"
+ title="Unauthenticated User"
+ />
+ <grant
+ permission="zope.View"
+ principal="zope.anybody"
+ />
+
+ <principal
+ id="zope.mgr"
+ title="Manager"
+ login="mgr"
+ password="mgrpw"
+ />
+
+ <role id="zope.Manager" title="Site Manager" />
+ <grantAll role="zope.Manager" />
+ <grant role="zope.Manager" principal="zope.mgr" />
+
+</configure>
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/static/README.txt
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/static/README.txt (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/static/README.txt 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,2 @@
+Put static files here, like javascript and css. They will be
+available as static/<filename> in views.
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/tests.py
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/tests.py (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/tests.py 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,12 @@
+import os.path
+import z3c.testsetup
+import trajectrdbexample
+from zope.app.testing.functional import ZCMLLayer
+
+
+ftesting_zcml = os.path.join(
+ os.path.dirname(trajectrdbexample.__file__), 'ftesting.zcml')
+FunctionalLayer = ZCMLLayer(ftesting_zcml, __name__, 'FunctionalLayer',
+ allow_teardown=True)
+
+test_suite = z3c.testsetup.register_all_tests('trajectrdbexample')
Added: grokapps/trajectrdbexample/trunk/src/trajectrdbexample/url.py
===================================================================
--- grokapps/trajectrdbexample/trunk/src/trajectrdbexample/url.py (rev 0)
+++ grokapps/trajectrdbexample/trunk/src/trajectrdbexample/url.py 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,53 @@
+"""
+This module tells megrok.traject how to map URLs to ORM-backed objects
+and the non-persistent Departments object.
+"""
+
+import grok
+
+from z3c.saconfig import Session
+from sqlalchemy import and_
+from megrok import traject
+
+from trajectrdbexample.app import TrajectRDBExample, Departments
+from trajectrdbexample import db
+
+grok.context(TrajectRDBExample)
+
+class FacultyTraject(traject.Traject):
+ pattern = ':faculty_id:int'
+ model = db.Faculty
+
+ def factory(faculty_id):
+ session = Session()
+ return session.query(db.Faculty).filter(
+ db.Faculty.id == faculty_id).first()
+
+ def arguments(model):
+ return {'faculty_id': model.id}
+
+class DepartmentsTraject(traject.Traject):
+ pattern = ':faculty_id:int/departments'
+ model = Departments
+
+ def factory(faculty_id):
+ return Departments(faculty_id)
+
+ def arguments(model):
+ return {'faculty_id': model.faculty_id}
+
+class DepartmentTraject(traject.Traject):
+ # we browse to departments using the title attribute of
+ # Department, which is assumed (or constrained) to be unique.
+ pattern = ':faculty_id:int/departments/:department_title:str'
+ model = db.Department
+
+ def factory(faculty_id, department_title):
+ session = Session()
+ return session.query(db.Department).filter(
+ and_(db.Department.faculty_id == faculty_id,
+ db.Department.title == department_title)).first()
+
+ def arguments(model):
+ return {'faculty_id': model.faculty.id,
+ 'department_title': model.title}
Added: grokapps/trajectrdbexample/trunk/versions.cfg
===================================================================
--- grokapps/trajectrdbexample/trunk/versions.cfg (rev 0)
+++ grokapps/trajectrdbexample/trunk/versions.cfg 2010-01-18 21:08:38 UTC (rev 108233)
@@ -0,0 +1,137 @@
+# This file contains a list of versions of the various grok modules that
+# belong together.
+# It was downloaded from http://grok.zope.org/releaseinfo/grok-1.0.cfg
+# when this project was created.
+
+[versions]
+grok = 1.0
+ClientForm = 0.2.9
+grokcore.component = 1.7
+grokcore.formlib = 1.4
+grokcore.security = 1.2
+grokcore.startup = 0.4
+grokcore.view = 1.12.2
+grokcore.viewlet = 1.3
+grokui.admin = 0.3.2
+martian = 0.11.1
+mechanize = 0.1.7b
+pytz = 2009l
+RestrictedPython = 3.4.2
+simplejson = 2.0.9
+z3c.autoinclude = 0.2.2
+z3c.flashmessage = 1.0
+z3c.recipe.eggbasket = 0.4.3
+z3c.testsetup = 0.4
+zc.catalog = 1.2.0
+ZConfig = 2.5.1
+zc.recipe.testrunner = 1.0.0
+zdaemon = 2.0.2
+ZODB3 = 3.8.3
+zodbcode = 3.4.0
+zope.annotation = 3.4.1
+zope.app.apidoc = 3.4.3
+zope.app.applicationcontrol = 3.4.3
+zope.app.appsetup = 3.4.1
+zope.app.authentication = 3.4.4
+zope.app.basicskin = 3.4.0
+zope.app.broken = 3.4.0
+zope.app.catalog = 3.5.1
+zope.app.component = 3.4.1
+zope.app.container = 3.5.6
+zope.app.content = 3.4.0
+zope.app.debug = 3.4.1
+zope.app.dependable = 3.4.0
+zope.app.error = 3.5.1
+zope.app.exception = 3.4.1
+zope.app.file = 3.4.4
+zope.app.folder = 3.4.0
+zope.app.form = 3.4.1
+zope.app.generations = 3.4.1
+zope.app.http = 3.4.1
+zope.app.i18n = 3.4.4
+zope.app.interface = 3.4.0
+zope.app.intid = 3.4.1
+zope.app.keyreference = 3.4.1
+zope.app.locales = 3.4.5
+zope.app.onlinehelp = 3.4.1
+zope.app.pagetemplate = 3.4.1
+zope.app.preference = 3.4.1
+zope.app.principalannotation = 3.4.0
+zope.app.publication = 3.4.3
+zope.app.publisher = 3.5.1
+zope.app.renderer = 3.4.0
+zope.app.rotterdam = 3.4.1
+zope.app.schema = 3.4.0
+zope.app.security = 3.5.2
+zope.app.securitypolicy = 3.4.6
+zope.app.server = 3.4.2
+zope.app.session = 3.5.1
+zope.app.skins = 3.4.0
+zope.app.testing = 3.4.3
+zope.app.tree = 3.4.0
+zope.app.twisted = 3.4.1
+zope.app.wsgi = 3.4.2
+zope.app.zapi = 3.4.0
+zope.app.zcmlfiles = 3.4.3
+zope.app.zopeappgenerations = 3.4.0
+zope.cachedescriptors = 3.4.1
+zope.component = 3.4.0
+zope.configuration = 3.4.0
+zope.contentprovider = 3.4.0
+zope.contenttype = 3.4.0
+zope.copypastemove = 3.4.0
+zope.datetime = 3.4.0
+zope.deferredimport = 3.4.0
+zope.deprecation = 3.4.0
+zope.dottedname = 3.4.2
+zope.dublincore = 3.4.0
+zope.error = 3.5.1
+zope.event = 3.4.0
+zope.exceptions = 3.4.0
+zope.filerepresentation = 3.4.0
+zope.formlib = 3.4.0
+zope.hookable = 3.4.0
+zope.i18n = 3.4.0
+zope.i18nmessageid = 3.4.3
+zope.index = 3.4.1
+zope.interface = 3.4.1
+zope.lifecycleevent = 3.4.0
+zope.location = 3.4.0
+zope.minmax = 1.1.0
+zope.modulealias = 3.4.0
+zope.pagetemplate = 3.4.0
+zope.proxy = 3.4.2
+zope.publisher = 3.4.9
+zope.schema = 3.4.0
+zope.security = 3.4.1
+zope.securitypolicy = 3.4.1
+zope.server = 3.4.3
+zope.session = 3.4.1
+zope.size = 3.4.0
+zope.structuredtext = 3.4.0
+zope.tal = 3.4.1
+zope.tales = 3.4.0
+zope.testbrowser = 3.4.2
+zope.testing = 3.7.6
+zope.thread = 3.4
+zope.traversing = 3.4.1
+zope.viewlet = 3.4.2
+
+
+# Here we pin the recipes and other packages that are not in the
+# downloaded versions.cfg of grok
+Paste = 1.7.2
+PasteDeploy = 1.3.2
+PasteScript = 1.7.3
+setuptools = 0.6c9
+collective.recipe.template = 1.4.0
+z3c.evalexception = 2.0
+z3c.recipe.dev = 0.5.3
+z3c.recipe.i18n = 0.5.3
+z3c.recipe.mkdir = 0.3.1
+zc.buildout = 1.1.1
+zc.lockfile = 1.0.0
+zc.recipe.egg = 1.1.0
+zc.recipe.filestorage = 1.0.1
+
+
More information about the checkins
mailing list