1. Atsushi Odagiri
  2. alchemyadmin

Commits

Atsushi Odagiri  committed 691be2a

show list of models.

  • Participants
  • Parent commits 307e292
  • Branches default

Comments (0)

Files changed (3)

File src/alchemyadmin/__init__.py

View file
 #
 from werkzeug import Request, Response
+from jinja2 import Environment, PackageLoader
+default_template_env = Environment(loader=PackageLoader('alchemyadmin', 'templates'))
 
 class Application(object):
     def __init__(self, settings, *models, **modelsdict):
-        pass
+        self.template_env = default_template_env
+        self.models = modelsdict.copy()
+        for m in models:
+            self.models[m.__name__.lower()] = m
+
 
     def __call__(self, environ, start_response):
-        res = Response()
+        res = Response(self.render('index.html', models=self.models),
+                       content_type='text/html;charset=utf-8')
         return res(environ, start_response)
+
+    def render(self, template_name, **kw):
+        template = self.template_env.get_template(template_name)
+        return template.render(**kw)

File src/alchemyadmin/demo/__init__.py

View file
+from sqlalchemy import *
+from sqlalchemy.orm import *
+from sqlalchemy.ext.declarative import declarative_base
+
+Base = declarative_base()
+metadata = Base.metadata
+
+class User(Base):
+    __tablename__ = 'user'
+    user_id = Column(Integer, primary_key=True)
+    user_name = Column(String(255), unique=True)
+    password = Column(String(255))
+    display_name = Column(Unicode(255))
+    description = Column(UnicodeText)
+    birthday = Column(DateTime)
+
 
 def make_app(global_conf, **app_conf):
     from alchemyadmin import Application
     conf = global_conf.copy()
     conf.update(app_conf)
-    app = Application(conf)
+    engine = engine_from_config(conf)
+    metadata.bind = engine
+    app = Application(conf, User)
     return app
 

File src/alchemyadmin/templates/index.html

View file
+<ul>
+  {%for m in models%}
+  <li>{{m}}</li>
+  {%endfor %}
+</ul>