Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic view mixins for Django 1.3 #10

Closed
bradleyayers opened this issue May 27, 2011 · 1 comment
Closed

Add generic view mixins for Django 1.3 #10

bradleyayers opened this issue May 27, 2011 · 1 comment

Comments

@bradleyayers
Copy link
Collaborator

I'm thinking a SingleTableMixin and MultipleTableMixin would be good. The following is a quick attempt at a SingleTableMixin, feedback would be appreciated. I think implementing the ability to change querystring variable names first (issue #5) would be a good idea, and necessary for MultipleTableMixin anyway.

class SingleTableMixin(object):
    """
    Adds a suitable table to the context. Requires a ``table`` attribute on the
    view.
    """
    table = None
    context_table_name = "table"

    def get_context_data(self, **kwargs):
        table = self.table(self.get_queryset(), order_by=self.request.GET.get('sort'))
        table.paginate(page=self.request.GET.get('page', 1))
        context = super(TableMixin, self).get_context_data(**kwargs)
        context[self.context_table_name] = table
        return context
bradleyayers added a commit that referenced this issue Jun 2, 2011
@bradleyayers
Copy link
Collaborator Author

I'm going to consider this done until a decent pattern is developed for MultipleFooMixin classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant