<commit_before>from django import template
from django.db.models import get_model
from django.template import (Node, TemplateSyntaxError, VariableDoesNotExist,
                             FilterExpression)
from categories.base import CategoryBase
from categories.models import Category
from mptt.utils import drilldown_tree_for_node
from mptt.templatetags.mptt_tags import (tree_path, tree_info, RecurseTreeNode,
                                         full_tree_for_model)

register = template.Library()

register.filter("category_path", tree_path)
register.filter(tree_info)
register.tag("full_tree_for_category", full_tree_for_model)


def resolve(var, context):
    try:
        return var.resolve(context)
    except VariableDoesNotExist:
        try:
            return var.var
        except AttributeError:
            return var


def get_cat_model(model):
    """
    Return a class from a string or class
    """
    try:
        if isinstance(model, basestring):
            model_class = get_model(*model.split("."))
        elif issubclass(model, CategoryBase):
            model_class = model
        if model_class is None:
            raise TypeError
    except TypeError:
        raise TemplateSyntaxError("Unknown model submitted: %s" % model)
    return model_class


def get_category(category_string, model=Category):
    """
    Convert a string, including a path, and return the Category object
    """
    model_class = get_cat_model(model)
    category = category_string.strip("'\"")<commit_msg>Fixes: Exception Value:	'Category' object has no attribute 'strip' Exception Location:	/usr/local/python-env/medtehnica.ro/src/django-categories/categories/templatetags/category_tags.py in get_category, line 49<commit_after>from django import template
from django.db.models import get_model
from django.template import (Node, TemplateSyntaxError, VariableDoesNotExist,
                             FilterExpression)
from categories.base import CategoryBase
from categories.models import Category
from mptt.utils import drilldown_tree_for_node
from mptt.templatetags.mptt_tags import (tree_path, tree_info, RecurseTreeNode,
                                         full_tree_for_model)

register = template.Library()

register.filter("category_path", tree_path)
register.filter(tree_info)
register.tag("full_tree_for_category", full_tree_for_model)


def resolve(var, context):
    try:
        return var.resolve(context)
    except VariableDoesNotExist:
        try:
            return var.var
        except AttributeError:
            return var


def get_cat_model(model):
    """
    Return a class from a string or class
    """
    try:
        if isinstance(model, basestring):
            model_class = get_model(*model.split("."))
        elif issubclass(model, CategoryBase):
            model_class = model
        if model_class is None:
            raise TypeError
    except TypeError:
        raise TemplateSyntaxError("Unknown model submitted: %s" % model)
    return model_class


def get_category(category_string, model=Category):
    """
    Convert a string, including a path, and return the Category object
    """
    model_class = get_cat_model(model)
    category = category_string.__unicode__().strip("'\'")
{'fraction_non_alphanumeric': 0.07803379416282642, 'fraction_numerical': 0.0006144393241167435, 'mean_word_length': 3.080200501253133, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5550509', 'n_tokens_mistral': 897, 'n_tokens_neox': 879, 'n_words': 236}