forked from ptahproject/devel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alan runyan
committed
Oct 10, 2011
1 parent
1258cef
commit f3ca62b
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" This is an example of running Ptah in 1 module. """ | ||
|
||
import cgi | ||
from paste.httpserver import serve | ||
from memphis import view | ||
import ptah | ||
import ptah_cms | ||
|
||
view.registerRoute('show_models', '/show_models') | ||
|
||
@view.pyramidView(route='show_models') | ||
def show_models(request): | ||
from ptah_cms import Session, Content | ||
models = Session.query(Content).all() | ||
return cgi.escape(str(models)) | ||
|
||
@view.pyramidView('show_info', context=ptah_cms.Content) | ||
def show_info(context, request): | ||
return cgi.escape(str(context.info())) | ||
|
||
@view.pyramidView('list_children', context=ptah_cms.Container) | ||
def list_children(context, request): | ||
out = [] | ||
for name, child in context.items(): | ||
if isinstance(child, ptah_cms.Container): | ||
href = '<a href="%slist_children">%s</a>' #XXX extra /? | ||
href = href % (request.resource_url(child), child.title) | ||
else: | ||
href = '<a href="%sshow_info">%s</a>' | ||
href = href % (request.resource_url(child), child.title) | ||
out.append(href) | ||
return '<br />'.join(out) | ||
|
||
if __name__ == '__main__': | ||
""" need to point to your settings.ini file in make_wsgi_app call. | ||
http://localhost:8080/show_models is url dispatch function. | ||
http://localhost:8080/list_children is traverser on context | ||
$resource_url/show_info on either folder or content. | ||
""" | ||
app = ptah.make_wsgi_app({'settings':r'./ptah.ini'}) | ||
serve(app, host='0.0.0.0') |