def get_context_data(self, filtered_ids): all_categories = CategoryService.get_categories_with_count() filtered_categories = CategoryService.get_categories_with_count(filtered_ids) for category in all_categories: if category.slug == self.value: category.selected = True try: category.count = filtered_categories.get(id=category.id).count except Category.DoesNotExist: category.count = 0 category.disabled = True context = {"categories": all_categories} return context
def get_category_tag_cloud(): from techblog.services.articles import ArticleService from techblog.services.categories import CategoryService cats = CategoryService.get_categories_with_count() for category in cats: article_ids = ArticleService.get_article_ids_by_category(category) category.tags = list(TagService.get_filtered_tag_cloud([a.id for a in article_ids])) if not category.tags: category.empty = True return cats