Giter Club home page Giter Club logo

Comments (5)

bradleyayers avatar bradleyayers commented on May 22, 2024

I hadn't thought about this before, but I totally agree. I think Table.page should be rewritten to not handle the exception, that code should be moved to SingleTableMixin. However as the code should be customisable.

I feel like perhaps pagination.page(number) should actually be executed in Table.paginate, so that EmptyPage and PageNotAnInteger are raised those that call, rather than being delayed until Table.page.

One possible pattern would be to just require get_table to be implemented in subclasses:

class Example(tables.Table):
    # ...

    def get_table(self):
        try:
            return super(Example, self).get_table()
        except PageNotAnInteger:
            # ...
        except EmptyPage:
            # ...

I'm not sure how the Meta flag you option would allow arbitrary handling of pagination exceptions (and really the general case here is table configuration errors)

from django-tables2.

andir avatar andir commented on May 22, 2024

Yes, I agree moving pagination.page(n) to Table.paginate would actually work quiet well. The pattern you mentioned would be even better (one place to implement the handling vs. dozens of (nearly) equal code parts).

With the Meta flag I just thought about a way to switch between the current and possible new behavior for compatibility reasons. So the "new" behavior would be opt-in for a while. There might be people checking for the Http404-Exception atm.

from django-tables2.

bradleyayers avatar bradleyayers commented on May 22, 2024

Any thoughts on the Meta variable name? Alternatively it could be passed to Table.paginate(), and set as a default in SimpleTableMixin.

from django-tables2.

andir avatar andir commented on May 22, 2024

Something along the lines of "page_out_of_bounds_action"(=404/page1/...) ? But thats terribly long....
I'm also thinking about a way to do things like an HttpRedirect in that case.. so maybe re-raising should be also possible?

from django-tables2.

bradleyayers avatar bradleyayers commented on May 22, 2024

RequestConfig now handles pagination errors silently. This happens when silent=True is included in its paginate argument, e.g. RequestConfig(..., paginate={"silent": True}) (or when it's not specified). It handles exceptions as follows:

  • EmptyPage -> render last page
  • PageNotAnInteger -> render first page

from django-tables2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.