diff --git a/pyalchemybiz/config/environment.py b/pyalchemybiz/config/environment.py index 1c57d9d..5963ee6 100644 --- a/pyalchemybiz/config/environment.py +++ b/pyalchemybiz/config/environment.py @@ -12,6 +12,7 @@ import pyalchemybiz.lib.app_globals as app_globals import pyalchemybiz.lib.helpers from pyalchemybiz.config.routing import make_map + def load_environment(global_conf, app_conf): """Configure the Pylons environment via the ``pylons.config`` object diff --git a/pyalchemybiz/config/middleware.py b/pyalchemybiz/config/middleware.py index 84ed761..d0eda92 100644 --- a/pyalchemybiz/config/middleware.py +++ b/pyalchemybiz/config/middleware.py @@ -12,6 +12,7 @@ from pylons.wsgiapp import PylonsApp from pyalchemybiz.config.environment import load_environment + def make_app(global_conf, full_stack=True, **app_conf): """Create a Pylons WSGI application and return it diff --git a/pyalchemybiz/config/routing.py b/pyalchemybiz/config/routing.py index 1d42332..e685eb8 100644 --- a/pyalchemybiz/config/routing.py +++ b/pyalchemybiz/config/routing.py @@ -7,6 +7,7 @@ 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'], diff --git a/pyalchemybiz/controllers/customer.py b/pyalchemybiz/controllers/customer.py index 25550f7..eabdb72 100644 --- a/pyalchemybiz/controllers/customer.py +++ b/pyalchemybiz/controllers/customer.py @@ -5,16 +5,17 @@ from pyalchemybiz.model import customer, meta log = logging.getLogger(__name__) + class CustomerController(BaseController): def index(self): sess = meta.Session() cust_q = sess.query(customer.Customer) c.customers = cust_q.all() - return render('/customer.mako') + return render('/customer/index.mako') def edit(self, id): sess = meta.Session() cust_q = sess.query(customer.Customer) c.customer = cust_q.filter(customer.Customer.id==id).one() - return c.customer + return render('/customer/edit.mako') diff --git a/pyalchemybiz/controllers/error.py b/pyalchemybiz/controllers/error.py index 665ac31..1ef899b 100644 --- a/pyalchemybiz/controllers/error.py +++ b/pyalchemybiz/controllers/error.py @@ -6,6 +6,7 @@ from pylons.middleware import error_document_template, media_path from pyalchemybiz.lib.base import * + class ErrorController(BaseController): """Generates error documents as and when they are required. @@ -14,8 +15,9 @@ class ErrorController(BaseController): 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 % \ diff --git a/pyalchemybiz/controllers/index.py b/pyalchemybiz/controllers/index.py index 7d63df0..e959244 100644 --- a/pyalchemybiz/controllers/index.py +++ b/pyalchemybiz/controllers/index.py @@ -4,6 +4,7 @@ from pyalchemybiz.lib.base import * log = logging.getLogger(__name__) + class IndexController(BaseController): def index(self): diff --git a/pyalchemybiz/controllers/template.py b/pyalchemybiz/controllers/template.py index 740491b..cbd8898 100644 --- a/pyalchemybiz/controllers/template.py +++ b/pyalchemybiz/controllers/template.py @@ -1,5 +1,6 @@ from pyalchemybiz.lib.base import * + class TemplateController(BaseController): def view(self, url): diff --git a/pyalchemybiz/lib/app_globals.py b/pyalchemybiz/lib/app_globals.py index 7f7585f..d650178 100644 --- a/pyalchemybiz/lib/app_globals.py +++ b/pyalchemybiz/lib/app_globals.py @@ -1,6 +1,7 @@ """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 diff --git a/pyalchemybiz/lib/base.py b/pyalchemybiz/lib/base.py index 1b923c0..7933628 100644 --- a/pyalchemybiz/lib/base.py +++ b/pyalchemybiz/lib/base.py @@ -16,6 +16,7 @@ import pyalchemybiz.model as model from pyalchemybiz.model import meta from sqlalchemy.orm import sessionmaker + class BaseController(WSGIController): def __call__(self, environ, start_response): diff --git a/pyalchemybiz/model/__init__.py b/pyalchemybiz/model/__init__.py index 7309801..5ccbee3 100644 --- a/pyalchemybiz/model/__init__.py +++ b/pyalchemybiz/model/__init__.py @@ -1,3 +1,4 @@ +"""Data model for pyalchemybiz.""" import logging import sqlalchemy as sa from sqlalchemy import orm @@ -7,9 +8,10 @@ from pyalchemybiz.model import person, customer, product log = logging.getLogger(__name__) + def init_model(engine): """Call me before using any of the tables or classes in the model.""" - + sm = orm.sessionmaker(autoflush=True, transactional=True, bind=engine) meta.engine = engine @@ -24,9 +26,9 @@ def init_model(engine): 'product', meta.metadata, autoload=True, autoload_with=engine) orm.mapper(person.Person, person.t_person) - orm.mapper(customer.Customer, customer.t_customer) - customer.Customer.person = orm.relation(person.Person) + orm.mapper(customer.Customer, customer.t_customer, properties={ + 'person': orm.relation(person.Person, backref='customer')}) orm.mapper(product.ProductType, product.t_producttype) - orm.mapper(product.Product, product.t_product) - product.Product.producttype = orm.relation( - product.Product, backref=orm.backref('products', lazy='dynamic')) + orm.mapper(product.Product, product.t_product, properties={ + 'producttype': orm.relation(product.ProductType, + backref='products')}) diff --git a/pyalchemybiz/model/customer.py b/pyalchemybiz/model/customer.py index 5fe8321..6d3af38 100644 --- a/pyalchemybiz/model/customer.py +++ b/pyalchemybiz/model/customer.py @@ -1,5 +1,12 @@ +"""Customer related model elements.""" t_customer = None + class Customer(object): - def __str__(self): - return "%s %s" % (self.firstname, self.lastname) + """Customer model class.""" + + def __repr__(self): + if self.id is None: + return "" % (self.person) + else: + return "" % (self.id, self.person) diff --git a/pyalchemybiz/model/meta.py b/pyalchemybiz/model/meta.py index 578584a..6eeb4e6 100644 --- a/pyalchemybiz/model/meta.py +++ b/pyalchemybiz/model/meta.py @@ -9,6 +9,6 @@ engine = None # SQLAlchemy session manager. Updated by model.init_model(). Session = None -# Global metadata. If you have multiple databases with overlapping table +# Global metadata. If you have multiple databases with overlapping table # names, you'll need a metadata for each database. metadata = MetaData() diff --git a/pyalchemybiz/model/person.py b/pyalchemybiz/model/person.py index d9ee9b4..3f32abe 100644 --- a/pyalchemybiz/model/person.py +++ b/pyalchemybiz/model/person.py @@ -1,5 +1,11 @@ t_person = None + class Person(object): - def __str__(self): - return "%s %s" % (self.firstname, self.lastname) + + def __repr__(self): + if self.id is None: + return "" % (self.firstname, self.lastname) + else: + return "" % (self.id, self.firstname, + self.lastname) diff --git a/pyalchemybiz/model/product.py b/pyalchemybiz/model/product.py index 866bf70..67a6b24 100644 --- a/pyalchemybiz/model/product.py +++ b/pyalchemybiz/model/product.py @@ -1,8 +1,21 @@ t_producttype = None t_product = None + class ProductType(object): - pass + + def __repr__(self): + if self.id is None: + return "" % (self.name) + else: + return "" % (self.id, self.name) + class Product(object): - pass + + def __repr__(self): + if self.id is None: + return "" % (self.name, self.producttype) + else: + return "" % (self.id, self.name, + self.producttype) diff --git a/pyalchemybiz/templates/customer.mako b/pyalchemybiz/templates/customer.mako deleted file mode 100644 index 8aefd56..0000000 --- a/pyalchemybiz/templates/customer.mako +++ /dev/null @@ -1,9 +0,0 @@ -<%inherit file="base.mako" /> - -

