<commit_before>from django.conf.urls.defaults import patterns, url
from django.http import Http404
from django.http import HttpResponseNotFound
from django.template.response import TemplateResponse

from ..product import app
from . import models

class CategorizedProductApp(app.ProductApp):
    app_name = 'category'
    category_model = models.Category
    category_details_templates = [
        'satchless/category/%(category_model)s/view.html',
        'satchless/category/view.html',
    ]
    category_list_templates = [
        'satchless/category/%(category_model)s/list.html',
        'satchless/category/list.html',
    ]
    allow_uncategorized_product_urls = False

    def path_from_slugs(self, slugs):
        """
        Returns list of Category instances matching given slug path.
        """
        if len(slugs) == 0:
            return []
        leaves = self.category_model.objects.filter(slug=slugs[-1])
        if not leaves:
            raise self.category_model.DoesNotExist, "slug='%s'" % slugs[-1]
        for leaf in leaves:
            path = leaf.get_ancestors()
            if len(path) + 1 != len(slugs):
                continue
            if [c.slug for c in path] != slugs[:-1]:
                continue
            return list(path) + [leaf]
        raise self.category_model.DoesNotExist

    def category_list(self, request):
        context = self.get_context_data(request)
        format_data = {
            'category_model': self.category_model._meta.module_name,
        }
        templates = [p % format_data for p in self.category_details_templates]
        return TemplateResponse(request, templates, context)

    def category_details(self, request, parent_slugs, category_slug):
        slugs = filter(None, parent_slugs.split('/') + [category_slug])
        try:
            path = self.path_from_slugs(slugs)
        except self.category_model.DoesNotExist:
            return HttpResponseNotFound()
        category = path[-1]
        context = self.get_context_data(request, category=category, path=path)
        format_data = {
            'category_model': category._meta.module_name,
        }
        templates = [p % format_data for p in self.category_details_templates]
        return TemplateResponse(request, templates, context)

    def get_context_data(self, request, product=None, **kwargs):
        categories = self.category_model.objects.filter(parent__isnull=True)
        context = dict(kwargs, categories=categories)
        if product:
            context.update({
                'path': product.category_path,<commit_msg>fix category_list view to use category_list templates<commit_after>from django.conf.urls.defaults import patterns, url
from django.http import Http404
from django.http import HttpResponseNotFound
from django.template.response import TemplateResponse

from ..product import app
from . import models

class CategorizedProductApp(app.ProductApp):
    app_name = 'category'
    category_model = models.Category
    category_details_templates = [
        'satchless/category/%(category_model)s/view.html',
        'satchless/category/view.html',
    ]
    category_list_templates = [
        'satchless/category/%(category_model)s/list.html',
        'satchless/category/list.html',
    ]
    allow_uncategorized_product_urls = False

    def path_from_slugs(self, slugs):
        """
        Returns list of Category instances matching given slug path.
        """
        if len(slugs) == 0:
            return []
        leaves = self.category_model.objects.filter(slug=slugs[-1])
        if not leaves:
            raise self.category_model.DoesNotExist, "slug='%s'" % slugs[-1]
        for leaf in leaves:
            path = leaf.get_ancestors()
            if len(path) + 1 != len(slugs):
                continue
            if [c.slug for c in path] != slugs[:-1]:
                continue
            return list(path) + [leaf]
        raise self.category_model.DoesNotExist

    def category_list(self, request):
        context = self.get_context_data(request)
        format_data = {
            'category_model': self.category_model._meta.module_name,
        }
        templates = [p % format_data for p in self.category_list_templates]
        return TemplateResponse(request, templates, context)

    def category_details(self, request, parent_slugs, category_slug):
        slugs = filter(None, parent_slugs.split('/') + [category_slug])
        try:
            path = self.path_from_slugs(slugs)
        except self.category_model.DoesNotExist:
            return HttpResponseNotFound()
        category = path[-1]
        context = self.get_context_data(request, category=category, path=path)
        format_data = {
            'category_model': category._meta.module_name,
        }
        templates = [p % format_data for p in self.category_details_templates]
        return TemplateResponse(request, templates, context)

    def get_context_data(self, request, product=None, **kwargs):
        categories = self.category_model.objects.filter(parent__isnull=True)
        context = dict(kwargs, categories=categories)
        if product:
            context.update({
                'path': product.category_path,
{'fraction_non_alphanumeric': 0.09565716472163766, 'fraction_numerical': 0.0034436579299789555, 'mean_word_length': 2.633078526754691, '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': '3679599', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1446, 'n_words': 319}