Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add feed

  • Loading branch information...
commit 3c57d66b57ef772b2bb8accdfcc6e2ef1a882694 1 parent 05930fc
@whtsky whtsky authored
View
12 handlers/__init__.py
@@ -43,8 +43,8 @@ def get_source(self):
for k, v in sources.items():
if k in ua:
return v
- if 'Windows Phone' in ua:
- return 'Windows Phone'
+ if 'Windows Phone' in ua:
+ return 'Windows Phone'
if 'Nokia' in ua:
return _NOKIA_FINDER_.findall(ua)[0]
@@ -53,12 +53,14 @@ def get_source(self):
@property
def db(self):
return self.application.db
-
+
@property
def messages(self):
if not hasattr(self, '_messages'):
messages = self.get_secure_cookie('flash_messages')
- self._messages = messages and tornado.escape.json_decode(messages) or []
+ self._messages = []
+ if messages:
+ self._messages = tornado.escape.json_decode(messages)
return self._messages
def get_member(self, name):
@@ -87,7 +89,7 @@ def get_avatar(self, member, size=48):
avatar += '?s=%s' % size
return '<a href="/member/%s" class="avatar">\
<img src="%s" /></a>' % (member['name'], avatar)
-
+
def get_page_num(self, count, per_page):
return int((count + per_page - 1) / per_page)
View
23 handlers/others.py
@@ -4,13 +4,20 @@
class UserAgentHandler(BaseHandler):
- def get(self):
- ua = self.request.headers.get("User-Agent", "Unknow")
- source = self.get_source()
- if not source:
- source = 'Desktop'
- self.render('others/ua.html', ua=ua, source=source)
-
+ def get(self):
+ ua = self.request.headers.get("User-Agent", "Unknow")
+ source = self.get_source()
+ if not source:
+ source = 'Desktop'
+ self.render('others/ua.html', ua=ua, source=source)
+
+
+class FeedHandler(BaseHandler):
+ def get(self):
+ topics = self.db.topics.find(sort=[('modified', -1)])
+ self.render('feed.xml', topics=topics)
+
handlers = [
- (r'/ua', UserAgentHandler),
+ (r'/ua', UserAgentHandler),
+ (r'/feed', FeedHandler),
]
View
2  main.py
@@ -25,7 +25,7 @@ def __init__(self):
2: 'Admin',
3: 'SuperAdmin'}}
execfile(options.settings, {}, settings)
-
+
settings['host'] = settings['forum_url'].split('/')[2]
if 'static_path' not in settings:
View
1  templates/base.html
@@ -7,6 +7,7 @@
<link rel="stylesheet" href="{{ static_url('css/style.css') }}" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="{{ handler.settings['forum_url'] }}{% block canonical %}{% end %}" />
+ <link rel="alternate" type="application/atom+xml" href="/feed" />
{% block head %}{% end %}
</head>
<body>
View
20 templates/feed.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>{{ handler.settings['forum_title'] }}</title>
+ <link href="{{ handler.settings['forum_url'] }}feed" rel="self" />
+ <link href="{{ handler.settings['forum_url'] }}" />
+ <updated>{{ topics and topics[0]['modified'] }}</updated>
+ <id>{{ handler.settings['forum_url'] }}</id>
+ {% for topic in topics[:15] %}
+ <entry>
+ <title><![CDATA[{{ topic['title'] }}]]></title>
+ <link href="{{ handler.settings['forum_url'] }}topic/{{ topic['_id'] }}"/>
+ <id>{{ handler.settings['forum_url'] }}topic/{{ topic['_id'] }}</id>
+ <content type="html">
+ <![CDATA[
+ {{ topic['content_html'] }}
+ ]]>
+ </content>
+ </entry>
+ {% end %}
+</feed>
Please sign in to comment.
Something went wrong with that request. Please try again.