Hi Devs,

I just bumped into this and can see both sides so I'm posting here...

I'm working on a project that wants a list view to have configurable
num_per_page for pagination.  I set it up to pull from the GET (eg: /
search/category-slug/?per_page=10).  What I did was check for the
existence of per_page in request.GET and pass it to the paginator in
my generic list view.

What I got was:

    TypeError at /search/category-slug/
    unsupported operand type(s) for //: 'int' and 'unicode'

because GET['per_page'] is a unicode string and not an int.

I could easily convert to int in my view, checking for ValueError at
the same time but I'd have to do that in all my views if I had more
than one which doesn't seem right.

It makes some sense to push this conversion down into paginator.py,
but what if there is an error on conversion.  It would probably not be
good to have a default in paginator, would it?

    try:
        self.num_per_page = int(num_per_page)
    except ValueError:
        self.num_per_page = PER_PAGE_DEFAULT

Or simply let ValueError bubble up?  Or is it best to leave it be?

If we want paginator to auto-convert I can file a bug and submit a
patch (which is already sitting in one of my git branches) but the
other is a design decision I'm curious about.

Thanks,
Rob

PS: Sorry if this comes through twice -- I got an error, waited a few
minutes, then posted again.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to