<commit_before>from __future__ import unicode_literals

from .publisher import Publisher, SimplePatternsMixin
from .models import ModelPublisher

from django.template.response import TemplateResponse

class ViewPublisherMixin(object):
    '''
    A Publisher for non-API views.

    Replaces create_response with a wrapper around TemplateResponse.
    '''
    api_name = None

    def get_template_name(self):
        '''Return the template name to use for this view.'''
        return '%s/%s_%s.html' % (
            self.api_name or self.model._meta.app_label,
            self.model._meta.model_name,
            self.action,
        )

    def create_response(self, content, **response_kwargs):
        '''Return a response serialising the content'''
        template = response_kwargs.pop('template', None)
        if not template:
            template = self.get_template_names()
        return TemplateResponse(self.request, template, content,
            **response_kwargs
        )

class ViewPublisher(SimplePatternsMixin, Publisher):
    pass

class ModelViewPublisher(SimplePatternsMixin, ModelPublisher):
    model = None<commit_msg>Can't reference models in non-model view publisher<commit_after>from __future__ import unicode_literals

from .publisher import Publisher, SimplePatternsMixin
from .models import ModelPublisher

from django.template.response import TemplateResponse

class ViewPublisherMixin(object):
    '''
    A Publisher for non-API views.

    Replaces create_response with a wrapper around TemplateResponse.
    '''
    api_name = None

    def create_response(self, content, **response_kwargs):
        '''Return a response serialising the content'''
        template = response_kwargs.pop('template', None)
        if not template:
            template = self.get_template_names()
        return TemplateResponse(self.request, template, content,
            **response_kwargs
        )

class ViewPublisher(SimplePatternsMixin, Publisher):
    def get_template_name(self):
        return self.template_name % {
            'action': self.action,
            'method': self.method,
            'mode': self.mode,
        }

class ModelViewPublisher(SimplePatternsMixin, ModelPublisher):
    model = None

    def get_template_name(self):
        '''Return the template name to use for this view.'''
        return '%s/%s_%s.html' % (
            self.api_name or self.model._meta.app_label,
            self.model._meta.model_name,
            self.action,
        )
{'fraction_non_alphanumeric': 0.08473221422861711, 'fraction_numerical': 0.0, 'mean_word_length': 2.9231974921630095, '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': '3456651', 'n_tokens_mistral': 685, 'n_tokens_neox': 653, 'n_words': 180}