Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def article_list(request):
page = page_for_app_request(request)
page.activate_language(request)
return render_list(
request,
Article.objects.filter(category=page.application),
{"page": page},
paginate_by=5,
)
def test_render_list(self):
for i in range(7):
Article.objects.create(title="Article %s" % i, category="publications")
request = RequestFactory().get("/", data={"page": 2})
response = render_list(
request, list(Article.objects.all()), model=Article, paginate_by=2
)
self.assertEqual(response.template_name, "testapp/article_list.html")
self.assertEqual(len(response.context_data["object_list"]), 2)
self.assertEqual(response.context_data["object_list"].number, 2)
self.assertEqual(response.context_data["object_list"].paginator.num_pages, 4)
def article_list_all(request):
page = page_for_app_request(request)
page.activate_language(request)
return render_list(
request, Article.objects.filter(category=page.application), {"page": page}
)
def article_list(request):
page = page_for_app_request(request)
page.activate_language(request)
return render_list(
request,
# Only show articles for the current app.
Article.objects.published().filter(
category=page.application,
).prefetch_related('images'),
{'page': page},
paginate_by=10,
)