<commit_before>from django.http import HttpResponse
from django.shortcuts import render
from vikalp.helper_functions.functional import process_tag_or_categories_or_article, get_page
from vikalp.helper_functions.pdf_generator import PDFGenerator
from vikalp.service.article_service import ArticleService
from vikalp.helper_functions.pdf_generator import StyleArticlePDF
from vikalp.helper_functions.pdf_generator import PDF_CONTENT_TYPE


class ArticleDetail:
    def __init__(self):
        self.article_service = ArticleService()
        self.pdf_generator = PDFGenerator()
        self.style_article_pdf = StyleArticlePDF()

    def article_detail(self, request, slug, template="article/article_detail.html"):
        articles = self.article_service.get_published_articles_with_related_articles(request)
        article = process_tag_or_categories_or_article(slug, articles)
        return render(request, template, {"article": article, "page": get_page(request)})


    def build_response(self, article_title):
        response = HttpResponse(content_type=PDF_CONTENT_TYPE)
        response['Content-Disposition'] = self.pdf_generator.generate_pdf_filename(article_title)
        return response


    def build_pdf_content(self, article):
        return self.style_article_pdf.sytle_pdf_content(article)

    def article_download(self, request, slug):
        article = process_tag_or_categories_or_article(slug,
                                                       self.article_service.get_published_articles_with_related_articles(
                                                           request))
        response = self.pdf_generator.generate_pdf_from_html(html=self.build_pdf_content(article),
                                                             file=self.build_response(article_title=article.slug))
        return response
<commit_msg>Changed article detail view to highlight the policy editorial tab for articles if it is a policy edit<commit_after>from django.http import HttpResponse
from django.shortcuts import render
from vikalp.helper_functions.functional import process_tag_or_categories_or_article, get_page
from vikalp.helper_functions.pdf_generator import PDFGenerator
from vikalp.service.article_service import ArticleService
from vikalp.helper_functions.pdf_generator import StyleArticlePDF
from vikalp.helper_functions.pdf_generator import PDF_CONTENT_TYPE


def article_category_is_policy_edits(category):
    if('policy' in category.title.lower()):
        return True


def article_is_a_policy_edit(article):
    return filter(article_category_is_policy_edits, article.article_categories.all())


class ArticleDetail:
    def __init__(self):
        self.article_service = ArticleService()
        self.pdf_generator = PDFGenerator()
        self.style_article_pdf = StyleArticlePDF()

    def article_detail(self, request, slug, template="article/article_detail.html"):
        articles = self.article_service.get_published_articles_with_related_articles(request)
        article = process_tag_or_categories_or_article(slug, articles)
        page = get_page(request)
        if(article_is_a_policy_edit(article)):
            request.path_info = '/policy-edits/'
            page = get_page(request)
        return render(request, template, {"article": article, "page": page})


    def build_response(self, article_title):
        response = HttpResponse(content_type=PDF_CONTENT_TYPE)
        response['Content-Disposition'] = self.pdf_generator.generate_pdf_filename(article_title)
        return response


    def build_pdf_content(self, article):
        return self.style_article_pdf.sytle_pdf_content(article)

    def article_download(self, request, slug):
        article = process_tag_or_categories_or_article(slug,
                                                       self.article_service.get_published_articles_with_related_articles(
                                                           request))
        response = self.pdf_generator.generate_pdf_from_html(html=self.build_pdf_content(article),
                                                             file=self.build_response(article_title=article.slug))
        return response

{'fraction_non_alphanumeric': 0.06717484516436398, 'fraction_numerical': 0.0, 'mean_word_length': 3.3378099173553717, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3381035', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1068, 'n_words': 202}