diff --git apps middleware feedburner py apps middleware feedburner py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
diff --git a/apps/middleware/feedburner.py b/apps/middleware/feedburner.py
new file mode 100644
--- /dev/null
+++ b/apps/middleware/feedburner.py
@@ -0,0 +1,31 @@
+from django.http import HttpResponseRedirect
+from django.conf import settings
+from django.core.urlresolvers import resolve
+
+
+class FeedburnerMiddleware(object):
+ '''
+ Redirect the user to a feedburner feed for basic feeds
+ '''
+ def __init__(self):
+ try:
+ self.base, self.feeds = settings.FEEDBURNER
+ except ValueError:
+ self.base, self.feeds = None
+ print self.base, self.feeds
+
+ def process_request(self, request):
+ func, args, kwargs = resolve(request.path)
+ if (not self.base or
+ func.__name__ not in ('redirect_to_feed', 'feed') or
+ kwargs['url'] not in self.feeds):
+ return None
+
+ if request.META['HTTP_USER_AGENT'].startswith('FeedBurner'):
+ return None
+ else:
+ return HttpResponseRedirect('/'.join((
+ 'http://feedproxy.google.com',
+ self.base,
+ kwargs['url'])))
+
diff --git a/settings.py b/settings.py
--- a/settings.py
+++ b/settings.py
@@ -88,6 +88,7 @@
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
+ 'middleware.feedburner.FeedburnerMiddleware',
'lib.threadlocals.ThreadLocalsMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'middleware.url.UrlMiddleware',
@@ -222,6 +223,9 @@
POSTIMAGE_ROOT = MEDIA_ROOT
POSTIMAGE_URL = MEDIA_URL
+# Feedburner
+FEEDBURNER = False
+
STATIC_PAGES = (
# Name, url, title. When bool(name) is False, separator will be inserted
('Blog', '/%s' % BLOG_URLCONF_ROOT, ''),
diff --git a/settings_local.py.template b/settings_local.py.template
--- a/settings_local.py.template
+++ b/settings_local.py.template
@@ -47,6 +47,10 @@
RENDER_METHOD = 'markdown' # Choices: bbcode and simple. Don't use html here, it is unsafe
MAINTENANCE_MODE = False # Set True if you want to put site in maitenance (offline) mode
+# Set to [basename, [names, of, feeds]] to enable FeedBurner support
+# If your feed is "feedproxy.google.com/YourName/blog", "YourName" is basename, "blog" is name of feed
+FEEDBURNER = False
+
# SOCIAL_BOOKMARKS can be reconfigured to contain values from apps/blog/templatetags/bookmarks.py
# BLOG_URLCONF_ROOT can be set if you want to remove 'blog/' prefix
# URL_PREFIX can be set to add url prefix to *all* urls