whole bunch of changes to make things work cleanly on the server
author<mako@atdot.cc> <>
Mon, 17 Sep 2007 00:01:04 +0000 (20:01 -0400)
committer<mako@atdot.cc> <>
Mon, 17 Sep 2007 00:01:04 +0000 (20:01 -0400)
ruler_gallery_db.sql
templates/gallery.tmpl
templates/index.tmpl
templates/show_ruler.tmpl
templates/site.tmpl
templates/style.css.tmpl [moved from static/style.css with 78% similarity]
yourule.py

index 43079e67d2ccd43de6d8f1ddf8aeeb949c0ed35b..863af503e39aae2278c9bc656a6339de288df77f 100644 (file)
@@ -1,11 +1,12 @@
 DROP TABLE IF EXISTS gallery;
 CREATE TABLE gallery (
 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)
 );
 
 
 );
 
 
index b80b538d89571e2b7e74dbd2e00dd3e7d6cf2b96..ecfd4fdb263926d59216adfcaa2eb389e27c3a5d 100644 (file)
@@ -18,9 +18,9 @@
   <td><%= ruler.pixel_width %></td>
   <td><%= ruler.cm_width() %>/<%= ruler.in_width() %></td>
   <td>
   <td><%= ruler.pixel_width %></td>
   <td><%= ruler.cm_width() %>/<%= ruler.in_width() %></td>
   <td>
-    <a href="/show/ruler_<%= ruler.pixel_width %>px_<%= ruler.cm_width() %>centimeters.png?fromgallery=true">cm</a>/<a href="/show/ruler_<%= ruler.pixel_width %>px_<%= ruler.in_width() %>inches.png?fromgallery=true">in</a>
+    <a href="<%= homepath %>/show/ruler_<%= ruler.pixel_width %>px_<%= ruler.cm_width() %>centimeters.png?fromgallery=true">cm</a>/<a href="<%= homepath %>/show/ruler_<%= ruler.pixel_width %>px_<%= ruler.in_width() %>inches.png?fromgallery=true">in</a>
   </td>
   </td>
-  <td><form method="GET" action="delete/<%= ruler.id %>" style="display:inline;">
+  <td><form method="GET" action="<%= homepath %>/delete/<%= ruler.id %>" style="display:inline;">
       <input type="submit" value="delete" /></form></td>
 </tr>
 <% endfor %>
       <input type="submit" value="delete" /></form></td>
 </tr>
 <% endfor %>
@@ -37,7 +37,7 @@ form.</p>
 <%= errormsg %>
 </div>
 <% endif %>
 <%= errormsg %>
 </div>
 <% endif %>
-<form method="POST" action="/gallery">
+<form method="POST" action="<%= homepath %>/gallery">
 
 <% include '_form_elements.tmpl' %>
 
 
 <% include '_form_elements.tmpl' %>
 
index 5f3f352be4bc245607239d6876472f7b278fc3d4..bcac6d974cfe6be5032b90a72d4753a88026fa4e 100644 (file)
@@ -6,7 +6,7 @@
 
 <p>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 <a
 
 <p>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 <a
-href="/gallery">ruler gallery</a>.</p>
+href="<%= homepath %>/gallery">ruler gallery</a>.</p>
 
 <h2>Create Custom Ruler</h2>
 
 
 <h2>Create Custom Ruler</h2>
 
@@ -17,11 +17,11 @@ href="/gallery">ruler gallery</a>.</p>
 </div>
 <% endif %>
 
 </div>
 <% endif %>
 
-<form method="POST" action="/">
+<form method="POST" action="<%= homepath %>/">
 
 <% include '_form_elements.tmpl' %>
 
 <input type="Submit" name="submit" value="Generate" />
 
 <% include '_form_elements.tmpl' %>
 
 <input type="Submit" name="submit" value="Generate" />
-<form>
+</form>
 
 <% endblock %>
 
 <% endblock %>
index d10b380cbc458a74d7a07de3d1ee047b17b9d53d..bcdf7fae2e4e6a078f9568f305cf0d4476a68170 100644 (file)
@@ -1,19 +1,19 @@
 <html>
 <head>
 <html>
 <head>
-<link rel="stylesheet" type="text/css" href="/static/style.css" />
+<link rel="stylesheet" type="text/css" href="<%= homepath %>/style.css" />
 </head>
 <p id="menu">
 </head>
 <p id="menu">
-<a href="/show/<%= other_unit_url %>">show in <%= other_unit %></a>
+<a href="<%= homepath %>/show/<%= other_unit_url %>">show in <%= other_unit %></a>
 /
 <% if fromgallery %>
 /
 <% if fromgallery %>
