<commit_before>import django.core.urlresolvers
import django.views.generic
from django import shortcuts
from django.contrib.contenttypes import models as contenttypes
from django.views import generic

import core
from core.views import base
import features
from features.associations import models as associations
from features.contributions import views as contributions
from features.files import forms as files
from features.galleries import forms as galleries
from features.gestalten import models as gestalten
from features.groups import models as groups
from . import forms, models


class List(core.views.PermissionMixin, django.views.generic.ListView):
    permission_required = 'content.list'
    model = associations.Association
    paginate_by = 10
    template_name = 'content/list.html'

    def get_queryset(self):
        return super().get_queryset().ordered_user_content(self.request.user)


class DetailBase(contributions.ContributionFormMixin, base.PermissionMixin, generic.DetailView):
    permission_required = 'content.view'
    permission_required_post = 'content.comment'
    model = associations.Association
    template_name = 'articles/detail.html'

    form_class = forms.Comment

    def get_object(self, queryset=None):
        try:
            entity = groups.Group.objects.get(slug=self.kwargs['entity_slug'])
        except groups.Group.DoesNotExist:
            entity = shortcuts.get_object_or_404(
                    gestalten.Gestalt, user__username=self.kwargs['entity_slug'])
        return shortcuts.get_object_or_404(
                self.model,
                entity_id=entity.id,
                entity_type=contenttypes.ContentType.objects.get_for_model(entity),
                slug=self.kwargs['association_slug'])

    def get_template_names(self):
        if self.object.container.is_poll:
            name = ('polls/detail.html', )
        elif self.object.container.is_gallery:
            name = ('galleries/detail.html', )
        elif self.object.container.is_file:
            name = ('files/detail.html', )
        elif self.object.container.is_event:
            name = ('events/detail.html', )
        return super().get_template_names()


class Detail(DetailBase):
    def get(self, request, *args, **kwargs):
        self.object = self.get_object()
        if self.object.container.is_poll:
            return features.polls.views.Detail(kwargs=kwargs, request=request).get(
                    request, *args, **kwargs)
        return super().get(request, *args, **kwargs)


class Permalink(django.views.generic.RedirectView):
    def get_redirect_url(self, *args, **kwargs):
        association = django.shortcuts.get_object_or_404(
                associations.Association, pk=kwargs.get('association_pk'))
        return django.core.urlresolvers.reverse(<commit_msg>Fix template names<commit_after>import django.core.urlresolvers
import django.views.generic
from django import shortcuts
from django.contrib.contenttypes import models as contenttypes
from django.views import generic

import core
from core.views import base
import features
from features.associations import models as associations
from features.contributions import views as contributions
from features.files import forms as files
from features.galleries import forms as galleries
from features.gestalten import models as gestalten
from features.groups import models as groups
from . import forms


class List(core.views.PermissionMixin, django.views.generic.ListView):
    permission_required = 'content.list'
    model = associations.Association
    paginate_by = 10
    template_name = 'content/list.html'

    def get_queryset(self):
        return super().get_queryset().ordered_user_content(self.request.user)


class DetailBase(contributions.ContributionFormMixin, base.PermissionMixin, generic.DetailView):
    permission_required = 'content.view'
    permission_required_post = 'content.comment'
    model = associations.Association
    template_name = 'articles/detail.html'

    form_class = forms.Comment

    def get_object(self, queryset=None):
        try:
            entity = groups.Group.objects.get(slug=self.kwargs['entity_slug'])
        except groups.Group.DoesNotExist:
            entity = shortcuts.get_object_or_404(
                    gestalten.Gestalt, user__username=self.kwargs['entity_slug'])
        return shortcuts.get_object_or_404(
                self.model,
                entity_id=entity.id,
                entity_type=contenttypes.ContentType.objects.get_for_model(entity),
                slug=self.kwargs['association_slug'])

    def get_template_names(self):
        if self.object.container.is_poll:
            names = ('polls/detail.html',)
        elif self.object.container.is_gallery:
            names = ('galleries/detail.html',)
        elif self.object.container.is_file:
            names = ('files/detail.html',)
        elif self.object.container.is_event:
            names = ('events/detail.html',)
        else:
            names = super().get_template_names()
        return names


class Detail(DetailBase):
    def get(self, request, *args, **kwargs):
        self.object = self.get_object()
        if self.object.container.is_poll:
            return features.polls.views.Detail(kwargs=kwargs, request=request).get(
                    request, *args, **kwargs)
        return super().get(request, *args, **kwargs)


class Permalink(django.views.generic.RedirectView):
    def get_redirect_url(self, *args, **kwargs):
        association = django.shortcuts.get_object_or_404(
                associations.Association, pk=kwargs.get('association_pk'))
        return django.core.urlresolvers.reverse(
{'fraction_non_alphanumeric': 0.09352517985611511, 'fraction_numerical': 0.003860326373047903, 'mean_word_length': 3.209748892171344, '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': '87231', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1540, 'n_words': 335}