<commit_before>from . import filters, forms, models
from content import creation as content_creation, models as content_models
from crispy_forms import bootstrap, layout
from django import http, shortcuts
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import mixins as auth_mixins
from django.contrib.sites import models as sites_models
from django.core import urlresolvers
from django.db import models as django_models
from django.utils import six
from django.views import generic
from django_filters import views as filters_views
from rules.contrib import views as rules_views
from utils import forms as utils_forms, views as utils_views


class Gestalt(utils_views.List):
    menu = 'gestalt'
    permission = 'entities.view_gestalt'
    sidebar = ('calendar',)
    template_name = 'entities/gestalt_detail.html'

    def get_permission_object(self):
        return self.get_gestalt()

    def get_queryset(self):
        return content_models.Content.objects.permitted(self.request.user).filter(django_models.Q(gestaltcontent__gestalt=self.get_gestalt()) | django_models.Q(author=self.get_gestalt()))

    def get_title(self):
        return str(self.get_gestalt())

class GestaltList(utils_views.List):
    menu = 'gestalt'
    permission = 'content.view_content_list'
    queryset = models.Gestalt.objects.filter(public=True)
    title = 'Gestalten'

class GestaltUpdate(utils_views.ActionMixin, generic.UpdateView):
    action = 'Dein Profil'
    form_class = forms.Gestalt
    menu = 'gestalt'
    message = 'Die Einstellungen wurden geändert.'
    model = models.Gestalt
    permission = 'entities.change_gestalt'

    def get_parent(self):
        return self.object


class GestaltAvatarUpdate(utils_views.ActionMixin, generic.UpdateView):
    action = 'Avatar ändern'
    fields = ('avatar',)
    layout = ('avatar',)
    menu = 'gestalt'
    model = models.Gestalt
    permission = 'entities.change_gestalt'

    def get_parent(self):
        return self.object


class GestaltBackgroundUpdate(utils_views.ActionMixin, generic.UpdateView):
    action = 'Hintergrundbild ändern'
    fields = ('background',)
    layout = ('background',)
    menu = 'gestalt'
    model = models.Gestalt
    permission = 'entities.change_gestalt'

    def get_parent(self):
        return self.object


class Group(utils_views.List):
    inline_view = (content_creation.Gallery, 'intro_gallery_form')
    menu = 'group'
    permission = 'entities.view_group'
    template_name = 'entities/group_detail.html'

    def get(self, *args, **kwargs):
        if not self.get_group():
            raise http.Http404('Gruppe nicht gefunden')
        return super().get(*args, **kwargs)

    def get_context_data(self, **kwargs):
        conversations = self.get_conversations()
        kwargs['calendar_events'] = self.get_events().around()
        kwargs['intro_content'] = self.get_intro_content()
        kwargs['conversations'] = conversations[:3]
        kwargs['has_more_conversations'] = len(conversations) > 3
        kwargs['sidebar_groups'] = models.Group.objects.exclude(pk=self.get_group().pk).scored().similar(self.get_group()).order_by('-score')
        kwargs['upcoming_events'] = self.get_events().upcoming(3)
        return super().get_context_data(**kwargs)

    def get_events(self):
        return content_models.Event.objects.permitted(self.request.user).filter(groups=self.get_group())

    def get_group_content(self):
        return self.get_group().content.permitted(self.request.user)

    def get_inline_view_form(self):
        # FIXME: hacky code follows
        if (self.request.user.has_perm('entities.create_group_content', self.get_group())
                and not self.get_group().get_head_gallery()):
            form = super().get_inline_view_form()
            form.helper.filter(six.string_types).wrap(layout.Field)
            form.helper.filter(layout.Field).update_attributes(
                    **{'data-component': '', 'type': 'hidden'})
            del form.helper[-1]
            form.helper.layout.append(utils_forms.Submit('<i class="sg sg-2x sg-camera"></i>', 'gallery-create', 'btn btn-backdrop btn-ts'))
            form.initial['image_creation_redirect'] = True
            form.initial['pinned'] = True
            form.initial['public'] = True
            form.initial['text'] = 'Introgalerie der Gruppe @{}'.format(self.get_group().slug)
            form.initial['title'] = self.get_group()
            return form
        return None

    def get_intro_content(self):
        pinned_content = self.get_group_content().filter(groupcontent__pinned=True)
        try:
            return pinned_content.exclude(pk=self.get_group().get_head_gallery().pk)
        except AttributeError:
            return pinned_content

    def get_conversations(self):
        return self.get_group().get_conversations(self.request.user)[:3]

    def get_queryset(self):
        return self.get_group_content().filter(groupcontent__pinned=False).exclude(article__isnull=False, public=False)

    def get_related_object(self):
        return self.get_group()
