<commit_before># Specialized template classes for Django, decoupled from the basic template system.

from django.core import template_loader
from django.core.template import Context
from django.conf.settings import DEBUG, INTERNAL_IPS
from django.utils.httpwrappers import HttpResponse

def load_and_render(template_name, dictionary=None, context_instance=None):
    dictionary = dictionary or {}
    t = template_loader.get_template(template_name)
    if context_instance:
        c = context_instance.update(dictionary)
    else:
        c = Context(dictionary)
    return HttpResponse(t.render(c))

class DjangoContext(Context):
    """
    This subclass of template.Context automatically populates 'user' and
    'messages' in the context.
    """
    def __init__(self, request, dict=None):
        Context.__init__(self, dict)
        self['user'] = request.user
        self['messages'] = request.user.get_and_delete_messages()<commit_msg>Fixed #533 -- Fixed bug when using custom context_instance in load_and_render(). Thanks, Brantley<commit_after># Specialized template classes for Django, decoupled from the basic template system.

from django.core import template_loader
from django.core.template import Context
from django.conf.settings import DEBUG, INTERNAL_IPS
from django.utils.httpwrappers import HttpResponse

def load_and_render(template_name, dictionary=None, context_instance=None):
    dictionary = dictionary or {}
    t = template_loader.get_template(template_name)
    if context_instance:
        context_instance.update(dictionary)
    else:
        context_instance = Context(dictionary)
    return HttpResponse(t.render(context_instance))

class DjangoContext(Context):
    """
    This subclass of template.Context automatically populates 'user' and
    'messages' in the context.
    """
    def __init__(self, request, dict=None):
        Context.__init__(self, dict)
        self['user'] = request.user
        self['messages'] = request.user.get_and_delete_messages()
{'fraction_non_alphanumeric': 0.08491508491508491, 'fraction_numerical': 0.0014985014985014985, 'mean_word_length': 4.384408602150538, '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': '4088429', 'n_tokens_mistral': 541, 'n_tokens_neox': 525, 'n_words': 151}