<commit_before>from django import template
from django.utils.safestring import SafeText
from django.db.models import Q

from isisdata.models import *

register = template.Library()


PUBLICATION_DATE = AttributeType.objects.get(name='PublicationDate').id


@register.filter(name='render_object')
def render_object(obj):
    model_name = obj.__class__.__name__
    # model_class = globals().get(model_name)
    elem = u'<div class="row">'
    if model_name == 'Citation':
        elem += '<span class="label label-primary">' + obj.get_type_controlled_display() + '</span> '
        elem += obj.title
        elem += '<span class="text-warning">'
        elem += ' by ' + ', '.join([getattr(relation.authority, 'name', 'missing') + ' ('+  relation.get_type_controlled_display() + ')' for relation in obj.acrelations
                    if relation.type_controlled in [ACRelation.AUTHOR, ACRelation.EDITOR]])


        elem += '</span>'

        elem += '<dl class="dl-horizontal">'
        elem += '<dt>Publication date</dt>'
        elem += '<dd>' + getattr(obj.publication_date, 'isoformat', lambda: 'missing')() + '</dd>'

        for relation in obj.acrelations:
            if relation.type_controlled in [ACRelation.PUBLISHER, ACRelation.PERIODICAL, ACRelation.BOOK_SERIES]:
                elem += '<dt>' + relation.get_type_controlled_display() + '</dt>'
                elem += '<dd>' + getattr(relation.authority, 'name', 'missing') + '</dd>'

        elem += '</dl>'

    else:
        elem += obj.__unicode__()
    elem += u'</div>'

    return SafeText(elem)


@register.filter(name='get_citation_title')
def get_citation_title(obj):
    title = obj.title
    if not title:
        for relation in obj.ccrelations:
            if relation.type_controlled in [CCRelation.REVIEW_OF, CCRelation.REVIEWED_BY]:
                return u'Review: %s' % relation.subject.title if relation.subject.id != obj.id else relation.object.title
        return u'Untitled review'
    return title


@register.filter(name='get_publisher')
def get_publisher(obj):
    acrel = obj.acrelations.filter(type_controlled=ACRelation.PUBLISHER).first()
    if acrel:
        return acrel.authority
    return None

@register.filter(name='get_isbn')
def get_isbn(obj):<commit_msg>ISISCB-591 for acrelation without citation, bail early on extracting citation title<commit_after>from django import template
from django.utils.safestring import SafeText
from django.db.models import Q

from isisdata.models import *

register = template.Library()


PUBLICATION_DATE = AttributeType.objects.get(name='PublicationDate').id


@register.filter(name='render_object')
def render_object(obj):
    model_name = obj.__class__.__name__
    # model_class = globals().get(model_name)
    elem = u'<div class="row">'
    if model_name == 'Citation':
        elem += '<span class="label label-primary">' + obj.get_type_controlled_display() + '</span> '
        elem += obj.title
        elem += '<span class="text-warning">'
        elem += ' by ' + ', '.join([getattr(relation.authority, 'name', 'missing') + ' ('+  relation.get_type_controlled_display() + ')' for relation in obj.acrelations
                    if relation.type_controlled in [ACRelation.AUTHOR, ACRelation.EDITOR]])


        elem += '</span>'

        elem += '<dl class="dl-horizontal">'
        elem += '<dt>Publication date</dt>'
        elem += '<dd>' + getattr(obj.publication_date, 'isoformat', lambda: 'missing')() + '</dd>'

        for relation in obj.acrelations:
            if relation.type_controlled in [ACRelation.PUBLISHER, ACRelation.PERIODICAL, ACRelation.BOOK_SERIES]:
                elem += '<dt>' + relation.get_type_controlled_display() + '</dt>'
                elem += '<dd>' + getattr(relation.authority, 'name', 'missing') + '</dd>'

        elem += '</dl>'

    else:
        elem += obj.__unicode__()
    elem += u'</div>'

    return SafeText(elem)


@register.filter(name='get_citation_title')
def get_citation_title(obj):
    if not obj:
        return u'No linked citation'
    title = obj.title
    if not title:
        for relation in obj.ccrelations:
            if relation.type_controlled in [CCRelation.REVIEW_OF, CCRelation.REVIEWED_BY]:
                return u'Review: %s' % relation.subject.title if relation.subject.id != obj.id else relation.object.title
        return u'Untitled review'
    return title


@register.filter(name='get_publisher')
def get_publisher(obj):
    acrel = obj.acrelations.filter(type_controlled=ACRelation.PUBLISHER).first()
    if acrel:
        return acrel.authority
    return None

@register.filter(name='get_isbn')
def get_isbn(obj):
{'fraction_non_alphanumeric': 0.13922961050139876, 'fraction_numerical': 0.0006455777921239509, 'mean_word_length': 3.291782086795937, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '2226224', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1411, 'n_words': 310}