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.
Template tags suck. Settings are globals. What about being able to configure per view?
Imagine this:
Usage will be easy:
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.