From: Date: Mon, 17 Sep 2007 00:01:04 +0000 (-0400) Subject: whole bunch of changes to make things work cleanly on the server X-Git-Url: https://projects.mako.cc/source/yourule/commitdiff_plain/e9647b2143c8c4ec343d66ad3083aabd77659b14?hp=c61d6a6300242da86d532d34bb0506e04c9de658 whole bunch of changes to make things work cleanly on the server --- diff --git a/ruler_gallery_db.sql b/ruler_gallery_db.sql index 43079e6..863af50 100644 --- a/ruler_gallery_db.sql +++ b/ruler_gallery_db.sql @@ -1,11 +1,12 @@ DROP TABLE IF EXISTS gallery; CREATE TABLE gallery ( - id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, - pixel_width REAL NOT NULL, - unit_width REAL NOT NULL, - units VARCHAR(100) NOT NULL, - model VARCHAR(255) NOT NULL, - show INTEGER NOT NULL DEFAULT 1 + id integer not null auto_increment, + pixel_width float not null, + unit_width float not null, + units VARCHAR(100) not null, + model VARCHAR(255) not null, + visible tinyint not null default 1, + primary key (id) ); diff --git a/templates/gallery.tmpl b/templates/gallery.tmpl index b80b538..ecfd4fd 100644 --- a/templates/gallery.tmpl +++ b/templates/gallery.tmpl @@ -18,9 +18,9 @@ <%= ruler.pixel_width %> <%= ruler.cm_width() %>/<%= ruler.in_width() %> - cm/in + cm/in -
+
<% endfor %> @@ -37,7 +37,7 @@ form.

<%= errormsg %> <% endif %> -
+ <% include '_form_elements.tmpl' %> diff --git a/templates/index.tmpl b/templates/index.tmpl index 5f3f352..bcac6d9 100644 --- a/templates/index.tmpl +++ b/templates/index.tmpl @@ -6,7 +6,7 @@

To view a list of rulers others have created or to save your ruler so that others with your computer can find it, visit the ruler gallery.

+href="<%= homepath %>/gallery">ruler gallery.

Create Custom Ruler

@@ -17,11 +17,11 @@ href="/gallery">ruler gallery.

<% endif %> - + <% include '_form_elements.tmpl' %> - +
<% endblock %> diff --git a/templates/show_ruler.tmpl b/templates/show_ruler.tmpl index d10b380..bcdf7fa 100644 --- a/templates/show_ruler.tmpl +++ b/templates/show_ruler.tmpl @@ -1,19 +1,19 @@ - +
-<%= ruler_url %> +<%= ruler_url %>
diff --git a/templates/site.tmpl b/templates/site.tmpl index d9eaad3..3c497ef 100644 --- a/templates/site.tmpl +++ b/templates/site.tmpl @@ -1,14 +1,15 @@ - - + + You Rule
diff --git a/static/style.css b/templates/style.css.tmpl similarity index 78% rename from static/style.css rename to templates/style.css.tmpl index b589157..5fe6171 100644 --- a/static/style.css +++ b/templates/style.css.tmpl @@ -39,7 +39,11 @@ em { #header { width: 885px; height: 138px; - background: url(/static/images/yourule_banner.png); + /* background: url(<%= homepath %>/static/images/yourule_banner.png); */ +} + +#header a img { + border: none; } #header h1, #header h2 { @@ -48,23 +52,23 @@ em { .mainbox { margin-top: 1em; - background: url(/static/images/tl.png) no-repeat top left; + background: url(<%= homepath %>/static/images/tl.png) no-repeat top left; } .mainbox_top { - background: url(/static/images/tr.png) no-repeat top right; + background: url(<%= homepath %>/static/images/tr.png) no-repeat top right; } .mainbox_bottom { - background: url(/static/images/bl.png) no-repeat bottom left; + background: url(<%= homepath %>/static/images/bl.png) no-repeat bottom left; } .mainbox_bottom div { - background: url(/static/images/br.png) no-repeat bottom right; + background: url(<%= homepath %>/static/images/br.png) no-repeat bottom right; } .mainbox_content { - background: url(/static/images/r.png) top right repeat-y; + background: url(<%= homepath %>/static/images/r.png) top right repeat-y; } diff --git a/yourule.py b/yourule.py index d6f44bd..2e4022b 100755 --- a/yourule.py +++ b/yourule.py @@ -13,11 +13,16 @@ from jinja import Environment, FileSystemLoader jinja_env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>', loader=FileSystemLoader(os.path.dirname(__file__) + "/templates/")) -def render(filename, vars): - web.header("Content-Type","text/html; charset=utf-8") +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") + tmpl = jinja_env.get_template(filename + '.tmpl') + vars['homepath'] = web.ctx.homepath + vars['ctx'] = web.ctx print tmpl.render(vars) - print web.ctx # the url map for the application urls = ( '/?', 'index', @@ -25,10 +30,10 @@ urls = ( '/?', 'index', '/show/(.*(svg|png|jpg))', 'show_ruler', '/gallery(.*)', 'gallery', '/delete/(\d+)', 'delete', - '/undelete/(\d+)', 'undelete') + '/undelete/(\d+)', 'undelete', + '/style.css', 'css') -database = create_database("sqlite:%s/db/yourule.db" % - os.path.dirname(__file__)) +database = create_database("mysql:yourule") store = Store(database) @@ -39,7 +44,7 @@ class Ruler(object): unit_width = Float() model = Unicode() units = Unicode() - show = Int() + visible = Int() cm_in_ratio = 0.3937 def __init__(self, **kw): @@ -136,8 +141,14 @@ class gallery: 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): @@ -161,14 +172,14 @@ class gallery: 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') @@ -176,10 +187,14 @@ class delete: 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] @@ -196,7 +211,6 @@ def get_other_unit(url): new_ruler = Ruler(pixel_width=pixel_width, unit_width=unit_width, units=units) - web.debug(units) return(units, new_ruler.url())