-<a href="/gallery">back to gallery</a>
+<a href="<%= homepath %>/gallery">back to gallery</a>
 <% else %>
 <% else %>
-<a href="/gallery/<%= ruler_url %>">save for others</a>
+<a href="<%= homepath %>/gallery/<%= ruler_url %>">save for others</a>
 <% endif %>
 </p>
 
 <div id="rulerimg">
 <% endif %>
 </p>
 
 <div id="rulerimg">
-<img src="/<%= ruler_url %>" alt="<%= ruler_url %>" />
+<img src="<%= homepath %>/<%= ruler_url %>" alt="<%= ruler_url %>" />
 </div>
 
 
 </div>
 
 
index d9eaad372ce7a212300ac1e09c8b30ff23e893d1..3c497efa25c200ba8c809ced9692ade9c6ecbef0 100644 (file)
@@ -1,14 +1,15 @@
 <html>
 <head>
 <html>
 <head>
-  <link rel="stylesheet" type="text/css" href="/static/style.css" />
-  <script src="/static/prototype.js" type="text/javascript"></script>
+  <link rel="stylesheet" type="text/css" href="<%= homepath %>/style.css" />
+  <script src="<%= homepath %>/static/prototype.js" type="text/javascript"></script>
   <title>You Rule</title>
 </head>
 <body>
 <div id="wrapper">
 <div id="header">
   <title>You Rule</title>
 </head>
 <body>
 <div id="wrapper">
 <div id="header">
-<h1>YouRule</h1>
-<h2>Onscreen Ruler Generator</h2>
+<a href="<%= homepath %>"
+<img src="<%= homepath %>/static/images/yourule_banner.png" alt="YouRule" />
+</a>
 </div>
 
 <div class="mainbox">
 </div>
 
 <div class="mainbox">
similarity index 78%
rename from static/style.css
rename to templates/style.css.tmpl
index b5891575b8ef1abc461dccf2407ca532cce1b628..5fe6171f0700a9501a4a0e18bf50337316754512 100644 (file)
@@ -39,7 +39,11 @@ em {
 #header {
   width: 885px;
   height: 138px;
 #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 {
 }
 
 #header h1, #header h2 {
@@ -48,23 +52,23 @@ em {
 
 .mainbox {
   margin-top: 1em;
 
 .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 {
 }
 
 .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 {
 }
 
 .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 {
 }
 
 .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 {
 }
 
 .mainbox_content {
-  background: url(/static/images/r.png) top right repeat-y;
+  background: url(<%= homepath %>/static/images/r.png) top right repeat-y;
 }
 
 
 }
 
 
index d6f44bdfbabe0ed7b1b57527ceb2e335c656cfae..2e4022b872c88c5aa4c2a6ae0d808f095e8d2768 100755 (executable)
@@ -13,11 +13,16 @@ from jinja import Environment, FileSystemLoader
 jinja_env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>', 
                         loader=FileSystemLoader(os.path.dirname(__file__) + "/templates/"))
 
 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')
     tmpl = jinja_env.get_template(filename + '.tmpl')
+    vars['homepath'] = web.ctx.homepath
+    vars['ctx'] = web.ctx
     print tmpl.render(vars)
     print tmpl.render(vars)
-    print web.ctx
 
 # the url map for the application
 urls = ( '/?', 'index',
 
 # 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',
          '/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)
 
 
 store = Store(database)
 
@@ -39,7 +44,7 @@ class Ruler(object):
     unit_width = Float()
     model = Unicode()
     units = Unicode()
     unit_width = Float()
     model = Unicode()
     units = Unicode()
-    show = Int()
+    visible = Int()
     cm_in_ratio = 0.3937
 
     def __init__(self, **kw):
     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]
 
         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):
         render('gallery', locals())
 
     def POST(self, ruler_url):
@@ -161,14 +172,14 @@ class gallery:
             store.add(new_ruler)
             store.commit()
 
             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))
         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')
 
         store.commit()
         web.redirect('/gallery')
 
@@ -176,10 +187,14 @@ class delete:
 class undelete:
     def GET(self, id):
         ruler = store.get(Ruler, int(id))
 class undelete:
     def GET(self, id):
         ruler = store.get(Ruler, int(id))
-        ruler.show = 1
+        ruler.visible = 1
         store.commit()
         web.redirect('/gallery')
 
         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]
 
 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)
 
     new_ruler = Ruler(pixel_width=pixel_width, unit_width=unit_width,
                       units=units)
 
-    web.debug(units)
     return(units, new_ruler.url())
 
 
     return(units, new_ruler.url())
 
 

Benjamin Mako Hill || Want to submit a patch?