<commit_before>import datetime

from django import template
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist

from home.models import Social, Copyright, AboutFooter, Logo, \
    Page, BlogPageMediaItem, AboutPageContactItem, MediaItem

register = template.Library()


@register.simple_tag(takes_context=True)
def test_tag(context):
    import pdb; pdb.set_trace()
    return {
        'request': context['request']
    }


# settings value
@register.simple_tag
def settings_value(name):
    return getattr(settings, name, "")


# Site wide get root method
@register.assignment_tag(takes_context=True)
def get_site_root(context):
    # NB this returns a core.Page, not the implementation-specific model used
    # so object-comparison to self will return false as objects would differ
    return context['request'].site.root_page


# Contact Item populate
@register.inclusion_tag('home/tags/contact_item.html', takes_context=True)
def contact_item(context, item):
    self = context.get('self')
    contact_page = item.link_page
    return {
        'contact_page': contact_page,
        'item': item,
        'request': context['request'],
    }


# Blog hero area, to display the blog index image and title
@register.inclusion_tag('home/tags/index_image.html', takes_context=True)
def index_image(context):
    self = context.get('self')
    if self.content_type.model == 'blogindexpage':
        blog_index = self
    elif self.content_type.model == 'aboutpage':
        blog_index = self
    elif self.content_type.model == 'seasonpage':
        blog_index = self
    else:
        blog_index = self.get_parent().specific
    return {
        'blog_index': blog_index,
        'request': context['request'],
    }


def blog_item(context, blog):
    self = context.get('self')
    try:
        media_item = BlogPageMediaItem.objects.get(page=blog)
    except:
        media_item = None
    try:
        media_item = MediaItem.objects.get(page=blog)
    except:
        media_item = None
    supported_sites = None
    if media_item:
        if media_item.link_external:
            url_split = media_item.link_external.split('.')
            supported_sites = []
            if 'youtube' in url_split:
                supported_sites.append('youtube')
            elif 'soundcloud' in url_split:
                supported_sites.append('soundcloud')
            elif 'vimeo' in url_split:
                supported_sites.append('vimeo')
    return {
        'blog': blog,
        'media_item': media_item,
        'supported_sites': supported_sites,
        'request': context['request'],
    }


@register.inclusion_tag('home/tags/blog_index_item.html', takes_context=True)
def blog_index_item(context, blog):
    return blog_item(context, blog)


@register.inclusion_tag('home/tags/blog_hero_item.html', takes_context=True)
def blog_hero_item(context, blog):
    return blog_item(context, blog)


@register.inclusion_tag('home/tags/venue_index_item.html', takes_context=True)
def venue_index_item(context, venue):
    address = venue.venue_details.address.split(',')
    short_address = address[0] + ',' + address[1]
    open_hours = venue.open_hours
    if len(open_hours) > 1:<commit_msg>fixed wierdness in tag function<commit_after>import datetime

from django import template
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist

from home.models import Social, Copyright, AboutFooter, Logo, \
    Page, BlogPageMediaItem, AboutPageContactItem, MediaItem

register = template.Library()


@register.simple_tag(takes_context=True)
def test_tag(context):
    import pdb; pdb.set_trace()
    return {
        'request': context['request']
    }


# settings value
@register.simple_tag
def settings_value(name):
    return getattr(settings, name, "")


# Site wide get root method
@register.assignment_tag(takes_context=True)
def get_site_root(context):
    # NB this returns a core.Page, not the implementation-specific model used
    # so object-comparison to self will return false as objects would differ
    return context['request'].site.root_page


# Contact Item populate
@register.inclusion_tag('home/tags/contact_item.html', takes_context=True)
def contact_item(context, item):
    self = context.get('self')
    contact_page = item.link_page
    return {
        'contact_page': contact_page,
        'item': item,
        'request': context['request'],
    }


# Blog hero area, to display the blog index image and title
@register.inclusion_tag('home/tags/index_image.html', takes_context=True)
def index_image(context):
    self = context.get('self')
    if self.content_type.model == 'blogindexpage':
        blog_index = self
    elif self.content_type.model == 'aboutpage':
        blog_index = self
    elif self.content_type.model == 'seasonpage':
        blog_index = self
    else:
        blog_index = self.get_parent().specific
    return {
        'blog_index': blog_index,
        'request': context['request'],
    }


def blog_item(context, blog):
    self = context.get('self')
    try:
        media_item = BlogPageMediaItem.objects.get(page=blog)
    except:
        try:
            media_item = MediaItem.objects.get(page=blog)
        except:
            media_item = None
    
    supported_sites = None
    if media_item:
        try:
            url_split = media_item.link_external.split('.')
            supported_sites = []
            if 'youtube' in url_split:
                supported_sites.append('youtube')
            elif 'soundcloud' in url_split:
                supported_sites.append('soundcloud')
            elif 'vimeo' in url_split:
                supported_sites.append('vimeo')
        except AttributeError:
            pass
    return {
        'blog': blog,
        'media_item': media_item,
        'supported_sites': supported_sites,
        'request': context['request'],
    }


@register.inclusion_tag('home/tags/blog_index_item.html', takes_context=True)
def blog_index_item(context, blog):
    return blog_item(context, blog)


@register.inclusion_tag('home/tags/blog_hero_item.html', takes_context=True)
def blog_hero_item(context, blog):
    return blog_item(context, blog)


@register.inclusion_tag('home/tags/venue_index_item.html', takes_context=True)
def venue_index_item(context, venue):
    address = venue.venue_details.address.split(',')
    short_address = address[0] + ',' + address[1]
    open_hours = venue.open_hours
    if len(open_hours) > 1:
{'fraction_non_alphanumeric': 0.10629133979387786, 'fraction_numerical': 0.0009229349330872173, 'mean_word_length': 3.3116710875331563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3205527', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1926, 'n_words': 433}