1. Atsushi Odagiri
  2. pyconjp2011

Commits

Atsushi Odagiri  committed ff26ee8

formalchemy customized classes

  • Participants
  • Parent commits 0b6fc9e
  • Branches default

Comments (0)

Files changed (6)

File formalchemy/pyconjp2011/formalchemy_demo/__init__.py

View file
 from formalchemy import Field
 from formalchemy import fields
 from formalchemy import Grid
+from formalchemy import config
+from fa.jquery import renderers as jquery
+from fa.jquery.utils import TemplateEngine
+
+config.engine = TemplateEngine()
 
 from .. import models
 from ..framework.application import Application, rest_controller
 
 templates = TemplateLookup(directories=[templates_dir])
 
+FieldSet.default_renderers.update(jquery.default_renderers)
+
 class UserForm(FieldSet):
     def __init__(self, **kw):
         super(UserForm, self).__init__(model=models.User, **kw)
 user_form = UserForm(session=models.DBSession)
 #user_form.append(Field(name='user_image').with_renderer(fields.FileFieldRenderer))
 
-user_grid = Grid(models.User, session=models.DBSession)
-user_grid.configure(readonly=True, exclude=[user_grid._password])
+class UserGrid(Grid):
+    def __init__(self, **kw):
+        super(UserGrid, self).__init__(cls=models.User, **kw)
+        self.append(Field('edit_link', value=lambda u: '<a href="%s/edit">Edit</a>' % u.id))
+        self.configure(readonly=True, exclude=[self._password])
+
+user_grid = UserGrid(session=models.DBSession)
 
 def index(request):
     users = models.DBSession.query(models.User).all()

File formalchemy/pyconjp2011/formalchemy_demo/templates/add_user.mak

View file
-<html>
-<head>
-<title>FormAlchemy Demo</title>
-</head>
-<body>
+<%inherit file="base.mak" />
 <form method="post" action="${request.application.route_url('add_user')}">
 ${form.render()}
 <button type="submit">Save</button>
-</form>
-</body>
-</html>
+

File formalchemy/pyconjp2011/formalchemy_demo/templates/base.mak

View file
+<html>
+<head>
+<title>FormAlchemy Demo</title>
+<link type="text/css" href="/jquery/css/smoothness/jquery-ui-1.8.8.custom.css" rel="stylesheet" />
+<link type="text/css" href="/jquery/colorpicker/syronex-colorpicker.css" rel="stylesheet" />
+<link type="text/css" href="/jquery/css/jquery.jgrowl.css" rel="stylesheet" />
+<link type="text/css" href="/jquery/fa/jquery.formalchemy.css" rel="stylesheet" />
+<style>
+.layout-grid, .layout-grid th, .layout-grid td {border-spacing: 0px;border-collapse: collapse;border:1px; margin:0;}
+.layout-grid {border:thin solid #5C9CCC;}
+.layout-grid th, .layout-grid td {padding:0.2em 0.3em;border-left:thin solid #5C9CCC;}
+.layout-grid td {vertical-align:top;}
+
+.fa_field {font-size:1em;}
+.fa_field {margin-left:0.2em;margin-bottom:0.3em;}
+.fa_field div.ui-state-error {margin:0.3em 0em; padding:0.2em; width:20em;}
+.fa_controls {margin-top: 1.5em;}
+.fa_model {display:block;text-align:center;margin:1.5em 20%;padding:1em 0px;}
+td.field_readonly {vertical-align:top;width:10%; text-align:right;}
+
+.ui-widget-even {background-color: #DFEFFC;}
+.ui-widget-odd {background-color: #FCFDFD;}
+
+.fa_selectable .ui-selecting { background: #DFEFFC; }
+.fa_selectable .ui-selected { background: #E6E6E6;}
+.fa_selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
+.fa_selectable li { margin: 3px; padding: 0.4em; height: 18px; cursor:pointer;}
+
+.fa_sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
+.fa_sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; height: 18px; cursor:move;}
+.fa_sortable li span { position: absolute; margin-left: -1.3em; }
+
+.ui-widget-link {padding:0.4em 1em 0.4em 20px;position:relative;text-decoration:none;}
+.ui-widget-link span.ui-icon {left:0.2em; margin:-8px 5px 0 0; position:absolute; top:50%;}
+
+.ui-grid-icon {margin:auto;width:20px;height:16px;padding-left:4px;}
+.ui-grid-icon input, .ui-widget-link input {background-color:transparent; border:none; cursor:pointer;}
+
+a.ui-widget-button input {display:none;}
+a.ui-widget-button, a.ui-widget-link {margin-right:1em;}
+
+.ui-pager {margin-bottom:1em;}
+
+/* jGrowl */
+div.ui-state-info {
+    background-color: #FFFFCC;
+    border:1px solid #336633;
+    color:#000000;
+}
+
+div.ui-state-warning {
+    background-color: #FF9966;
+    border:1px solid #FF3300;
+    color:#FF3300;
+}
+
+
+
+/* colorbox */
+#cboxOverlay{background-image:css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png);}
+
+/* patch for datepicker + jQuery UI */
+#ui-datepicker-div {
+	z-index: 1010;
+}
+
+</style>
+<script type="text/javascript" src="/jquery/js/jquery-1.4.4.min.js"></script>
+<script type="text/javascript" src="/jquery/js/jquery-ui-1.8.8.custom.min.js"></script>
+<script type="text/javascript" src="/jquery/fa/jquery.formalchemy.js"></script>
+<script type="text/javascript" src="/jquery/colorpicker/syronex-colorpicker.js"></script>
+<script type="text/javascript" src="/jquery/js/jquery.jgrowl_minimized.js"></script>
+
+</head>
+<body>
+${self.body()}
+</body>
+</html>
+

File formalchemy/pyconjp2011/formalchemy_demo/templates/index.mak

View file
-<html>
-<head>
-<title>FormAlchemy Demo</title>
-</head>
-<body>
+<%inherit file="base.mak" />
 <table>
 ${form.render()}
 </table>
 <a href="${request.application.route_url('add_user')}">Add</a>
-</body>
-</html>

File formalchemy/setup.py

View file
     "mako",
     "routes",
     "formalchemy",
+    "fa.jquery",
+    "zope.schema", # for demo application
     "mako",
     "pyconjp2011.models",
 ]

File webapp.ini

View file
 sqlalchemy.url = sqlite:///%(here)s/pyconjp2011.db
 sqlalchemy.echo = true
 
+[composite:formalchemy]
+use = egg:paste#urlmap
+/ = formalchemy_app
+/jquery = egg:fa.jquery
+/fa.jquery = egg:fa.jquery#test
+
 [pipeline:formalchemy_demo]
 pipeline =
     egg:repoze.tm2#tm
-    formalchemy_app
+    formalchemy
 
 [app:wtforms_app]
 use = egg:pyconjp2011.wtforms_demo