Changeset - e75642ed4721
[Not reviewed]
0 1 0
Bradley Kuhn (bkuhn) - 8 years ago 2014-07-14 16:35:08
bkuhn@ebb.org
use get_object() in BlogFeed to get request object

Upon reading
https://docs.djangoproject.com/en/dev/ref/contrib/syndication/#a-complex-example

I think that this is what I need to do to forward-port this Django 1.2
to Django 1.4's Feed objects.
1 file changed with 11 insertions and 7 deletions:
0 comments (0 inline, 0 general)
www/conservancy/feeds.py
Show inline comments
...
 
@@ -144,28 +144,31 @@ class OmnibusFeed(ConservancyFeedBase):
 
        a  = [ ii for ii in itertools.chain(blogs, news)]
 
        a.sort(key=operator.attrgetter('pub_date'), reverse=True)
 
        return a
 

	
 

	
 
    def item_extra_kwargs(self, item):
 
        return super(OmnibusFeed, self).item_extra_kwargs(item)
 

	
 
class BlogFeed(ConservancyFeedBase):
 
    link = "/blog/"
 
    get_absolute_url = '/feeds/blog/'
 

	
 
    def title(self):
 
    def get_object(self, request):
 
        return request
 

	
 
    def title(self, obj):
 
        answer = "The Software Freedom Conservancy Blog"
 

	
 
        GET = self.request.GET
 
        GET = obj.GET
 
        tags = []
 
        if 'author' in GET:
 
            tags = GET.getlist('author')
 
        if 'tag' in GET:
 
            tags += GET.getlist('tag')
 

	
 
        if len(tags) == 1:
 
            answer += " (" + tags[0] + ")"
 
        elif len(tags) > 1:
 
            firstTime = True
 
            done = {}
 
            for tag in tags:
...
 
@@ -173,28 +176,28 @@ class BlogFeed(ConservancyFeedBase):
 
                if firstTime:
 
                    answer += " ("
 
                    firstTime = False
 
                else:
 
                    answer += ", "
 
                answer += tag
 
                done[tag] = tag
 
            answer += ")"
 
        else:
 
            answer += "."
 
        return answer
 
        
 
    def description(self):
 
    def description(self, obj):
 
        answer = "Blogs at the Software Freedom Conservancy"
 

	
 
        GET = self.request.GET
 
        GET = obj.GET
 
        tags = []
 
        if 'author' in GET: tags = GET.getlist('author')
 
        if 'tag' in GET:    tags += GET.getlist('tag')
 

	
 
        done = {}
 
        if len(tags) == 1:
 
            answer += " tagged with " + tags[0]
 
        elif len(tags) > 1:
 
            firstTime = True
 
            for tag in tags:
 
                if done.has_key(tag): continue
 
                if firstTime:
...
 
@@ -211,42 +214,43 @@ class BlogFeed(ConservancyFeedBase):
 
        return answer
 
        
 
    def item_title(self, item):
 
        return item.headline
 

	
 
    def item_description(self, item):
 
        return item.summary
 

	
 
    def item_author_name(self, item):
 
        return item.author.formal_name
 

	
 
    def item_author_email(self, item):
 
        GET = self.request.GET
 
        GET = self.get_object().GET
 
        if not 'author' in GET:
 
            return "%s@sfconservancy.org" % item.author
 
        else:
 
            answer = ""
 
            authors = GET.getlist('author')
 
            firstTime = True
 
            for author in authors:
 
                if not firstTime:
 
                    answer = "%s@sfconservancy.org" % author
 
                    firstTime = False
 
                else:
 
                    answer += ",%s@sfconservancy.org" % author
 

	
 
    def item_pubdate(self, item):
 
        return item.pub_date
 
    def items(self):
 
        GET = self.request.GET
 

	
 
    def items(self, obj):
 
        GET = obj.GET
 

	
 
        def OR_filter(field_name, subfield_name, objs):
 
            from django.db.models import Q
 
            return reduce(lambda x, y: x | y,
 
                          [Q(**{'%s__%s' % (field_name, subfield_name): x})
 
                           for x in objs])
 

	
 
        queryset = BlogEntry.objects.filter(pub_date__lte=datetime.now())
 

	
 
        if 'author' in GET:
 
            authors = GET.getlist('author')
 
            queryset = queryset.filter(OR_filter('author', 'username', authors))
0 comments (0 inline, 0 general)