feedburner middleware

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from django.http import HttpResponseRedirect
import settings


class FeedburnerMiddleware(object):
    '''
    Redirect the user to a feedburner feed for basic feeds
    '''
    def process_request(self, request):
        r = request.path.split('/')
        if not settings.FEEDBURNER or\
            not r[1] == 'feeds' or \
            not r[-2] in settings.FEEDBURNER[1]:
            return None
        
        if request.META['HTTP_USER_AGENT'].startswith('FeedBurner'):
            return None
        else:
            return HttpResponseRedirect('/'.join((
                'http://feedproxy.google.com', 
                settings.FEEDBURNER[0],
                '/'.join(r[3:-1]))
                ))

More like this

  1. Display arbitrary models by bjornkri 5 years, 9 months ago
  2. LinkShare Pixel Tracking template tag for Satchmo by maxk 3 years, 3 months ago
  3. RSS feed with content:encoded elements by philgyford 3 years, 7 months ago
  4. Row-Level, URL-based permissions for FlatPages by bradmontgomery 4 years, 10 months ago
  5. Unobtrusive comment moderation by ubernostrum 7 years, 1 month ago

Comments

adoleo (on September 23, 2008):

This is great! Thank you for sharing it!

#

(Forgotten your password?)