Permalink
Browse files

eliminate use of firstof in templates because it doesn't handle unico…

…de. fixes problems with forums that have unicode characters in title/url/sidebar etc.
  • Loading branch information...
1 parent dd7f98e commit b6f6a0ddc5c8d70c3cb493bfbad54f2fd7e0b971 @kjk committed Dec 27, 2009
View
@@ -14,7 +14,7 @@
<p>Available forums:
<ul>
{% for f in forums %}
- <li> <a href="/{{ f.url }}"> {% firstof f.title f.url %}</a></li>
+ <li> <a href="/{{ f.url }}"> {{ f.title_or_url }}</a></li>
{% endfor %}
</ul>
</p>
View
@@ -371,6 +371,8 @@ def get(self):
'forum' : forum
}
if forum:
+ forum.title_non_empty = forum.title or "Title."
+ forum.sidebar_non_empty = forum.sidebar or "Sidebar."
disable = self.request.get('disable')
enable = self.request.get('enable')
if disable or enable:
@@ -391,6 +393,7 @@ def render_rest(self, tvals, forum=None):
forumsq = db.GqlQuery("SELECT * FROM Forum")
forums = []
for f in forumsq:
+ f.title_or_url = f.title or f.url
edit_url = "/manageforums?forum_key=" + str(f.key())
if f.is_disabled:
f.enable_disable_txt = "enable"
@@ -424,6 +427,8 @@ def get(self):
return self.redirect("/manageforums")
MAX_FORUMS = 256 # if you need more, tough
forums = db.GqlQuery("SELECT * FROM Forum").fetch(MAX_FORUMS)
+ for f in forums:
+ f.title_or_url = f.title or f.url
tvals = {
'forums' : forums,
'isadmin' : users.is_current_user_admin(),
@@ -507,6 +512,7 @@ def get(self):
new_start = 0
if len(topics) == MAX_TOPICS:
new_start = start + MAX_TOPICS
+ forum.title_or_url = forum.title or forum.url
tvals = {
'siteroot' : siteroot,
'siteurl' : self.request.url,
@@ -756,6 +762,7 @@ def get(self):
if not post: return self.redirect(siteroot)
to_name = post.user_name or post.user_homepage
subject = "Re: " + (forum.title or forum.url) + " - " + post.topic.subject
+ forum.title_or_url = forum.title or forum.url
tvals = {
'siteroot' : siteroot,
'forum' : forum,
@@ -817,6 +824,7 @@ def get(self):
prevName = user.name
prevEmail = user.email
(num1, num2) = (random.randint(1,9), random.randint(1,9))
+ forum.title_or_url = forum.title or forum.url
tvals = {
'siteroot' : siteroot,
'forum' : forum,
View
@@ -31,14 +31,14 @@
<tr>
<td colspan="2" class="header">
<div>
- <h1><a href="" class="green" id="titleId">{% firstof forum.title "Title." %}</a></h1>
+ <h1><a href="" class="green" id="titleId">{{ forum.title_non_empty }}</a></h1>
<p id="taglineId">{{ forum.tagline }}</p>
</div>
</td>
</tr>
<tr>
<td class="sidebar" id="sidebarId">
- {% firstof forum.sidebar "Sidebar." %}
+ {{ forum.sidebar_non_empty }}
</td>
<td class="contents">
<p>Welcome to <b><font color="blue">Fo</font></b>rums <b><font color="blue">Fo</font></b>r Yo<b><font color="blue">u</font></b>!</p>
@@ -51,7 +51,7 @@
Existing forums:
<ul>
{% for f in forums %}
- <li> <a href="{{ f.url }}">{% firstof f.title f.url %}</a>
+ <li> <a href="{{ f.url }}">{{ f.title_or_url }}</a>
{% if f.no_edit_link %}
edit
{% else %}
@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
- <title>{% firstof forum.title forum.url %}</title>
+ <title>{{ forum.title }}</title>
<link href="/static/default.css" rel="stylesheet" type="text/css">
<script language="javascript" src="/static/default.js" type="text/javascript"></script>
</head>
@@ -14,7 +14,7 @@
<tr>
<td colspan="2" class="header">
<div>
- <h1><a href="{{ siteroot }}" class="green">{% firstof forum.title forum.url %}</a></h1>
+ <h1><a href="{{ siteroot }}" class="green">{{ forum.title_or_url }}</a></h1>
<p>{{ forum.tagline }}</p>
</div>
</td>
@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
- <title>{% firstof forum.title forum.url %}</title>
+ <title>{{ forum.title }}</title>
<link href="/static/default.css" rel="stylesheet" type="text/css">
<script language="javascript" src="/static/default.js" type="text/javascript"></script>
</head>
@@ -14,7 +14,7 @@
<tr>
<td colspan="2" class="header">
<div>
- <h1><a href="{{ siteroot }}" class="green">{% firstof forum.title forum.url %}</a></h1>
+ <h1><a href="{{ siteroot }}" class="green">{{ forum.title }}</a></h1>
<p>{{ forum.tagline }}</p>
</div>
</td>
@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
- <title>{% firstof forum.title forum.url %}</title>
+ <title>{{ forum.title_or_url }}</title>
<link href="/static/default.css" rel="stylesheet" type="text/css">
<script language="javascript" src="/static/default.js" type="text/javascript"></script>
</head>
@@ -14,7 +14,7 @@
<tr>
<td colspan="2" class="header">
<div>
- <h1><a href="{{ siteroot }}" class="green">{% firstof forum.title forum.url %}</a></h1>
+ <h1><a href="{{ siteroot }}" class="green">{{ forum.title_or_url }}</a></h1>
<p>{{ forum.tagline }}</p>
<a href="{{ siteroot }}rss" title="RSS feed"><img src="/img/rss.gif" alt="RSS feed" align="right" valign="middle" border="0" height="14" width="36"></a><br />
</div>
@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
- <title>{% firstof forum.title forum.url %}</title>
+ <title>{{ forum.title_or_url }}</title>
<link href="/static/default.css" rel="stylesheet" type="text/css">
<script language="javascript" src="/static/default.js" type="text/javascript"></script>
</head>
@@ -14,7 +14,7 @@
<tr>
<td colspan="2" class="header">
<div>
- <h1><a href="{{ siteroot }}" class="green">{% firstof forum.title forum.url %}</a></h1>
+ <h1><a href="{{ siteroot }}" class="green">{{ forum.title_or_url }}</a></h1>
<p>{{ forum.tagline }}</p>
</div>
</td>
@@ -2,7 +2,7 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
- <title>{% firstof forum.title forum.url %}</title>
+ <title>{{ forum.title_or_url }}</title>
<link href="/static/default.css" rel="stylesheet" type="text/css">
<script language="javascript" src="/static/default.js" type="text/javascript"></script>
<link type="application/rss+xml" rel="alternate" title="Discussion Group" href="{{ siteroot }}rss">
@@ -15,7 +15,7 @@
<tr>
<td colspan="2" class="header">
<div>
- <h1><a href="{{ siteroot }}" class="green">{% firstof forum.title forum.url %}</a></h1>
+ <h1><a href="{{ siteroot }}" class="green">{{ forum.title_or_url }}</a></h1>
<p>{{ forum.tagline }}</p>
</div>
<a href="{{ siteroot }}rss" title="RSS feed"><img src="/img/rss.gif" alt="RSS feed" align="right" valign="middle" border="0" height="14" width="36"></a><br />
View
@@ -12,6 +12,8 @@ TODO must have:
post form based on a wrong cookie). When not logged in, replying
to a post fills out user info based on the orignal poster, not the
person who's replying
+ - urllib.quote() on unicode doesn't work, they have to be converted to
+ utf8 (I think).
TODO nice to have:
- comment count should only count non-deleted posts

0 comments on commit b6f6a0d

Please sign in to comment.