pydanny / dj-paginator

Django + Pagination made easy.
BSD 3-Clause "New" or "Revised" License
36 stars 4 forks source link

Add super ninja style mixin to make this even easier to use. #1

Open pydanny opened 9 years ago

pydanny commented 9 years ago

Template tags suck. Settings are globals. What about being able to configure per view?

Imagine this:

class PaginatorMixin(object):
    theme = PAGINATOR_THEME  # from settings but overridable
    caching = PAGINATOR_CACHE # boolean for caching of results for moar speed
    paginate_by = 10 # Because we know for certain we'll be paginating

    def paginator(self):
        # Because we're getting the template here, we can probably cache the load somehow.
        template = get_template(self.theme)
        # Add all the normal paginator stuff
        context = template.add_stuff_like_page_obj()
        return template.render(context)

Usage will be easy:

class MyModelListView(PaginatorMixin, ListView):
    model = MyModel
<!--  Loop through the content -->
{% for mymodel in mymodel_list %}
{{ mymodel.title }}
{% endfor %}

<!-- Call the view method -->
{{ view.paginator }}

And that's it! No loading of template tags. That means code isn't stuck in the dark corner of template tags. It exists in a relative simple model, or better yet easy tested utility functions.

pydanny commented 9 years ago

I have a rough of this but it's in a really unclean state. I'll try to get it in this week.