Skip to content
Browse files

add Nagare in examples

  • Loading branch information...
1 parent a9b6892 commit aea43b1c089d2bb24b507f789447d29de1617113 Vincent committed Nov 9, 2010
View
0 nagare/conf/__init__.py
No changes.
View
10 nagare/conf/so_starving.cfg
@@ -0,0 +1,10 @@
+[application]
+path = app so_starving
+name = so_starving
+debug = off
+
+[database]
+activated = off
+uri = sqlite:///$here/../data/so_starving.db
+metadata = so_starving.models:__metadata__
+debug = off
View
0 nagare/data/__init__.py
No changes.
View
23 nagare/setup.py
@@ -0,0 +1,23 @@
+VERSION = '0.0.1'
+
+from setuptools import setup, find_packages
+
+setup(
+ name = 'so_starving',
+ version = VERSION,
+ author = 'Vincent Rialland',
+ author_email = 'vincent.rialland@net-ng.com',
+ description = 'The "I am so starving example with the Nagare framework (http://agiliq.com/blog/2010/11/i-am-so-starving-same-web-app-in-various-python-we/)',
+ license = '',
+ keywords = '',
+ url = '',
+ packages = find_packages(),
+ include_package_data = True,
+ package_data = {'' : ['*.cfg']},
+ zip_safe = False,
+ install_requires = ('nagare', 'simplejson', 'werkzeug'),
+ entry_points = """
+ [nagare.applications]
+ so_starving = so_starving.app:app
+ """
+ )
View
0 nagare/so_starving/__init__.py
No changes.
View
37 nagare/so_starving/app.py
@@ -0,0 +1,37 @@
+from __future__ import with_statement
+from werkzeug.contrib.cache import SimpleCache
+from nagare import component, presentation
+
+import simplejson
+import urllib
+
+cache = SimpleCache()
+
+class SoStarving(object):
+ def get_fb_data(self):
+ fml_endpoint = 'http://graph.facebook.com/search?q="fun&type=post'
+ fb_data = cache.get(key=fml_endpoint)
+ if not fb_data:
+ fb_response = urllib.urlopen(fml_endpoint,).read()
+ fb_data = simplejson.loads(fb_response)["data"]
+ cache.set(fml_endpoint, fb_data, 30 * 60)
+ return fb_data
+
+
+@presentation.render_for(SoStarving)
+def render(self, h, *args):
+ h << h.head.title(u'FMl')
+ h << h.head.css(h.generate_id(), '''.author{ font-style:italic; }
+li { list-style: none; }
+.picture, .message { float: left; }''')
+ with h.ul:
+ for post in self.get_fb_data():
+ with h.li:
+ with h.div:
+ h << h.div(h.img(src='https://graph.facebook.com/'+post['from']['id']+'/picture'), class_='picture')
+ h << h.div(post.get('message', u''), u' : ', h.span(post['from']['name'], class_='author'), class_='message')
+ return h.root
+
+# ---------------------------------------------------------------
+
+app = SoStarving
View
6 nagare/so_starving/models.py
@@ -0,0 +1,6 @@
+from elixir import *
+from sqlalchemy import MetaData
+
+__metadata__ = MetaData()
+
+# Here, put the definition of your Elixir or SQLAlchemy models
View
0 nagare/static/__init__.py
No changes.

0 comments on commit aea43b1

Please sign in to comment.
Something went wrong with that request. Please try again.