/gist:1415cf6300f07b9bc568 Secret
Created
October 7, 2011 17:01
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MarcusListView(ListView): | |
paginate_by = settings.MARCUS_PAGINATE_BY | |
class TranslationMixin(object): | |
language = 'ru' | |
language_kwarg = 'language' | |
def get_queryset(self): | |
self.language = self.kwargs.get(self.language_kwarg, self.language) | |
qs = super(TranslationMixin, self).get_queryset() | |
return qs.language(self.language) | |
def get_context_data(self, **kwargs): | |
context = super(TranslationMixin, self).get_context_data(**kwargs) | |
context.update({'language': self.language}) | |
return context | |
class CategoryMixin(object): | |
category = None | |
category_kwarg = 'slug' | |
def dispatch(self, *args, **kwargs): | |
slug = kwargs.get(self.category_kwarg) | |
self.category = get_object_or_404(models.Category, slug=slug) | |
return super(CategoryMixin, self).dispatch(*args, **kwargs) | |
def get_context_data(self, **kwargs): | |
context = super(CategoryMixin, self).get_context_data(**kwargs) | |
context.update({'category': self.category}) | |
return context | |
class CategoryFilterMixin(CategoryMixin): | |
def get_queryset(self): | |
qs = super(CategoryFilterMixin, self).get_queryset() | |
return qs.filter(categories=self.category) | |
class CategoryArticleListView(CategoryFilterMixin, TranslationMixin, MarcusListView): | |
queryset = models.Article.public | |
template_name = 'marcus/category.html' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment