* initial checkin
This commit is contained in:
parent
3a553ecbfb
commit
79e3237986
27 changed files with 660 additions and 0 deletions
0
gnuviechadminweb/__init__.py
Normal file
0
gnuviechadminweb/__init__.py
Normal file
0
gnuviechadminweb/config/__init__.py
Normal file
0
gnuviechadminweb/config/__init__.py
Normal file
33
gnuviechadminweb/config/environment.py
Normal file
33
gnuviechadminweb/config/environment.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"""Pylons environment configuration"""
|
||||
import os
|
||||
|
||||
from pylons import config
|
||||
|
||||
import gnuviechadminweb.lib.app_globals as app_globals
|
||||
import gnuviechadminweb.lib.helpers
|
||||
from gnuviechadminweb.config.routing import make_map
|
||||
|
||||
def load_environment(global_conf, app_conf):
|
||||
"""Configure the Pylons environment via the ``pylons.config``
|
||||
object
|
||||
"""
|
||||
# Pylons paths
|
||||
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
paths = dict(root=root,
|
||||
controllers=os.path.join(root, 'controllers'),
|
||||
static_files=os.path.join(root, 'public'),
|
||||
templates=[os.path.join(root, 'templates')])
|
||||
|
||||
# Initialize config with the basic options
|
||||
config.init_app(global_conf, app_conf, package='gnuviechadminweb',
|
||||
template_engine='mako', paths=paths)
|
||||
|
||||
config['routes.map'] = make_map()
|
||||
config['pylons.g'] = app_globals.Globals()
|
||||
config['pylons.h'] = gnuviechadminweb.lib.helpers
|
||||
|
||||
# Customize templating options via this variable
|
||||
tmpl_options = config['buffet.template_options']
|
||||
|
||||
# CONFIGURATION OPTIONS HERE (note: all config options will override
|
||||
# any Pylons config options)
|
||||
57
gnuviechadminweb/config/middleware.py
Normal file
57
gnuviechadminweb/config/middleware.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
"""Pylons middleware initialization"""
|
||||
from paste.cascade import Cascade
|
||||
from paste.registry import RegistryManager
|
||||
from paste.urlparser import StaticURLParser
|
||||
from paste.deploy.converters import asbool
|
||||
|
||||
from pylons import config
|
||||
from pylons.error import error_template
|
||||
from pylons.middleware import error_mapper, ErrorDocuments, ErrorHandler, \
|
||||
StaticJavascripts
|
||||
from pylons.wsgiapp import PylonsApp
|
||||
|
||||
from gnuviechadminweb.config.environment import load_environment
|
||||
|
||||
def make_app(global_conf, full_stack=True, **app_conf):
|
||||
"""Create a Pylons WSGI application and return it
|
||||
|
||||
``global_conf``
|
||||
The inherited configuration for this application. Normally from
|
||||
the [DEFAULT] section of the Paste ini file.
|
||||
|
||||
``full_stack``
|
||||
Whether or not this application provides a full WSGI stack (by
|
||||
default, meaning it handles its own exceptions and errors).
|
||||
Disable full_stack when this application is "managed" by
|
||||
another WSGI middleware.
|
||||
|
||||
``app_conf``
|
||||
The application's local configuration. Normally specified in the
|
||||
[app:<name>] section of the Paste ini file (where <name>
|
||||
defaults to main).
|
||||
"""
|
||||
# Configure the Pylons environment
|
||||
load_environment(global_conf, app_conf)
|
||||
|
||||
# The Pylons WSGI app
|
||||
app = PylonsApp()
|
||||
|
||||
# CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
|
||||
|
||||
if asbool(full_stack):
|
||||
# Handle Python exceptions
|
||||
app = ErrorHandler(app, global_conf, error_template=error_template,
|
||||
**config['pylons.errorware'])
|
||||
|
||||
# Display error documents for 401, 403, 404 status codes (and
|
||||
# 500 when debug is disabled)
|
||||
app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf)
|
||||
|
||||
# Establish the Registry for this application
|
||||
app = RegistryManager(app)
|
||||
|
||||
# Static files
|
||||
javascripts_app = StaticJavascripts()
|
||||
static_app = StaticURLParser(config['pylons.paths']['static_files'])
|
||||
app = Cascade([static_app, javascripts_app, app])
|
||||
return app
|
||||
24
gnuviechadminweb/config/routing.py
Normal file
24
gnuviechadminweb/config/routing.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
"""Routes configuration
|
||||
|
||||
The more specific and detailed routes should be defined first so they
|
||||
may take precedent over the more generic routes. For more information
|
||||
refer to the routes manual at http://routes.groovie.org/docs/
|
||||
"""
|
||||
from pylons import config
|
||||
from routes import Mapper
|
||||
|
||||
def make_map():
|
||||
"""Create, configure and return the routes Mapper"""
|
||||
map = Mapper(directory=config['pylons.paths']['controllers'],
|
||||
always_scan=config['debug'])
|
||||
|
||||
# The ErrorController route (handles 404/500 error pages); it should
|
||||
# likely stay at the top, ensuring it can always be resolved
|
||||
map.connect('error/:action/:id', controller='error')
|
||||
|
||||
# CUSTOM ROUTES HERE
|
||||
|
||||
map.connect(':controller/:action/:id')
|
||||
map.connect('*url', controller='template', action='view')
|
||||
|
||||
return map
|
||||
0
gnuviechadminweb/controllers/__init__.py
Normal file
0
gnuviechadminweb/controllers/__init__.py
Normal file
41
gnuviechadminweb/controllers/error.py
Normal file
41
gnuviechadminweb/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 gnuviechadminweb.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
gnuviechadminweb/controllers/template.py
Normal file
27
gnuviechadminweb/controllers/template.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from gnuviechadminweb.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)
|
||||
0
gnuviechadminweb/lib/__init__.py
Normal file
0
gnuviechadminweb/lib/__init__.py
Normal file
14
gnuviechadminweb/lib/app_globals.py
Normal file
14
gnuviechadminweb/lib/app_globals.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
"""The application's Globals object"""
|
||||
from pylons import config
|
||||
|
||||
class Globals(object):
|
||||
"""Globals acts as a container for objects available throughout the
|
||||
life of the application
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""One instance of Globals is created during application
|
||||
initialization and is available during requests via the 'g'
|
||||
variable
|
||||
"""
|
||||
pass
|
||||
27
gnuviechadminweb/lib/base.py
Normal file
27
gnuviechadminweb/lib/base.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
"""The base Controller API
|
||||
|
||||
Provides the BaseController class for subclassing, and other objects
|
||||
utilized by Controllers.
|
||||
"""
|
||||
from pylons import c, cache, config, g, request, response, session
|
||||
from pylons.controllers import WSGIController
|
||||
from pylons.controllers.util import abort, etag_cache, redirect_to
|
||||
from pylons.decorators import jsonify, validate
|
||||
from pylons.i18n import _, ungettext, N_
|
||||
from pylons.templating import render
|
||||
|
||||
import gnuviechadminweb.lib.helpers as h
|
||||
import gnuviechadminweb.model as model
|
||||
|
||||
class BaseController(WSGIController):
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
"""Invoke the Controller"""
|
||||
# WSGIController.__call__ dispatches to the Controller method
|
||||
# the request is routed to. This routing information is
|
||||
# available in environ['pylons.routes_dict']
|
||||
return WSGIController.__call__(self, environ, start_response)
|
||||
|
||||
# Include the '_' function in the public names
|
||||
__all__ = [__name for __name in locals().keys() if not __name.startswith('_') \
|
||||
or __name == '_']
|
||||
6
gnuviechadminweb/lib/helpers.py
Normal file
6
gnuviechadminweb/lib/helpers.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
"""Helper functions
|
||||
|
||||
Consists of functions to typically be used within templates, but also
|
||||
available to Controllers. This module is available to both as 'h'.
|
||||
"""
|
||||
from webhelpers import *
|
||||
0
gnuviechadminweb/model/__init__.py
Normal file
0
gnuviechadminweb/model/__init__.py
Normal file
108
gnuviechadminweb/public/index.html
Normal file
108
gnuviechadminweb/public/index.html
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Pylons Default Page</title>
|
||||
<style>
|
||||
body { background-color: #fff; color: #333; }
|
||||
|
||||
body, p {
|
||||
font-family: verdana, arial, helvetica, sans-serif;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
}
|
||||
pre {
|
||||
background-color: #eee;
|
||||
padding: 10px;
|
||||
font-size: 11px;
|
||||
line-height: 13px;
|
||||
}
|
||||
|
||||
a { color: #000; }
|
||||
a:visited { color: #666; }
|
||||
a:hover { color: #fff; background-color:#000; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>Welcome to your Pylons Web Application</h1>
|
||||
|
||||
<h2>Weren't expecting to see this page?</h2>
|
||||
|
||||
<p>The <tt>gnuviechadminweb/public/</tt> directory is searched for static files
|
||||
<i>before</i> your controllers are run. Remove this file (<tt>gnuviechadminweb/public/index.html</tt>)
|
||||
and edit the routes in <tt>gnuviechadminweb/config/routing.py</tt> to point the
|
||||
<a href="/">root path</a> to a 'hello' controller we'll create below:
|
||||
<pre> map.connect('', controller='hello', action='index')</pre>
|
||||
</p>
|
||||
|
||||
<h2>Getting Started</h2>
|
||||
<p>You're now ready to start creating your own web application. To create a 'hello' controller,
|
||||
run the following command in your project's root directory:
|
||||
<pre>
|
||||
gnuviechadminweb$ paster controller hello
|
||||
</pre>
|
||||
|
||||
This generates the following the following code in <tt>gnuviechadminweb/controllers/hello.py</tt>:
|
||||
<pre>
|
||||
import logging
|
||||
|
||||
from gnuviechadminweb.lib.base import *
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class HelloController(BaseController):
|
||||
|
||||
def index(self):
|
||||
# Return a rendered template
|
||||
# return render('/some/template.mako)
|
||||
# or, Return a response
|
||||
return 'Hello World'
|
||||
</pre>
|
||||
</p>
|
||||
<p>This controller simply prints out 'Hello World' to the browser. Pylons' default routes
|
||||
automatically set up this controller to respond at the <a href="/hello">/hello</a> URL.
|
||||
With the additional route described above, this controller will also respond at the
|
||||
<a href="/">root path</a>.
|
||||
</p>
|
||||
|
||||
<h3>Using a template</h3>
|
||||
<p>To call a template and do something a little more complex, this following example
|
||||
shows how to print out some request information from a
|
||||
<a href="http://www.makotemplates.org">Mako</a> template.
|
||||
</p>
|
||||
<p>Create a <tt>serverinfo.mako</tt> file in your project's <tt>gnuviechadminweb/templates/</tt>
|
||||
directory with the following contents:
|
||||
</p>
|
||||
<pre>
|
||||
<h2>
|
||||
Server info for ${request.host}
|
||||
</h2>
|
||||
|
||||
<p>
|
||||
The URL you called: ${h.url_for()}
|
||||
</p>
|
||||
|
||||
<p>
|
||||
The name you set: ${c.name}
|
||||
</p>
|
||||
|
||||
<p>The WSGI environ:<br />
|
||||
<pre>${c.pretty_environ}</pre>
|
||||
</p>
|
||||
</pre>
|
||||
|
||||
Then add the following to your 'hello' controller class:
|
||||
<pre>
|
||||
def serverinfo(self):
|
||||
import cgi
|
||||
import pprint
|
||||
c.pretty_environ = cgi.escape(pprint.pformat(request.environ))
|
||||
c.name = 'The Black Knight'
|
||||
return render('/serverinfo.mako')
|
||||
</pre>
|
||||
|
||||
You can now view the page at: <tt><a href="/hello/serverinfo">/hello/serverinfo</a></tt>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
40
gnuviechadminweb/tests/__init__.py
Normal file
40
gnuviechadminweb/tests/__init__.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"""Pylons application test package
|
||||
|
||||
When the test runner finds and executes tests within this directory,
|
||||
this file will be loaded to setup the test environment.
|
||||
|
||||
It registers the root directory of the project in sys.path and
|
||||
pkg_resources, in case the project hasn't been installed with
|
||||
setuptools. It also initializes the application via websetup (paster
|
||||
setup-app) with the project's test.ini configuration file.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
from unittest import TestCase
|
||||
|
||||
import pkg_resources
|
||||
import paste.fixture
|
||||
import paste.script.appinstall
|
||||
from paste.deploy import loadapp
|
||||
from routes import url_for
|
||||
|
||||
__all__ = ['url_for', 'TestController']
|
||||
|
||||
here_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
conf_dir = os.path.dirname(os.path.dirname(here_dir))
|
||||
|
||||
sys.path.insert(0, conf_dir)
|
||||
pkg_resources.working_set.add_entry(conf_dir)
|
||||
pkg_resources.require('Paste')
|
||||
pkg_resources.require('PasteScript')
|
||||
|
||||
test_file = os.path.join(conf_dir, 'test.ini')
|
||||
cmd = paste.script.appinstall.SetupCommand('setup-app')
|
||||
cmd.run([test_file])
|
||||
|
||||
class TestController(TestCase):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
|
||||
self.app = paste.fixture.TestApp(wsgiapp)
|
||||
TestCase.__init__(self, *args, **kwargs)
|
||||
0
gnuviechadminweb/tests/functional/__init__.py
Normal file
0
gnuviechadminweb/tests/functional/__init__.py
Normal file
0
gnuviechadminweb/tests/test_models.py
Normal file
0
gnuviechadminweb/tests/test_models.py
Normal file
14
gnuviechadminweb/websetup.py
Normal file
14
gnuviechadminweb/websetup.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
"""Setup the gnuviechadminweb application"""
|
||||
import logging
|
||||
|
||||
from paste.deploy import appconfig
|
||||
from pylons import config
|
||||
|
||||
from gnuviechadminweb.config.environment import load_environment
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
def setup_config(command, filename, section, vars):
|
||||
"""Place any commands to setup gnuviechadminweb here"""
|
||||
conf = appconfig('config:' + filename)
|
||||
load_environment(conf.global_conf, conf.local_conf)
|
||||
Loading…
Add table
Add a link
Reference in a new issue