<commit_before>from django import template
import json
from django.conf import settings
register = template.Library()

@register.simple_tag(takes_context=True)
def get_admin_context(context):

    ctx = {'location':None, 'param1':None, 'param2':None, 'static':settings.STATIC_URL}
    try:
        context['app_list']
        if len(context['app_list']) > 1:
            # we are at /admin/
            ctx['location'] = 'admin_index'
            return json.dumps(ctx)
        elif len(context['app_list']) == 1:
            #We are at the app index eg: /admin/app/
            ctx['location'] = 'app_index'
            ctx['param1'] = context['app_list'][0]['name'].lower()

            return json.dumps(ctx)

    except KeyError:
        pass

    try:
        # we are in the list view of the model eg: admin/app/model/
        ctx['location']= 'model_list'
        module_name = context['module_name'].lower()
        # django adds an 's' to every model name in this view, so we are gonna
        ctx['param1'] = module_name

        return json.dumps(ctx)

    except KeyError:
        pass

    try:
        # editing a model
        ctx['location']= 'model_edit'
        ctx['param1'] = context['original'].__class__.__name__.lower()
        ctx['param2'] = context['original'].pk
        return json.dumps(ctx)
    except KeyError:
        pass

    return json.dumps(ctx)<commit_msg>Check if original object is None<commit_after>from django import template
import json
from django.conf import settings
register = template.Library()

@register.simple_tag(takes_context=True)
def get_admin_context(context):

    ctx = {'location':None, 'param1':None, 'param2':None, 'static':settings.STATIC_URL}
    try:
        context['app_list']
        if len(context['app_list']) > 1:
            # we are at /admin/
            ctx['location'] = 'admin_index'
            return json.dumps(ctx)
        elif len(context['app_list']) == 1:
            #We are at the app index eg: /admin/app/
            ctx['location'] = 'app_index'
            ctx['param1'] = context['app_list'][0]['name'].lower()

            return json.dumps(ctx)

    except KeyError:
        pass

    try:
        # we are in the list view of the model eg: admin/app/model/
        ctx['location']= 'model_list'
        module_name = context['module_name'].lower()
        # django adds an 's' to every model name in this view, so we are gonna
        ctx['param1'] = module_name

        return json.dumps(ctx)

    except KeyError:
        pass

    try:
        # editing a model
        ctx['location']= 'model_edit'
        if context['original'] is not None:
            ctx['param1'] = context['original'].__class__.__name__.lower()
            ctx['param2'] = context['original'].pk
        return json.dumps(ctx)
    except KeyError:
        pass

    return json.dumps(ctx)
{'fraction_non_alphanumeric': 0.12626792584819868, 'fraction_numerical': 0.0062959076600209865, 'mean_word_length': 2.4088200238379023, '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': '2871208', 'n_tokens_mistral': 855, 'n_tokens_neox': 833, 'n_words': 227}