Hallo

- -
    -% for customer in c.customers: -
  • ${customer.firstname} ${customer.lastname} [${h.link_to('edit', h.url_for(id=customer.id, action="edit"))}]
  • -% endfor -
diff --git a/pyalchemybiz/templates/customer/index.mako b/pyalchemybiz/templates/customer/index.mako new file mode 100644 index 0000000..20989c6 --- /dev/null +++ b/pyalchemybiz/templates/customer/index.mako @@ -0,0 +1,9 @@ +<%inherit file="/base.mako" /> + +

Hallo

+ +
    +% for customer in c.customers: +
  • ${h.escape_once(customer)} [${h.link_to('edit', h.url_for(id=customer.id, action="edit"))}]
  • +% endfor +
diff --git a/pyalchemybiz/tests/__init__.py b/pyalchemybiz/tests/__init__.py index 91ff2e7..1caa487 100644 --- a/pyalchemybiz/tests/__init__.py +++ b/pyalchemybiz/tests/__init__.py @@ -32,6 +32,7 @@ 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): diff --git a/pyalchemybiz/tests/functional/test_customer.py b/pyalchemybiz/tests/functional/test_customer.py index 5a96361..68f3b62 100644 --- a/pyalchemybiz/tests/functional/test_customer.py +++ b/pyalchemybiz/tests/functional/test_customer.py @@ -1,5 +1,6 @@ from pyalchemybiz.tests import * + class TestCustomerController(TestController): def test_index(self): diff --git a/pyalchemybiz/tests/functional/test_index.py b/pyalchemybiz/tests/functional/test_index.py index e1b07cb..536254e 100644 --- a/pyalchemybiz/tests/functional/test_index.py +++ b/pyalchemybiz/tests/functional/test_index.py @@ -1,5 +1,6 @@ from pyalchemybiz.tests import * + class TestIndexController(TestController): def test_index(self): diff --git a/pyalchemybiz/websetup.py b/pyalchemybiz/websetup.py index f312c82..651259d 100644 --- a/pyalchemybiz/websetup.py +++ b/pyalchemybiz/websetup.py @@ -12,6 +12,7 @@ from pyalchemybiz.config.environment import load_environment log = logging.getLogger(__name__) + def setup_config(command, filename, section, vars): """Place any commands to setup pyalchemybiz here""" conf = appconfig('config:' + filename)