Commits

A S committed b092e9e

Added cache-control header decorator, code cleanup

Comments (0)

Files changed (3)

pypysite/__init__.py

 # Main pages
 
 @app.route('/')
+@utils.cache
 def index():
-    return render_template('index.html', tweets=twitter.pypy_tweets, binaries=data.downloads['binaries'])
+    return render_template('index.html',
+        tweets=twitter.pypy_tweets,
+        binaries=data.downloads['binaries'])
 
 
 @app.route('/compatibility/')
+@utils.cache
 def compatibility():
-    return render_template('compatibility.html', tweets=twitter.pypy_tweets, compatibility=data.compatibility)
+    return render_template('compatibility.html',
+        tweets=twitter.pypy_tweets,
+        compatibility=data.compatibility)
 
 
 @app.route('/download/')
+@utils.cache
 def download():
-    return render_template('download.html', tweets=twitter.pypy_tweets, binaries=data.downloads['binaries'], sources=data.downloads['source'])
+    return render_template('download.html',
+        tweets=twitter.pypy_tweets,
+        binaries=data.downloads['binaries'],
+        sources=data.downloads['source'])
 
 
 @app.route('/about/')
+@utils.cache
 def about():
-    return render_template('about.html', tweets=twitter.pypy_tweets)
+    return render_template('about.html',
+        tweets=twitter.pypy_tweets)
 
 
 # Admin pages
 #JSON
 
 @app.route('/downloads.json')
+@utils.cache
 def downloads_json():
     with open(config.DATA_DIR + '/downloads.json') as f:
         dl = f.read()
 
 
 @app.route('/supported.json')
+@utils.cache
 def supported_json():
     with open(config.DATA_DIR + '/compatibility.json') as f:
         comp = f.read()

pypysite/data/twitter_pypyproject.json

             "default_profile_image": false, 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
-            "follow_request_sent": false, 
-            "followers_count": 874, 
-            "following": true, 
+            "follow_request_sent": null, 
+            "followers_count": 881, 
+            "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "id": 277141637, 
             "listed_count": 43, 
             "location": "", 
             "name": "The PyPy Project", 
-            "notifications": false, 
+            "notifications": null, 
             "profile_background_color": "C0DEED", 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
             "follow_request_sent": null, 
-            "followers_count": 874, 
+            "followers_count": 881, 
             "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
             "follow_request_sent": null, 
-            "followers_count": 874, 
+            "followers_count": 881, 
             "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
             "follow_request_sent": null, 
-            "followers_count": 874, 
+            "followers_count": 881, 
             "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
             "follow_request_sent": null, 
-            "followers_count": 874, 
+            "followers_count": 881, 
             "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
             "follow_request_sent": null, 
-            "followers_count": 874, 
+            "followers_count": 881, 
             "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
             "follow_request_sent": null, 
-            "followers_count": 874, 
+            "followers_count": 881, 
             "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
             "follow_request_sent": null, 
-            "followers_count": 874, 
+            "followers_count": 881, 
             "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
             "follow_request_sent": null, 
-            "followers_count": 874, 
+            "followers_count": 881, 
             "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 
             "description": "The developers of the PyPy project: a fast, compliant Python interpreter.", 
             "favourites_count": 0, 
             "follow_request_sent": null, 
-            "followers_count": 874, 
+            "followers_count": 881, 
             "following": null, 
             "friends_count": 7, 
             "geo_enabled": false, 
             "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", 
             "profile_background_tile": false, 
-            "profile_image_url": "http://a3.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
+            "profile_image_url": "http://a0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_image_url_https": "https://si0.twimg.com/profile_images/1331828944/pypy_small64_normal.png", 
             "profile_link_color": "0084B4", 
             "profile_sidebar_border_color": "C0DEED", 

pypysite/utils.py

+"""
+    Cache decorator
+"""
+from flask import make_response
+from functools import update_wrapper
 
-# Open resource
-# ~~~~~~~~~~~~~
+
+def cache(f):
+    def new_func(*args, **kwargs):
+        resp = make_response(f(*args, **kwargs))
+        resp.headers['Cache-Control'] = 'max-age=28800'
+        return resp
+    return update_wrapper(new_func, f)
+
+
+"""
+    Open resource
+    ~~~~~~~~~~~~~
+"""
 
 import config
 from flask import Flask, Markup
     ftypes = ('rst', 'html')
 
     if (section):
-        floc = config.APP_PATH + '/content/%s/%s-%s.' % (page.lower(), name.lower(), section.lower())
+        floc = '/content/%s/%s-%s.' % (page.lower(), name.lower(), section.lower())
     else:
-        floc = config.APP_PATH + '/content/%s/%s.' % (page.lower(), name.lower())
+        floc = '/content/%s/%s.' % (page.lower(), name.lower())
 
     for index, ftype in enumerate(ftypes):
         try:
-            with app.open_resource(floc + ftype) as f:
+            with app.open_resource(config.APP_PATH + floc + ftype) as f:
                 if ftype == 'html':
                     return Markup(f.read())
                 else:
                 continue
 
 
-# The Pygments reStructuredText directive
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# http://pygments.org
-# http://docutils.sourceforge.net/docs/howto/rst-directives.html
+"""
+    The Pygments reStructuredText directive
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    http://pygments.org
+    http://docutils.sourceforge.net/docs/howto/rst-directives.html
+"""
 
 # Set to True if you want inline CSS styles instead of classes
 INLINESTYLES = False
 directives.register_directive('sourcecode', Pygments)
 
 
-# ReST
-# ~~~~
+"""
+    ReST
+    ~~~~
+"""
 
 from docutils import core
 
     return parts['body_pre_docinfo'] + parts['fragment']
 
 
-# Time
-# ~~~~
+"""
+    Time
+    ~~~~
+"""
 
 from datetime import datetime, timedelta