Lately I wanted to collect my django feeds into a single web-viewable channel.

There’s more than a single solution to do this. Being django fellow, I’ve decided to utilize FeedJack.

So… Well, I guess, it might work flawlessly for other people, but in my cause it failed miserably after adding two feeds:

  • official django blog and
  • djangosnippets

Just after adding djangosnippets, it messed up the order of posts terribly.

What’s going on? The code shows.

FeedJack says:

urlpatterns = patterns('',
    (r'^$', views.mainview),

That, after couple hops, translates to the fjlib.get_paginator:

def get_paginator(site, sfeeds_ids, page=0, tag=None, user=None):
    """ Returns a paginator object and a requested page from it.

    if tag:
            localposts = models.Tag.objects.get(name=tag).post_set.filter(\
            raise Http404
        localposts = models.Post.objects.filter(feed__in=sfeeds_ids)

    if user:
            localposts = localposts.filter(feed=user)
            raise Http404
    if site.order_posts_by == 2:
        localposts = localposts.order_by('-date_created', '-date_modified')
        localposts = localposts.order_by('-date_modified')

    paginator = ObjectPaginator(localposts.select_related(), 
        object_list = paginator.get_page(page)
    except InvalidPage:
        if page == 0:
            object_list = []
            raise Http404
    return (paginator, object_list)

Quick introspection reveals that localpost order isn’t broken just until the FeedJack creates the paginator with:

    paginator = ObjectPaginator(localposts.select_related(), 

After that, the post order is messed up and the cause is optimizing call to select_related.

I’m not yet sure if it’s a feature or a bug, but certainly, the premature optimization is the root of all evils.

  • Django - unicode branch
  • python 2.4
  • FeedJack 0.9.9

Good luck!

PS. Finally it was solved by leaving select_related in and adding sorting by id to preserve the original order.