1
0
Fork 0

* initial checkin

This commit is contained in:
Jan Dittberner 2008-06-03 19:12:16 +00:00
parent 3a553ecbfb
commit 79e3237986
27 changed files with 660 additions and 0 deletions

2
MANIFEST.in Normal file
View File

@ -0,0 +1,2 @@
recursive-include gnuviechadminweb/public *
recursive-include gnuviechadminweb/templates *

19
README.txt Normal file
View File

@ -0,0 +1,19 @@
This file is for you to describe the gnuviechadminweb application. Typically
you would include information such as the information below:
Installation and Setup
======================
Install ``gnuviechadminweb`` using easy_install::
easy_install gnuviechadminweb
Make a config file as follows::
paster make-config gnuviechadminweb config.ini
Tweak the config file as appropriate and then setup the application::
paster setup-app config.ini
Then you are ready to go.

64
development.ini Normal file
View File

@ -0,0 +1,64 @@
#
# gnuviechadminweb - Pylons development environment configuration
#
# The %(here)s variable will be replaced with the parent directory of this file
#
[DEFAULT]
debug = true
# Uncomment and replace with the address which should receive any error reports
#email_to = you@yourdomain.com
smtp_server = localhost
error_email_from = paste@localhost
[server:main]
use = egg:Paste#http
host = 0.0.0.0
port = 5000
[app:main]
use = egg:gnuviechadminweb
full_stack = true
cache_dir = %(here)s/data
beaker.session.key = gnuviechadminweb
beaker.session.secret = somesecret
# If you'd like to fine-tune the individual locations of the cache data dirs
# for the Cache data, or the Session saves, un-comment the desired settings
# here:
#beaker.cache.data_dir = %(here)s/data/cache
#beaker.session.data_dir = %(here)s/data/sessions
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
# execute malicious code after an exception is raised.
#set debug = false
# Logging configuration
[loggers]
keys = root, gnuviechadminweb
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = INFO
handlers = console
[logger_gnuviechadminweb]
level = DEBUG
handlers =
qualname = gnuviechadminweb
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s,%(msecs)03d %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

12
docs/index.txt Normal file
View File

@ -0,0 +1,12 @@
gnuviechadminweb
++++++++++++++++
This is the main index page of your documentation. It should be written in
`reStructuredText format <http://docutils.sourceforge.net/rst.html>`_.
You can generate your documentation in HTML format by running this command::
setup.py pudge
For this to work you will need to download and install ``buildutils`` and
``pudge``.

View File

@ -0,0 +1,58 @@
#
# gnuviechadminweb - Pylons configuration
#
# The %(here)s variable will be replaced with the parent directory of this file
#
[DEFAULT]
debug = true
email_to = you@yourdomain.com
smtp_server = localhost
error_email_from = paste@localhost
[server:main]
use = egg:Paste#http
host = 0.0.0.0
port = 5000
[app:main]
use = egg:gnuviechadminweb
full_stack = true
cache_dir = %(here)s/data
beaker.session.key = gnuviechadminweb
beaker.session.secret = ${app_instance_secret}
app_instance_uuid = ${app_instance_uuid}
# If you'd like to fine-tune the individual locations of the cache data dirs
# for the Cache data, or the Session saves, un-comment the desired settings
# here:
#beaker.cache.data_dir = %(here)s/data/cache
#beaker.session.data_dir = %(here)s/data/sessions
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
# execute malicious code after an exception is raised.
set debug = false
# Logging configuration
[loggers]
keys = root
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = INFO
handlers = console
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s] %(message)s

View File

@ -0,0 +1,3 @@
Pylons
WebHelpers
PasteScript

View File

View File

View 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)

View 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

View 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

View File

View 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)

View 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)

View File

View 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

View 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 == '_']

View 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 *

View File

View 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>
&lt;h2&gt;
Server info for ${request.host}
&lt;/h2&gt;
&lt;p&gt;
The URL you called: ${h.url_for()}
&lt;/p&gt;
&lt;p&gt;
The name you set: ${c.name}
&lt;/p&gt;
&lt;p&gt;The WSGI environ:&lt;br /&gt;
&lt;pre&gt;${c.pretty_environ}&lt;/pre&gt;
&lt;/p&gt;
</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>

View 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)

View File

View 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)

59
setup.cfg Normal file
View File

@ -0,0 +1,59 @@
[egg_info]
tag_build = dev
tag_svn_revision = true
[easy_install]
find_links = http://www.pylonshq.com/download/
[pudge]
theme = pythonpaste.org
# Add extra doc files here with spaces between them
docs = docs/index.txt
# Doc Settings
doc_base = docs/
dest = docs/html
# Add extra modules here separated with commas
modules = gnuviechadminweb
title = Gnuviechadminweb
organization = Pylons
# Highlight code-block sections with Pygments
highlighter = pygments
# Optionally add extra links
#organization_url = http://pylonshq.com/
#trac_url = http://pylonshq.com/project
settings = no_about=true
# Optionally add extra settings
# link1=/community/ Community
# link2=/download/ Download
[publish]
doc-dir=docs/html
make-dirs=1
# Babel configuration
[compile_catalog]
domain = gnuviechadminweb
directory = gnuviechadminweb/i18n
statistics = true
[extract_messages]
add_comments = TRANSLATORS:
output_file = gnuviechadminweb/i18n/gnuviechadminweb.pot
width = 80
[init_catalog]
domain = gnuviechadminweb
input_file = gnuviechadminweb/i18n/gnuviechadminweb.pot
output_dir = gnuviechadminweb/i18n
[update_catalog]
domain = gnuviechadminweb
input_file = gnuviechadminweb/i18n/gnuviechadminweb.pot
output_dir = gnuviechadminweb/i18n
previous = true

31
setup.py Normal file
View File

@ -0,0 +1,31 @@
try:
from setuptools import setup, find_packages
except ImportError:
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup, find_packages
setup(
name='gnuviechadminweb',
version="",
#description='',
#author='',
#author_email='',
#url='',
install_requires=["Pylons>=0.9.6.2"],
packages=find_packages(exclude=['ez_setup']),
include_package_data=True,
test_suite='nose.collector',
package_data={'gnuviechadminweb': ['i18n/*/LC_MESSAGES/*.mo']},
#message_extractors = {'gnuviechadminweb': [
# ('**.py', 'python', None),
# ('templates/**.mako', 'mako', None),
# ('public/**', 'ignore', None)]},
entry_points="""
[paste.app_factory]
main = gnuviechadminweb.config.middleware:make_app
[paste.app_install]
main = pylons.util:PylonsInstaller
""",
)

21
test.ini Normal file
View File

@ -0,0 +1,21 @@
#
# gnuviechadminweb - Pylons testing environment configuration
#
# The %(here)s variable will be replaced with the parent directory of this file
#
[DEFAULT]
debug = true
# Uncomment and replace with the address which should receive any error reports
#email_to = you@yourdomain.com
smtp_server = localhost
error_email_from = paste@localhost
[server:main]
use = egg:Paste#http
host = 0.0.0.0
port = 5000
[app:main]
use = config:development.ini
# Add additional test specific configuration options as necessary.