setup Pylons infrastructure
paster create -t pylons ... paster controller ddportfolio add support for sphinx
This commit is contained in:
parent
0c5816154b
commit
9c800c0ed8
27 changed files with 689 additions and 35 deletions
0
ddportfolioservice/controllers/__init__.py
Normal file
0
ddportfolioservice/controllers/__init__.py
Normal file
13
ddportfolioservice/controllers/ddportfolio.py
Normal file
13
ddportfolioservice/controllers/ddportfolio.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
import logging
|
||||
|
||||
from ddportfolioservice.lib.base import *
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class DdportfolioController(BaseController):
|
||||
|
||||
def index(self):
|
||||
# Return a rendered template
|
||||
# return render('/some/template.mako')
|
||||
# or, Return a response
|
||||
return 'Hello World'
|
41
ddportfolioservice/controllers/error.py
Normal file
41
ddportfolioservice/controllers/error.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
import cgi
|
||||
import os.path
|
||||
|
||||
from paste.urlparser import StaticURLParser
|
||||
from pylons.middleware import error_document_template, media_path
|
||||
|
||||
from ddportfolioservice.lib.base import *
|
||||
|
||||
class ErrorController(BaseController):
|
||||
"""Generates error documents as and when they are required.
|
||||
|
||||
The ErrorDocuments middleware forwards to ErrorController when error
|
||||
related status codes are returned from the application.
|
||||
|
||||
This behaviour can be altered by changing the parameters to the
|
||||
ErrorDocuments middleware in your config/middleware.py file.
|
||||
|
||||
"""
|
||||
def document(self):
|
||||
"""Render the error document"""
|
||||
page = error_document_template % \
|
||||
dict(prefix=request.environ.get('SCRIPT_NAME', ''),
|
||||
code=cgi.escape(request.params.get('code', '')),
|
||||
message=cgi.escape(request.params.get('message', '')))
|
||||
return page
|
||||
|
||||
def img(self, id):
|
||||
"""Serve Pylons' stock images"""
|
||||
return self._serve_file(os.path.join(media_path, 'img'), id)
|
||||
|
||||
def style(self, id):
|
||||
"""Serve Pylons' stock stylesheets"""
|
||||
return self._serve_file(os.path.join(media_path, 'style'), id)
|
||||
|
||||
def _serve_file(self, root, path):
|
||||
"""Call Paste's FileApp (a WSGI application) to serve the file
|
||||
at the specified path
|
||||
"""
|
||||
static = StaticURLParser(root)
|
||||
request.environ['PATH_INFO'] = '/%s' % path
|
||||
return static(request.environ, self.start_response)
|
27
ddportfolioservice/controllers/template.py
Normal file
27
ddportfolioservice/controllers/template.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
from ddportfolioservice.lib.base import *
|
||||
|
||||
class TemplateController(BaseController):
|
||||
|
||||
def view(self, url):
|
||||
"""By default, the final controller tried to fulfill the request
|
||||
when no other routes match. It may be used to display a template
|
||||
when all else fails, e.g.::
|
||||
|
||||
def view(self, url):
|
||||
return render('/%s' % url)
|
||||
|
||||
Or if you're using Mako and want to explicitly send a 404 (Not
|
||||
Found) response code when the requested template doesn't exist::
|
||||
|
||||
import mako.exceptions
|
||||
|
||||
def view(self, url):
|
||||
try:
|
||||
return render('/%s' % url)
|
||||
except mako.exceptions.TopLevelLookupException:
|
||||
abort(404)
|
||||
|
||||
By default this controller aborts the request with a 404 (Not
|
||||
Found)
|
||||
"""
|
||||
abort(404)
|
Loading…
Add table
Add a link
Reference in a new issue