Permalink
Browse files

Data.js generation now works on the server

  • Loading branch information...
1 parent ad511c1 commit a21aaaebf3783c4e1afdfd4d1a3a832fa526020e @fbreuer fbreuer committed Mar 6, 2012
Showing with 11 additions and 11 deletions.
  1. +9 −9 jsoninterface.py
  2. +2 −2 main.py
View
18 jsoninterface.py
@@ -149,13 +149,13 @@ def generatePage(self):
# add blogs
for blog in Feed.gql("WHERE category IN :1", ['history','fun','general','commercial','art','visual','pure','applied','teacher','journalism']):
id = blog.key().id_or_name()
- output["/blog/"+id] = {
+ output["/blog/"+str(id)] = {
"type": "/type/blog",
"name": blog.title,
"url": blog.homepage,
- "posts": [ "/post/" + post.key().id_or_name() for post in Post.gql("WHERE service = :1 ORDER BY timestamp_created DESC LIMIT 10", blog.title)],
+ "posts": [ "/post/" + str(post.key().id_or_name()) for post in Post.gql("WHERE service = :1 ORDER BY timestamp_created DESC LIMIT 10", blog.title)],
"category": blog.category,
- "tags": [ "/tag/" + tag.key().id_or_name() for tag in Tag.gql("WHERE blogs = :1", blog.key().id_or_name()) ],
+ "tags": [ "/tag/" + str(tag.key().id_or_name()) for tag in Tag.gql("WHERE blogs = :1", blog.key().id_or_name()) ],
"language": blog.language,
"comments-day": blog.comments_day,
"comments-week": blog.comments_week,
@@ -165,23 +165,23 @@ def generatePage(self):
# add posts
for post in Post.gql("WHERE category IN :1 ORDER BY timestamp_created DESC LIMIT 150", ['history','fun','general','commercial','art','visual','pure','applied','teacher','journalism']):
id = post.key().id_or_name()
- output["/post/"+id] = {
+ output["/post/"+str(id)] = {
"type": "/type/post",
"title": post.title,
"url": post.link,
- "blog": "/blog/" + Feed.gql("WHERE title = :1", post.service).get().key().id_or_name(),
+ "blog": "/blog/" + str(Feed.gql("WHERE title = :1", post.service).get().key().id_or_name()),
"date": post.timestamp_created.strftime('%B %d,%Y %I:%M:%S %p'),
- "tags": ["/tag/" + Tag.gql("WHERE name = :1", tag).get().key().id_or_name() for tag in post.tags ], # TODO: access Tag by key of post!,
+ "tags": ["/tag/" + str(Tag.gql("WHERE name = :1", tag).get().key().id_or_name()) for tag in post.tags ], # TODO: access Tag by key of post!,
"length": post.length
}
# add tags
for tag in Tag.all():
id = tag.key().id_or_name()
- output["/tag/"+id] = {
+ output["/tag/"+str(id)] = {
"type": "/type/tag",
"name": tag.name,
- "blogs": [ "/blog/" + blogid for blogid in tag.blogs],
- "posts": [ "/post/" + postid for postid in tag.posts]
+ "blogs": [ "/blog/" + str(blogid) for blogid in tag.blogs],
+ "posts": [ "/post/" + str(postid) for postid in tag.posts]
}
# TODO cleanup broken links (maybe Data.js handles them gracefully?)
return simplejson.dumps(output)
View
4 main.py
@@ -731,7 +731,7 @@ def get(self):
from weeklypicks import *
from statsview import * ### TODO make like dateview all, research, teacher, hisartivs
from feedspage import *
-from jsoninterface import PostsJSONP, BlogsJSONP, TagsJSONP, DataJSONP
+from jsoninterface import PostsJSONP, BlogsJSONP, TagsJSONP, DataJSONP, DataJS
@@ -763,7 +763,7 @@ def main():
('/cse-config', CSEConfig), ## TODO not up to date at all...
('/json', PostsJSONExport),
(r'/picksjsonp.*', WeeklyPicksJSONPHandler),
- (r'/jsonp/data.*', DataJSONP),
+ (r'/jsonp/data.*', DataJS), # we're serving JSON in Data.js format here
(r'/jsonp/blogs.*', BlogsJSONP),
(r'/jsonp/posts.*', PostsJSONP),
(r'/jsonp/tags.*', TagsJSONP),

0 comments on commit a21aaae

Please sign in to comment.