Unicode strings and flexible paths master
authordanigm <danigm@wadobo.com>
Mon, 23 May 2011 10:03:45 +0000 (12:03 +0200)
committerdanigm <danigm@wadobo.com>
Mon, 23 May 2011 10:06:07 +0000 (12:06 +0200)
proposal/app.py
proposal/config.py
proposal/db.py
proposal/templates/index.html
proposal/templates/layout.html
proposal/templates/proposal.html
proposal/view/prop.py

index a2abe31..6e295a2 100755 (executable)
@@ -39,6 +39,7 @@ def session_hook():
     # templates
     context = {'static': config.static,
                '_': web.ctx.gettext,
+               'path': config.path,
                'markdown': markdown}
     normal_render = web.template.render('templates', globals=context)
     context['render'] = normal_render
@@ -68,6 +69,7 @@ def get_gettext(lang='es'):
     return gtx.gettext
 
 app.add_processor(load_sqla)
+#web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
 
 if __name__ == '__main__':
     app.run()
index 476db12..bce62d3 100644 (file)
@@ -5,6 +5,10 @@ DB = 'sqlite:///database.sqlite'
 static = '/static'
 
 curdir = os.path.abspath(os.path.dirname(__file__))
+base = ''
 
 # i18n directory.
 localedir = curdir + '/i18n'
+
+def path(p):
+    return base + p
index 7212b17..d57697a 100644 (file)
@@ -13,7 +13,7 @@ metadata = Base.metadata
 class Tag(Base):
     __tablename__ = 'tags'
 
-    name = Column(String(60), primary_key=True)
+    name = Column(Unicode(60), primary_key=True)
 
     def __unicode__(self):
         return '<Tag "%s">' % self.name
@@ -23,12 +23,12 @@ class Proposal(Base):
     __tablename__ = 'proposals'
 
     id = Column(Integer, primary_key=True)
-    name = Column(String(100))
-    desc = Column(String)
+    name = Column(Unicode(100))
+    desc = Column(UnicodeText)
     votes = Column(Integer)
 
     tags_proposals = Table('tags_proposals', metadata,
-            Column('tag_id', String, ForeignKey('tags.name')),
+            Column('tag_id', Unicode(60), ForeignKey('tags.name')),
             Column('proposal_id', Integer, ForeignKey('proposals.id')))
 
     tags = relation('Tag', secondary=tags_proposals, backref='proposals')
@@ -38,7 +38,7 @@ class Comment(Base):
     __tablename__ = 'comments'
 
     id = Column(Integer, primary_key=True)
-    html = Column(String)
+    html = Column(UnicodeText)
 
     proposal_id = Column(Integer, ForeignKey('proposals.id'))
 
index bfd3bca..9f983bf 100644 (file)
@@ -5,7 +5,7 @@ $var jsfiles: js/index.js
 $var title: Proposal
 
 <div id="new_proposal">
-    <form method="POST" action="$action">
+    <form method="POST" action="$(path(action))">
         <div id="prop_name" class="gray"> $:prop_form.name.render() </div>
         <div id="prop_desc" class="gray"> $:prop_form.desc.render() </div>
         $:prop_form.send.render()
index 76baaa2..a476fdc 100644 (file)
@@ -17,7 +17,7 @@ $def with (content)
     <body>
         <div id="content">
             <div id="header">
-                <a href="/"><img src="$static/imgs/logo.png" alt="proposals"/></a>
+                <a href="$path("/")"><img src="$static/imgs/logo.png" alt="proposals"/></a>
             </div>
             $:content
             <div id="footer">
index fe1775b..700a1e6 100644 (file)
@@ -4,9 +4,9 @@ $def with (proposals, trim=False)
     $for proposal in proposals:
     <div class="proposal $loop.parity">
         <div class="vote">
-            <a class="vote_up" href="/vote/$proposal.id/1"><img src="$static/imgs/up.png" alt="+"/></a>
+            <a class="vote_up" href="$(path("/vote/%s/1" % proposal.id))"><img src="$static/imgs/up.png" alt="+"/></a>
             <br/>
-            <a class="vote_down" href="/vote/$proposal.id/-1"><img src="$static/imgs/down.png" alt="-"/></a>
+            <a class="vote_down" href="$(path("/vote/%s/-1" % proposal.id))"><img src="$static/imgs/down.png" alt="-"/></a>
             <br/>
             <span class="votes">$proposal.votes</span>
         </div>
@@ -14,7 +14,7 @@ $def with (proposals, trim=False)
             <a href="/edit/$proposal.id">$_("Edit")</a>
             <a href="/del/$proposal.id">$_("Delete")</a>
         </div>
-        <h2><a href="/view/$proposal.id">$proposal.name</a></h2>
+        <h2><a href="$(path("/view/%s" % proposal.id))">$proposal.name</a></h2>
         $if trim:
             $proposal.desc[:250]
             $if len(proposal.desc) > 250:
@@ -23,7 +23,7 @@ $def with (proposals, trim=False)
             $:markdown(proposal.desc)
         <div class="prop_tags">
             $for tag in proposal.tags:
-                <a href="/view/tag/$tag.name">$tag.name</a>
+                <a href="$(path("/view/tag/%s" % tag.name))">$tag.name</a>
                 $if not loop.last:
                     ,
         </div>
@@ -35,7 +35,7 @@ $def with (proposals, trim=False)
                     <div class="comment $loop.parity">
                         $:markdown(comment.html)
                     </div>
-                <form method="POST" action="/comment/$proposal.id">
+                <form method="POST" action="$(path("/comment/%s" % proposal.id))">
                     <textarea class="comment_input" name="comment"></textarea>
                     <br/>
                     <input type="submit" value="$_("Send")"/>
index 235e6b0..9d1d341 100644 (file)
@@ -1,6 +1,7 @@
 import web
 import db
 import re
+import config
 
 from sqlalchemy import desc
 
@@ -53,7 +54,7 @@ class New:
         prop.tags = tags
         orm.add(prop)
 
-        raise web.seeother('/')
+        raise web.seeother(config.path('/'))
 
 
 class Edit:
@@ -88,7 +89,7 @@ class Edit:
         prop.desc = desc
         prop.tags = tags
 
-        raise web.seeother('/')
+        raise web.seeother(config.path('/'))
 
 
 class View:
@@ -109,7 +110,7 @@ class Del:
         prop = orm.query(db.Proposal).get(id)
         orm.delete(prop)
 
-        raise web.seeother('/')
+        raise web.seeother(config.path('/'))
 
 
 class ViewTag: