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)
);
<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><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 %>
<%= errormsg %>
</div>
<% endif %>
-<form method="POST" action="/gallery">
+<form method="POST" action="<%= homepath %>/gallery">
<% include '_form_elements.tmpl' %>
<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>
</div>
<% endif %>
-<form method="POST" action="/">
+<form method="POST" action="<%= homepath %>/">
<% include '_form_elements.tmpl' %>
<input type="Submit" name="submit" value="Generate" />
-<form>
+</form>
<% endblock %>
<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">
-<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 %>
-<a href="/gallery">back to gallery</a>
+<a href="<%= homepath %>/gallery">back to gallery</a>
<% 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">
-<img src="/<%= ruler_url %>" alt="<%= ruler_url %>" />
+<img src="<%= homepath %>/<%= ruler_url %>" alt="<%= ruler_url %>" />
</div>
<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">
-<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">
#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 {
.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;
}
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',
'/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)
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())