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. Class Feeds DRY TemplateTag by gmandx 3 years, 1 month ago
  2. TaggedManager and TaggedQuerySet with chainable tagged() methods implemented with django-tagging by fish2000 3 years, 3 months ago
  3. Display arbitrary models by bjornkri 4 years, 11 months ago
  4. View to retrieve objects meeting a complex tag query by nathangeffen 2 years, 6 months ago
  5. Template tag to clear cached template fragment by joao.coelho 3 years, 7 months ago

Comments

adoleo (on September 23, 2008):

This is great! Thank you for sharing it!

#

(Forgotten your password?)