changeset 7:9a835002fe49

Fix URL generation bugs discovered in tesing on deployment server.
author Daniele Nicolodi <nicoldi@science.unitn.it>
date Wed, 15 Jun 2011 15:55:40 +0200
parents ceb5df800c51
children d6bedd937d10
files src/ltpdarepo/__init__.py src/ltpdarepo/templates/layout.html src/ltpdarepo/templates/query.html
diffstat 3 files changed, 13 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/ltpdarepo/__init__.py	Wed Jun 15 12:49:46 2011 +0200
+++ b/src/ltpdarepo/__init__.py	Wed Jun 15 15:55:40 2011 +0200
@@ -1,4 +1,5 @@
-from flask import Flask, g, request, session, render_template, Markup, redirect, flash
+from urlparse import urljoin
+from flask import Flask, g, request, session, render_template, Markup, redirect, flash, url_for
 from pkg_resources import get_distribution
 import MySQLdb as mysql
 
@@ -59,13 +60,13 @@
 
 @app.template_filter('breadcrumbs')
 def breadcrumbs(path):
-    url = ['', ]
+    url = []
     parts = []
     for item in path.split('/')[1:-1]:
         url.append(item)
         if item:
-            parts.append((item, '/'.join(url)))
-    out = ['<a href="/">home</a>', ]
+            parts.append((item, urljoin(url_for('.index'), '/'.join(url))))
+    out = ['<a href="%s">home</a>' % url_for('.index'), ]
     for name, href in parts[1:]:
         out.append('<a href="%s">%s</a>' % (href, name))
     if len(out) > 1:
@@ -78,7 +79,7 @@
     if request.method == 'POST':
         if authenticate(request.form['username'], request.form['password']):
             session['username'] = request.form['username']
-            url = request.args.get('next', '/')
+            url = urljoin(url_for('.index'), request.args.get('next', ''))
             return redirect(url)
         flash('Login failed.', category='error')
 
@@ -88,7 +89,7 @@
 @app.route('/logout')
 def logout():
     session.pop('username', None)
-    return redirect('/')
+    return redirect(url_for('.index'))
 
 
 @app.route('/')
--- a/src/ltpdarepo/templates/layout.html	Wed Jun 15 12:49:46 2011 +0200
+++ b/src/ltpdarepo/templates/layout.html	Wed Jun 15 15:55:40 2011 +0200
@@ -4,13 +4,13 @@
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
     <title>{% block title %} {% endblock %} &mdash; LTPDA Repository</title>
-    <link rel="stylesheet" type="text/css" href="/static/style.css"></link>
+    <link rel="stylesheet" type="text/css" href="{{ url_for('.static', filename='style.css') }}"></link>
     {%- block head %}{% endblock %}
   </head>
   <body>
 
     <div class="header"><div>      
-      <h1><a href="/">LTPDA Repository</a></h1>
+      <h1><a href="{{ url_for('.index') }}">LTPDA Repository</a></h1>
       <span>{{ request.host }}</span>
     </div></div>
 
@@ -25,9 +25,9 @@
         <a href="{{ url_for('.logout') }}">logout</a>
         {% endif %}
       </div>
-
+      
       <div class="clear">&nbsp;</div>
-  
+      
       {% for category, message in get_flashed_messages(True) %}
       <div class="flash {{ category }}">{{ message }}</div>
       {% endfor %}
--- a/src/ltpdarepo/templates/query.html	Wed Jun 15 12:49:46 2011 +0200
+++ b/src/ltpdarepo/templates/query.html	Wed Jun 15 15:55:40 2011 +0200
@@ -1,8 +1,8 @@
 {% extends "layout.html" %}
 {% block title %}{{ database.id }}{% endblock %}
 {% block head %}
-    <script type="text/javascript" src="/static/jquery.js"></script>
-    <script type="text/javascript" src="/static/querywidget.js"></script>
+    <script type="text/javascript" src="{{ url_for('.static', filename='jquery.js') }}"></script>
+    <script type="text/javascript" src="{{ url_for('.static', filename='querywidget.js') }}"></script>
     <script type="text/javascript">
       var criteria = {{ criteria|tojson|safe }};
     </script>