Coverage for articles/templatetags/article_tags.py: 100.00%

18 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-13 16:37 -0700

1import markdown 1a

2from django import template 1a

3from django.db.models import Count 1a

4from django.utils.safestring import mark_safe 1a

5 

6from ..models import Article 1a

7 

8register = template.Library() 1a

9 

10 

11@register.simple_tag 1a

12def get_most_commented_articles(count=5): 1a

13 return Article.published.annotate(total_comments=Count("comments")).order_by( 1daefgbchi

14 "-total_comments" 

15 )[:count] 

16 

17 

18@register.simple_tag 1a

19def total_articles(): 1a

20 return Article.published.count() 1daefgbchi

21 

22 

23@register.inclusion_tag("articles/latest_articles.html") 1a

24def show_latest_articles(count=5): 1a

25 latest_articles = Article.published.order_by("-publish")[:count] 1daefgbchi

26 return {"latest_articles": latest_articles} 1daefgbchi

27 

28 

29@register.filter(name="markdown") 1a

30def markdown_format(text): 1a

31 return mark_safe(markdown.markdown(text)) # noqa: S308 # pragma: no cover 1bc