<commit_before># coding: utf-8
from django.utils.module_loading import import_string


def _load(module):
    return import_string(module) if isinstance(module, str) else module


class view():
    def __init__(self, model, view, slug_field):
        self.model = _load(model)
        self.view = _load(view)
        self.slug_field = slug_field

        # define 'get_path' method for model
        self.model.get_path = lambda instance: '/'.join([getattr(item, slug_field) for item in instance.get_ancestors(include_self=True)])

    def __call__(self, *args, **kwargs):
        if 'path' not in kwargs:
            raise ValueError('Path was not captured! Please capture it in your urlconf. Example: url(r\'^gallery/(?P<path>.*)\', mptt_urls.view(...), ...)')

        instance = None  # actual instance the path is pointing to (None by default)
        path = kwargs['path']
        instance_slug = path.split('/')[-1]  # slug of the instance

        if instance_slug:
            candidates = self.model.objects.filter(**{self.slug_field: instance_slug})  # candidates to be the instance
            for candidate in candidates:
                # here we compare each candidate's path to the path passed to this view
                if candidate.get_path() == path:
                    instance = candidate
                    break

        kwargs['instance'] = instance
        return self.view(*args, **kwargs)<commit_msg>Add trailing slash to forward and reverse url resolutions<commit_after># coding: utf-8
from django.utils.module_loading import import_string


def _load(module):
    return import_string(module) if isinstance(module, str) else module


class view():
    def __init__(self, model, view, slug_field):
        self.model = _load(model)
        self.view = _load(view)
        self.slug_field = slug_field

        # define 'get_path' method for model
        self.model.get_path = lambda instance: '/'.join([getattr(item, slug_field) for item in instance.get_ancestors(include_self=True)]) + '/'

    def __call__(self, *args, **kwargs):
        if 'path' not in kwargs:
            raise ValueError('Path was not captured! Please capture it in your urlconf. Example: url(r\'^gallery/(?P<path>.*)\', mptt_urls.view(...), ...)')

        instance = None  # actual instance the path is pointing to (None by default)
        path = kwargs['path']
        instance_slug = path.split('/')[-2]  # slug of the instance

        if instance_slug:
            candidates = self.model.objects.filter(**{self.slug_field: instance_slug})  # candidates to be the instance
            for candidate in candidates:
                # here we compare each candidate's path to the path passed to this view
                if candidate.get_path() == path:
                    instance = candidate
                    break

        kwargs['instance'] = instance
        return self.view(*args, **kwargs)
{'fraction_non_alphanumeric': 0.1092032967032967, 'fraction_numerical': 0.0013736263736263737, 'mean_word_length': 2.5874384236453203, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6097449', 'n_tokens_mistral': 816, 'n_tokens_neox': 794, 'n_words': 255}