Commits

ont committed b8ac768

(+) pw2js (peewee to json filter)

  • Participants
  • Parent commits a661cf0

Comments (0)

Files changed (3)

 import models
+from pw2js import pw2js
 from bottle import route, run, static_file
 
 @route('/cards')
 def cards_list():
     cs = list(models.Card.select().where(models.Card.count > 0))
-    return {'success' : True, 'data' : cs}
+
+    for c in cs:
+        c.fetch()
+        c.save()
+
+    return {'success' : True, 'data' : pw2js(cs, [
+        'name', 'pict', 'count'
+    ])}
 
 @route('/cards', method='POST')
 def cards_add():
 	</div>
 
 	<div class="row">
-		<div class="large-8 columns">
+		<div class="large-12 columns">
 			<h3>The Grid</h3>
             {{cards | json}}
+            <ul class="large-block-grid-3">
+                <li ng-repeat="card in cards"><img width="80%" ng-src="{{card.pict}}"></li>
+            </ul>
 
 			<!-- Grid Example -->
 			<div class="row">
 					</div>
 				</div>
 			</div>
-
-			<h3>Buttons</h3>
-
-      <div class="row">
-        <div class="large-6 columns">
-          <p><a href="#" class="small button">Small Button</a></p>
-          <p><a href="#" class="button">Medium Button</a></p>
-          <p><a href="#" class="large button">Large Button</a></p>
-        </div>
-        <div class="large-6 columns">
-          <p><a href="#" class="small alert button">Small Alert Button</a></p>
-          <p><a href="#" class="success button">Medium Success Button</a></p>
-          <p><a href="#" class="large secondary button">Large Secondary Button</a></p>
-        </div>
-      </div>
-		</div>
-
-		<div class="large-4 columns">
-			<h4>Getting Started</h4>
-			<p>We're stoked you want to try Foundation! To get going, this file (index.html) includes some basic styles you can modify, play around with, or totally destroy to get going.</p>
-
-			<h4>Other Resources</h4>
-			<p>Once you've exhausted the fun in this document, you should check out:</p>
-			<ul class="disc">
-				<li><a href="http://foundation.zurb.com/docs">Foundation Documentation</a><br />Everything you need to know about using the framework.</li>
-				<li><a href="http://github.com/zurb/foundation">Foundation on Github</a><br />Latest code, issue reports, feature requests and more.</li>
-				<li><a href="http://twitter.com/foundationzurb">@foundationzurb</a><br />Ping us on Twitter if you have questions. If you build something with this we'd love to see it (and send you a totally boss sticker).</li>
-			</ul>
 		</div>
 	</div>
 
+import collections
+
+class Jsonify(object):
+    def jsonify(self, obj, fs):
+        res = dict([(k, getattr(obj, k)) for k in fs if isinstance(k, str)])
+        return res
+
+    def __call__(self, x, fs):
+        if isinstance(x, collections.Iterable):
+            return [ self.jsonify(v, fs) for v in x ]
+        else:
+            return self.jsonify(x, fs)
+
+pw2js = Jsonify()