#!/usr/bin/env python
+# YouRule: Onscreen Ruler Generator
+#
+# Copyright (C) 2007 Benjamin Mako Hill <mako@atdot.cc>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the Affero General Public License as published
+# by the Free Software Foundation, either version 1 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the Affero General Public License
+# along with this program. If not, see
+# <http://http://www.affero.org/oagpl.html>.
+
+
from __future__ import division
import web
import sys, os, re
from storm.locals import *
+
+# recalculate the path based on the location of the file
+sys.path.append(os.path.dirname(__file__))
from svgruler import SVGRuler
from jinja import Environment, FileSystemLoader
jinja_env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>',
- loader=FileSystemLoader('templates/'))
+ loader=FileSystemLoader(os.path.dirname(__file__) + "/templates/"))
+
+def render(filename, vars={}):
+ if re.match(r'.+\.\css$', filename):
+ web.header("Content-Type","text/css; charset=utf-8")
+ else:
+ web.header("Content-Type","text/html; charset=utf-8")
-def render(filename, vars):
- web.header("Content-Type","text/html; charset=utf-8")
tmpl = jinja_env.get_template(filename + '.tmpl')
+ vars['homepath'] = web.ctx.homepath
+ vars['ctx'] = web.ctx
print tmpl.render(vars)
- web.debug(web.ctx)
# the url map for the application
-urls = ( '/', 'index',
+urls = ( '/?', 'index',
'/ruler_([0-9\.]+)px_([0-9\.]+)([A-Za-z]+).(svg|png|jpg)', 'ruler_img',
'/show/(.*(svg|png|jpg))', 'show_ruler',
'/gallery(.*)', 'gallery',
'/delete/(\d+)', 'delete',
- '/undelete/(\d+)', 'undelete')
+ '/undelete/(\d+)', 'undelete',
+ '/style.css', 'css')
+
+database = create_database("mysql:yourule")
-database = create_database("sqlite:yourule.db")
store = Store(database)
class Ruler(object):
unit_width = Float()
model = Unicode()
units = Unicode()
- show = Int()
+ visible = Int()
cm_in_ratio = 0.3937
def __init__(self, **kw):
if ruler_url:
pixel_width, unit_width, units = process_ruler_url(ruler_url)[0:3]
- rulers = store.find(Ruler, Ruler.show == 1)
- rulers.order_by(Ruler.model)
+ new_rulers = store.find(Ruler, Ruler.visible == 1)#.order_by(Ruler.model)
+
+ rulers = []
+ for ruler in new_rulers:
+ rulers.append(ruler)
+
+ #rulers = map(lambda x: x, rulers)
+
render('gallery', locals())
def POST(self, ruler_url):
store.add(new_ruler)
store.commit()
- rulers = store.find(Ruler, Ruler.show == 1)
- rulers.order_by(Ruler.model)
+ rulers = store.find(Ruler, Ruler.visible == 1)
+ #rulers.order_by(Ruler.model)
render('gallery', locals())
class delete:
def GET(self, id):
ruler = store.get(Ruler, int(id))
- ruler.show = 0
+ ruler.visible = 0
store.commit()
web.redirect('/gallery')
class undelete:
def GET(self, id):
ruler = store.get(Ruler, int(id))
- ruler.show = 1
+ ruler.visible = 1
store.commit()
web.redirect('/gallery')
+class css:
+ def GET(self):
+ render('style.css')
+
def get_other_unit(url):
pixel_width, unit_width, units = process_ruler_url(url)[0:3]
new_ruler = Ruler(pixel_width=pixel_width, unit_width=unit_width,
units=units)
- web.debug(units)
return(units, new_ruler.url())
if __name__ == "__main__":
web.run(urls, globals(), web.reloader)
-#application = web.wsgifunc(web.webpyfunc(urls, globals()))
+application = web.wsgifunc(web.webpyfunc(urls, globals()))