<commit_msg>fix paginated link to group conversations<commit_after>from . import filters, forms, models
from content import creation as content_creation, models as content_models
from crispy_forms import bootstrap, layout
from django import http, shortcuts
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import mixins as auth_mixins
from django.contrib.sites import models as sites_models
from django.core import urlresolvers
from django.db import models as django_models
from django.utils import six
from django.views import generic
from django_filters import views as filters_views
from rules.contrib import views as rules_views
from utils import forms as utils_forms, views as utils_views


class Gestalt(utils_views.List):
    menu = 'gestalt'
    permission = 'entities.view_gestalt'
    sidebar = ('calendar',)
    template_name = 'entities/gestalt_detail.html'

    def get_permission_object(self):
        return self.get_gestalt()

    def get_queryset(self):
        return content_models.Content.objects.permitted(self.request.user).filter(django_models.Q(gestaltcontent__gestalt=self.get_gestalt()) | django_models.Q(author=self.get_gestalt()))

    def get_title(self):
        return str(self.get_gestalt())

class GestaltList(utils_views.List):
    menu = 'gestalt'
    permission = 'content.view_content_list'
    queryset = models.Gestalt.objects.filter(public=True)
    title = 'Gestalten'

class GestaltUpdate(utils_views.ActionMixin, generic.UpdateView):
    action = 'Dein Profil'
    form_class = forms.Gestalt
    menu = 'gestalt'
    message = 'Die Einstellungen wurden geändert.'
    model = models.Gestalt
    permission = 'entities.change_gestalt'

    def get_parent(self):
        return self.object


class GestaltAvatarUpdate(utils_views.ActionMixin, generic.UpdateView):
    action = 'Avatar ändern'
    fields = ('avatar',)
    layout = ('avatar',)
    menu = 'gestalt'
    model = models.Gestalt
    permission = 'entities.change_gestalt'

    def get_parent(self):
        return self.object


class GestaltBackgroundUpdate(utils_views.ActionMixin, generic.UpdateView):
    action = 'Hintergrundbild ändern'
    fields = ('background',)
    layout = ('background',)
    menu = 'gestalt'
    model = models.Gestalt
    permission = 'entities.change_gestalt'

    def get_parent(self):
        return self.object


class Group(utils_views.List):
    inline_view = (content_creation.Gallery, 'intro_gallery_form')
    menu = 'group'
    permission = 'entities.view_group'
    template_name = 'entities/group_detail.html'

    def get(self, *args, **kwargs):
        if not self.get_group():
            raise http.Http404('Gruppe nicht gefunden')
        return super().get(*args, **kwargs)

    def get_context_data(self, **kwargs):
        conversations = self.get_conversations()
        kwargs['calendar_events'] = self.get_events().around()
        kwargs['intro_content'] = self.get_intro_content()
        kwargs['conversations'] = conversations[:3]
        kwargs['has_more_conversations'] = len(conversations) > 3
        kwargs['sidebar_groups'] = models.Group.objects.exclude(pk=self.get_group().pk).scored().similar(self.get_group()).order_by('-score')
        kwargs['upcoming_events'] = self.get_events().upcoming(3)
        return super().get_context_data(**kwargs)

    def get_events(self):
        return content_models.Event.objects.permitted(self.request.user).filter(groups=self.get_group())

    def get_group_content(self):
        return self.get_group().content.permitted(self.request.user)

    def get_inline_view_form(self):
        # FIXME: hacky code follows
        if (self.request.user.has_perm('entities.create_group_content', self.get_group())
                and not self.get_group().get_head_gallery()):
            form = super().get_inline_view_form()
            form.helper.filter(six.string_types).wrap(layout.Field)
            form.helper.filter(layout.Field).update_attributes(
                    **{'data-component': '', 'type': 'hidden'})
            del form.helper[-1]
            form.helper.layout.append(utils_forms.Submit('<i class="sg sg-2x sg-camera"></i>', 'gallery-create', 'btn btn-backdrop btn-ts'))
            form.initial['image_creation_redirect'] = True
            form.initial['pinned'] = True
            form.initial['public'] = True
            form.initial['text'] = 'Introgalerie der Gruppe @{}'.format(self.get_group().slug)
            form.initial['title'] = self.get_group()
            return form
        return None

    def get_intro_content(self):
        pinned_content = self.get_group_content().filter(groupcontent__pinned=True)
        try:
            return pinned_content.exclude(pk=self.get_group().get_head_gallery().pk)
        except AttributeError:
            return pinned_content

    def get_conversations(self):
        return self.get_group().get_conversations(self.request.user)

    def get_queryset(self):
        return self.get_group_content().filter(groupcontent__pinned=False).exclude(article__isnull=False, public=False)

    def get_related_object(self):
        return self.get_group()

{'fraction_non_alphanumeric': 0.11155339805825243, 'fraction_numerical': 0.0016504854368932038, 'mean_word_length': 3.602770330652368, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '608918', 'n_tokens_mistral': 3080, 'n_tokens_neox': 3009, 'n_words': 609}