from pyramid.view import view_config
import pyramid_plugin
@view_config(route_name='home', renderer='form_view.mak')
def my_view(request):
Car = pyramid_plugin.get_car(request)
Car.get_type()
###
# app configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/environment.html
###
[app:main]
use = egg:formencode-tut
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
pyramid_debugtoolbar
pyramid_plugin
mako.directories = formencodetut:templates
plugin.make = Camaro SS
# By default, the toolbar only appears for clients from IP addresses
# '127.0.0.1' and '::1'.
# debugtoolbar.hosts = 127.0.0.1 ::1
###
# wsgi server configuration
###
[server:main]
use = egg:waitress#main
host = 0.0.0.0
port = 6543
###
# logging configuration
# http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/logging.html
###
[loggers]
keys = root, formencodetut
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = INFO
handlers = console
[logger_formencodetut]
level = DEBUG
handlers =
qualname = formencodetut
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
# -*- coding: utf-8 -*-
"""
Created on 05/03/14
@author: dwanyoike
Example of a pyramid Framework Addon
"""
from zope.interface import Interface
def get_car(request):
""" used to retrieve the object we saved with registerUtility the
object is stored in the request and is available globally"""
registry = getattr(request, 'registry', None)
if registry is None:
registry = request
return registry.getUtility(IPyramidutiliy)
class IPyramidutiliy(Interface):
pass
class Car(object):
def __init__(self,settings):
self.car_make = settings['plugin.make']
def get_type(self):
print self.car_make + " go Vroooom "
def includeme(config):
#Fetch settings from our development.ini or production.ini
settings = config.registry.settings
#Create a new car passing our setting fro our .ini files
new_car = Car(settings)
#Add the Car object to registry
config.registry.registerUtility(new_car, IPyramidutiliy)