Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

now we use elixir on top of sqlalchemy as orm

  • Loading branch information...
commit 19e516f3cc8bd7f02c7976ec4ee755040afebb3e 1 parent 69c7df3
@stanislavfeldman authored
View
15 kiss/core/application.py
@@ -11,7 +11,7 @@
from werkzeug.wsgi import SharedDataMiddleware
from kiss.core.events import Eventer, ApplicationStarted, ApplicationStopped, BeforeDatabaseEngineConfiguration, AfterDatabaseEngineConfiguration
from kiss.views.static import StaticBuilder
-from kiss.models import Model
+from kiss.models import metadata
import logging
@@ -25,7 +25,7 @@ def __init__(self, options):
self.options, self.eventer = Application.init_eventer(options)
self.options, self.router = Application.init_router(options)
self.eventer.publish(BeforeDatabaseEngineConfiguration, self)
- self.options, self.db_engine = Application.init_db(self.options)
+ self.options = Application.init_db(self.options)
self.eventer.publish(AfterDatabaseEngineConfiguration, self)
self.options, self.static_builder = Application.init_static(self.options)
self.options, self.wsgi_app = Application.init_session(self.options, self.wsgi_app)
@@ -81,14 +81,9 @@ def init_static(options):
def init_db(options):
if "models" not in options:
return (options, None)
- db_engine_class = options["models"].pop("engine")
- db_name = options["models"].pop("database")
- db_engine = db_engine_class(db_name, **options["models"])
- db_engine.connect()
- db_engine.set_autocommit(True)
- for m in Introspector.all_subclasses(Model):
- m._meta.database = db_engine
- return (options, db_engine)
+ metadata.bind = options["models"]["connection"]
+ metadata.bind.echo = False
+ return (options)
@staticmethod
def init_session(options, wsgi_app):
View
2  kiss/models/__init__.py
@@ -1 +1 @@
-from peewee import *
+from elixir import *
View
28 project/controllers/controller2.py
@@ -4,30 +4,22 @@
from models.models import Blog, Entry
import datetime
from kiss.controllers.core import Controller
-from kiss.models import Model, SqliteDatabase
+from kiss.models import setup_all, drop_all, create_all, session
class Controller2(Controller):
def get(self, request):
- print request.params
#publish some event
eventer = Eventer()
eventer.publish("some event", self)
if not "foo" in request.session:
request.session["foo"] = 0
request.session["foo"] += 1
- blog = Blog()
- #blog = Blog.get(id=1)
- blog.name = "super blog"
- blog.creator = "Stas"
- blog.save()
- entry = Entry()
- #entry = Entry.get(id=2)
- entry.blog = blog
- entry.title = "super post"
- entry.body = "lkoeirsldfkwierj"
- entry.pub_date = datetime.datetime.now()
- entry.save()
+ blog = Blog(name="super blog", creator="Stas")
+ if not Entry.get_by(title="super post"):
+ entry = Entry(title="super post", body="saifjo", blog=blog)
+ session.commit()
+ print Entry.query.all()
return TemplateResponse("view.html", {
"foo": request.session["foo"],
"users": [{"url": "google.com", "username": "brin"}],
@@ -36,12 +28,10 @@ def get(self, request):
#on load handler via eventer
def application_after_load(self, application):
+ setup_all()
+ drop_all()
+ create_all()
print "app loaded"
- Blog.create_table(fail_silently=True)
- Entry.create_table(fail_silently=True)
-
- def before_controller_action(self, request):
- request.params["inserted_param"] = "hi)"
def internal_server_error(self, request):
return Response("<h1>error: %s</h1>" % request.description)
View
19 project/models/models.py
@@ -1,14 +1,13 @@
-from kiss.models import Model, CharField, TextField, DateTimeField, BooleanField, ForeignKeyField
+from kiss.models import Entity, Field, Unicode, UnicodeText, OneToMany, ManyToOne
-class Blog(Model):
- creator = CharField()
- name = CharField()
+class Blog(Entity):
+ creator = Field(Unicode)
+ name = Field(Unicode)
+ entries = OneToMany("Entry")
-class Entry(Model):
- blog = ForeignKeyField(Blog)
- title = CharField()
- body = TextField()
- pub_date = DateTimeField()
- published = BooleanField(default=True)
+class Entry(Entity):
+ title = Field(Unicode)
+ body = Field(UnicodeText)
+ blog = ManyToOne("Blog")
View
8 project/settings.py
@@ -10,7 +10,6 @@
from controllers.controller2 import Controller2
from kiss.core.events import ApplicationStarted
from kiss.controllers.events import BeforeControllerAction
-from kiss.models import SqliteDatabase
from kiss.core.exceptions import InternalServerError
from kiss.controllers.page import PageController
from kiss.controllers.rest import RestController
@@ -66,15 +65,10 @@
},
"events": {
ApplicationStarted: Controller2.application_after_load,
- BeforeControllerAction: Controller2.before_controller_action,
InternalServerError.code: Controller2.internal_server_error
},
"models": {
- "engine": SqliteDatabase,
- #"host": "localhost",
- "database": path.join(current_dir, "kiss_py_project.sqldb")#,#,
- #"user": 'postgres',
- #"password": "postgres"
+ "connection": "sqlite:///kisspy_project.sqldb"
}
}
View
2  project/views/templates/view.html
@@ -13,7 +13,7 @@
</ul>
<div id="navbar">Blog: {{ blog.name }}</div>
<ul>
- {% for entry in blog.entry_set %}
+ {% for entry in blog.entries %}
<li>{{ entry.title }}</li>
{% endfor %}
</ul>
View
4 setup.py
@@ -6,7 +6,7 @@
setup(
name = "kiss.py",
- version = "0.3.8",
+ version = "0.4.0",
author = "Stanislav Feldman",
description = ("MVC web framework in Python with Gevent, Jinja2, Werkzeug"),
url = "http://stanislavfeldman.github.com/kiss.py/",
@@ -14,7 +14,7 @@
packages=[
"kiss", "kiss.controllers", "kiss.core", "kiss.views", "kiss.models"
],
- install_requires = ["gevent", "jinja2", "compressinja", "beaker", "werkzeug", "putils", "jsmin", "pyScss", "peewee", "jsonpickle", "pev"],
+ install_requires = ["gevent", "jinja2", "compressinja", "beaker", "werkzeug", "putils", "jsmin", "pyScss", "sqlalchemy", "elixir", "jsonpickle", "pev"],
classifiers=[
"Development Status :: 5 - Production/Stable",
"Topic :: Software Development",
Please sign in to comment.
Something went wrong with that request. Please try again.