<commit_before>from datetime import datetime
from django.conf import settings
from ddisearch.ddi.models import CodeBook


def ddi_lastmodified(request, agency, id):
    """Get the last modification time for a DDI document in eXist by agency and id.
    Used to generate last-modified header for views based on a single EAD document.

    :param id: eadid
    :param preview: load document from preview collection; defaults to False
    :rtype: :class:`datetime.datetime`
    """
    # get document last modified by
    res = CodeBook.objects.filter(id__val=id, id__agency=agency).only('last_modified').get()
    return exist_datetime_with_timezone(res.last_modified)

def ddi_etag(request, agency, id):
    """Generate a DDI Codebook document (specified by agency and id) by
    requesting a SHA-1 checksum of the entire DDI xml document from eXist.

    :param request:  http request
    :param agency:  agency code
    :param id:  id number
    :rtype: string
    """
    res = CodeBook.objects.filter(id__val=id, id__agency=agency).only('hash').get()
    return res.hash

def collection_lastmodified(request, *args, **kwargs):
    """Get the last modification time for the entire eXist collection.
    Used to generate last-modified header for views that are based on
    the entire collection.<commit_msg>adjust etag/last modified conditional functions to not error if not found<commit_after>from datetime import datetime
from django.conf import settings
from ddisearch.ddi.models import CodeBook


def ddi_lastmodified(request, agency, id):
    """Get the last modification time for a DDI document in eXist by agency and id.
    Used to generate last-modified header for views based on a single EAD document.

    :param id: eadid
    :param preview: load document from preview collection; defaults to False
    :rtype: :class:`datetime.datetime`
    """
    # get document last modified by
    res = CodeBook.objects.filter(id__val=id, id__agency=agency).only('last_modified')
    if res.count():
        return exist_datetime_with_timezone(res[0].last_modified)

def ddi_etag(request, agency, id):
    """Generate a DDI Codebook document (specified by agency and id) by
    requesting a SHA-1 checksum of the entire DDI xml document from eXist.

    :param request:  http request
    :param agency:  agency code
    :param id:  id number
    :rtype: string
    """
    res = CodeBook.objects.filter(id__val=id, id__agency=agency).only('hash')
    # don't error if not found, but just let it fall through to view
    if res.count():
        return res[0].hash

def collection_lastmodified(request, *args, **kwargs):
    """Get the last modification time for the entire eXist collection.
    Used to generate last-modified header for views that are based on
    the entire collection.
{'fraction_non_alphanumeric': 0.07959842237361062, 'fraction_numerical': 0.0014342058085335247, 'mean_word_length': 3.8606271777003482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2604947', 'n_tokens_mistral': 793, 'n_tokens_neox': 774, 'n_words': 312}