<commit_before>from django import template
from django.db.models import ObjectDoesNotExist

register = template.Library()


@register.assignment_tag(takes_context=True)
def get_contact_email(context):
    theme = get_theme(context)

    email = theme.content.contact_email
    if not email:
        try:
            defaults = context['request'].site.default_settings
            return defaults.contact_email
        except ObjectDoesNotExist:
            return ""

    return email


def get_theme(context):
    default_theme = context["default_theme"]
    try:
        page = context["self"]
        return page.theme
    except:
        return default_theme


@register.assignment_tag(takes_context=True)
def get_text_block(context, usage):
    theme = get_theme(context)
    return theme.content.block_links.filter(theme_content=theme.content, block__usage=usage).first().block


@register.assignment_tag(takes_context=True)
def get_follow_link(context, usage):
    theme = get_theme(context)
    return theme.content.follow_links.filter(theme_content=theme.content, block__usage=usage).first().block.link


@register.assignment_tag(takes_context=True)
def get_logo(context, usage):
    theme = get_theme(context)
    return theme.content.logo_links.filter(theme_content=theme.content, block__usage=usage).first().block.link
<commit_msg>OCW-758 #comment Fixed copy-n-paste error that resulted in an AttributeError when rendering the header.html<commit_after>from django import template
from django.db.models import ObjectDoesNotExist

register = template.Library()


@register.assignment_tag(takes_context=True)
def get_contact_email(context):
    theme = get_theme(context)

    email = theme.content.contact_email
    if not email:
        try:
            defaults = context['request'].site.default_settings
            return defaults.contact_email
        except ObjectDoesNotExist:
            return ""

    return email


def get_theme(context):
    default_theme = context["default_theme"]
    try:
        page = context["self"]
        return page.theme
    except:
        return default_theme


@register.assignment_tag(takes_context=True)
def get_text_block(context, usage):
    theme = get_theme(context)
    return theme.content.block_links.filter(theme_content=theme.content, block__usage=usage).first().block


@register.assignment_tag(takes_context=True)
def get_follow_link(context, usage):
    theme = get_theme(context)
    return theme.content.follow_links.filter(theme_content=theme.content, block__usage=usage).first().block.link


@register.assignment_tag(takes_context=True)
def get_logo(context, usage):
    theme = get_theme(context)
    return theme.content.logo_links.filter(theme_content=theme.content, block__usage=usage).first().block.logo

{'fraction_non_alphanumeric': 0.09460431654676259, 'fraction_numerical': 0.001079136690647482, 'mean_word_length': 4.307251908396947, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3810785', 'n_tokens_mistral': 819, 'n_tokens_neox': 800, 'n_words': 151}