summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2010-05-03 23:11:52 +0200
committerRené 'Necoro' Neumann <necoro@necoro.net>2010-05-03 23:11:52 +0200
commit81e7480e7526025ce27f0ca234104b039631cf3d (patch)
tree3e75d4728e1c378e51c23f09ae842f3c6c585e98
parentf0012811f8af8b1334b46781861a6dd3777ee392 (diff)
downloadkosten-81e7480e7526025ce27f0ca234104b039631cf3d.tar.gz
kosten-81e7480e7526025ce27f0ca234104b039631cf3d.tar.bz2
kosten-81e7480e7526025ce27f0ca234104b039631cf3d.zip
started modelling
-rwxr-xr-xindex.py21
-rw-r--r--model.py49
2 files changed, 70 insertions, 0 deletions
diff --git a/index.py b/index.py
index b91418d..d9e2e7d 100755
--- a/index.py
+++ b/index.py
@@ -2,6 +2,7 @@
import web
import controller
+import model
#
# URL Mappings
@@ -12,11 +13,31 @@ urls = (
)
#
+# ORM
+#
+def handle_sql(handler):
+ web.ctx.orm = session = model.session
+
+ try:
+ return handler()
+ except web.HTTPError:
+ session.commit()
+ raise
+ except:
+ session.rollback()
+ raise
+ else:
+ session.commit()
+
+#
# The App
#
app = web.application(urls, globals())
app.notfound = controller.FourOhFour
+# add orm processor
+app.add_processor(handle_sql)
+
# debug for the moment
web.config.debug = True
diff --git a/model.py b/model.py
new file mode 100644
index 0000000..903797b
--- /dev/null
+++ b/model.py
@@ -0,0 +1,49 @@
+import elixir
+from elixir import has_field, belongs_to, has_many, using_options, using_options_defaults
+from sqlalchemy import types as T
+
+from functools import partial
+
+elixir.metadata.bind = "sqlite:///test.sqlite"
+elixir.metadata.bind.echo = True
+
+has_req_field = partial(has_field, required = True)
+
+class Entity (elixir.Entity):
+ using_options(abstract = True)
+
+ using_options_defaults(shortnames = True)
+
+class Category (Entity):
+
+ has_field('name', T.String(50), unique = True)
+
+ def __repr__ (self):
+ return '<Category "%s">' % self.name
+
+class Expense (Entity):
+ using_options(inheritance='multi')
+
+ has_field('description', T.String(50))
+ has_req_field('expense', T.Numeric(scale = 2))
+
+ belongs_to('category', of_kind = 'Category', required = True)
+
+class SingleExpense (Expense):
+ using_options(inheritance='multi')
+
+ has_req_field('date', T.Date)
+
+class ConstExpense (Expense):
+ using_options(inheritance='multi')
+
+ has_req_field('months', T.Integer)
+ has_req_field('start', T.Date)
+ has_req_field('end', T.Date)
+
+elixir.setup_all()
+
+session = elixir.session
+
+if __name__ == "__main__":
+ elixir.create_all()