Commits

Anonymous committed aa4a9fa

add feed

  • Participants
  • Parent commits 38a8080

Comments (0)

Files changed (9)

     path = os.path.join(os.path.dirname(__file__),'themes')
     themes = os.listdir(path)
     themes.remove('admin')
+    for theme in themes:
+        if not os.path.isdir(os.path.join(path,theme)):
+            themes.remove(theme)
     return themes
 
 class MainHandler(AdminHandler):
 import re
 import urllib
 import fnmatch
+import datetime
 from google.appengine.api import users
 from google.appengine.ext import webapp
 from google.appengine.ext.webapp import util
 from django.utils import simplejson
-from util.handler import PublicHandler,get_or_404
+from util.handler import PublicHandler,get_or_404,FeedHandler
 from util.getimageinfo import getImageInfo
 from util.paging import PagedQuery
 from util.thumb import resize
         if user and users.is_current_user_admin() :
             return self.redirect("/a/upload/")
         return self.redirect(users.create_login_url("/a/upload/"))
+    
+class FeedIndexHandler(FeedHandler):
+    def get(self):
+        imgs = Image.all().order('-created').fetch(10)
+        self.template_value['imgs']=imgs
+        self.template_value['lastupdated'] = imgs[0].created if len(imgs) >0 else datetime.datetime.now()
+        self.response.headers['Content-Type'] = "application/atom+xml"
+        self.response.out.write(self.get_render("rss.xml"))
+    
+class FeedAlbumHandler(FeedHandler):
+    def get(self,key_name):
+        album = get_or_404(Album.get_by_key_name,key_name)
+        imgs = Image.all().filter('album =',album).order('-created').fetch(10)
+        self.template_value['imgs']=imgs
+        self.template_value['lastupdated'] = imgs[0].created if len(imgs) >0 else datetime.datetime.now()
+        self.response.headers['Content-Type'] = "application/atom+xml"
+        self.response.out.write(self.get_render("rss.xml"))
        
 def main():
     application = webapp.WSGIApplication ([
                                        ('/u/',ImageUploadHandler),
                                        ('/logout/',LogoutHandler),
                                        ('/login/',LoginHandler),
+                                       
+                                       #Feed
+                                       (r'/feed/?',FeedIndexHandler),
+                                       (r'/feed/(?P<key_name>[a-z0-9]+)/?',FeedAlbumHandler),
                                         ],
                                          debug=settings.DEBUG)
     util.run_wsgi_app(application)

File themes/default/album.html

 {% extends "base.html" %}
 {%block title %}{{settings.name}}&gt;{{album.name}}-sa3album {% endblock %}
+{% block meta %}
+<link rel="alternate" type="application/atom+xml" title="sa3album" href="/feed/{{album.key.name}}/" />
+{% endblock %}
 {% block content %}
 <h2><a href="/">{{settings.name}}</a>&gt;<a href="{{album.url}}">{{album.name}}</a><span class="info f12">({{album.count}})</span></h2>
 <ul id="album-list">

File themes/default/base.html

         <title>{% block title %}{% endblock %}</title>
         <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
         <link rel='stylesheet' href='/static/style.css' />
+		{% block meta %} {% endblock %}
     </head>
     <body>
         <div id="main">

File themes/default/index.html

 {% extends "base.html" %}
 {%block title %}{{settings.name}}-sa3album {% endblock %}
+{% block meta %}
+<link rel="alternate" type="application/atom+xml" title="sa3album" href="/feed/" />
+{% endblock %}
 {% block content %}
 <ul id="album-list">
 <h2><a href="/">{{settings.name}}</a>&gt;相册列表</h2>

File themes/gallery/album.html

 {% extends "base.html" %}
 {%block title %}{{settings.name}}&gt;{{album.name}}-sa3album {% endblock %}
+{% block meta %}
+<link rel="alternate" type="application/atom+xml" title="sa3album" href="/feed/{{album.key.name}}/" />
+{% endblock %}
 {% block content %}
 <div id="d">
 <h1><a href="/">{{settings.name}}</a>&gt;<a href="{{album.url}}">{{album.name}}</a><span class="info f12">({{album.count}})</span></h1>

File themes/gallery/base.html

     <head>
         <meta charset="utf-8">
         <title>{% block title %}{% endblock %}</title>
+		{% block meta %}{% endblock %}
         <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
         <link rel='stylesheet' href='/static/gallery/style.css' />
 		<link rel='stylesheet' href='/static/gallery/galleriffic.css' />

File themes/gallery/index.html

 {% extends "base.html" %}
 {%block title %}{{settings.name}}-sa3album {% endblock %}
+{% block meta %}
+<link rel="alternate" type="application/atom+xml" title="sa3album" href="/feed/" />
+{% endblock %}
 {% block content %}
 <div id="d">
 <h1><a href="/">{{settings.name}}</a>&gt;相册列表</h1>

File util/handler.py

             else:
                 self.error(500)
                 logging.exception(exception)
+                
+class FeedHandler(PublicHandler):
+    def get_render(self,template_file):
+        template_file = "themes/%s" % (template_file)
+        path = os.path.join(os.path.dirname(__file__), r'../',template_file)
+        return template.render(path, self.template_value)        
+    
 
 class ApiHandler(webapp.RequestHandler):
     def initialize(self,request,response):