Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def section(request, section):
section = Section.objects.get(name=section)
article_list = Article.objects.filter(section=section,is_active=True,head=True).order_by('-created_at')
q = request.GET.get('q', '')
if q:
article_list = article_list.filter(headline__icontains=q)
unpublished = article_list.exclude(status=Article.PUBLISHED).count()
paginator = Paginator(article_list, 15) # Show 15 articles per page
page = request.GET.get('page')
try:
articles = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
articles = paginator.page(1)
if order == 'newest':
order_by = '-published_at'
else:
order_by = 'published_at'
context = {
'order': order,
'q': query
}
if query is not None:
title = 'Search results for "%s"' % query
article_list = Article.objects.filter(is_published=True, headline__icontains=query).order_by(order_by)
paginator = Paginator(article_list, 15) # Show 15 articles per page
page = request.GET.get('page')
try:
articles = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
articles = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
articles = paginator.page(paginator.num_pages)
context['articles'] = articles
context['count'] = paginator.count
def author(self, request, slug=None):
try:
person = Person.objects.get(slug=slug)
except:
raise Http404("Author could not be found.")
articles = Article.objects.filter(authors=person, is_published=True)[:6]
context = {
'meta': self.get_author_meta(person),
'person': person,
'articles': articles
}
return render(request, 'author/base.html', context)
def section(self, request, section):
section = Section.objects.get(slug=section)
articles = Article.objects.filter(head=True,section=section)
context = {
'section': section,
'articles': articles,
}
return render(request, 'section/base.html', context)
def section(self, request, slug=None):
try:
section = Section.objects.get(slug=slug)
except:
return self.page(request, slug)
articles = Article.objects.filter(section=section, is_published=True).order_by('-published_at')
context = {
'meta': {
'title': section.name
},
'section': section,
'type': 'section',
'articles': {
'first': articles[0],
'rest': articles[1:9]
}
}
t = loader.select_template(["%s/%s" % (section.slug, 'section.html'), 'section.html'])
return HttpResponse(t.render(context))