<commit_before>import re

import django.views.generic.edit
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.utils.timezone import now

import core
from core.templatetags.core import ref
from features.associations.models import Association
from features.associations.views import AssociationMixin
from features.contributions.models import Contribution
from features.conversations.views import CreateGestaltConversation
from . import models


class Delete(AssociationMixin, core.views.PermissionMixin, django.views.generic.UpdateView):
    permission_required = 'contributions.delete'
    model = models.Contribution
    fields = []
    template_name = 'contributions/delete.html'

    def get_form_kwargs(self):
        self.association = self.get_association()
        kwargs = super().get_form_kwargs()
        kwargs['instance'].deleted = now()
        return kwargs

    def get_success_url(self):
        return self.association.get_absolute_url()


class ReplyToAuthor(CreateGestaltConversation):
    permission_required = 'contributions.reply_to_author'

    def get_initial(self):
        subject = 'Re: {}'.format(self.contribution.container.subject)
        if self.association.container.is_conversation:
            permalink_url = reverse('conversation', args=[self.association.pk])
        else:
            permalink_url = reverse('content-permalink', args=[self.association.pk])
        text = '{}\n — [{}]({}#{})'.format(
                self.contribution.contribution.text, self.contribution.author,
                permalink_url, ref(self.contribution))
        text = re.sub('^', '> ', text, flags=re.MULTILINE)
        return {'subject': subject, 'text': text}

    def get_permission_object(self):
        self.association = get_object_or_404(
                Association, pk=self.kwargs.get('association_pk'))
        self.contribution = get_object_or_404(
                Contribution, pk=self.kwargs.get('contribution_pk'))
        self.entity = self.contribution.author
        return self.contribution
<commit_msg>Allow deleting internal contributions, refs #632<commit_after>import re

import django.views.generic.edit
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.utils.timezone import now

import core
from core.templatetags.core import ref
from features.associations.models import Association
from features.associations.views import AssociationMixin
from features.contributions.models import Contribution
from features.conversations.views import CreateGestaltConversation
from . import models


class Delete(AssociationMixin, core.views.PermissionMixin, django.views.generic.UpdateView):
    permission_required = 'contributions.delete'
    queryset = models.Contribution.objects_with_internal
    fields = []
    template_name = 'contributions/delete.html'

    def get_form_kwargs(self):
        self.association = self.get_association()
        kwargs = super().get_form_kwargs()
        kwargs['instance'].deleted = now()
        return kwargs

    def get_success_url(self):
        return self.association.get_absolute_url()


class ReplyToAuthor(CreateGestaltConversation):
    permission_required = 'contributions.reply_to_author'

    def get_initial(self):
        subject = 'Re: {}'.format(self.contribution.container.subject)
        if self.association.container.is_conversation:
            permalink_url = reverse('conversation', args=[self.association.pk])
        else:
            permalink_url = reverse('content-permalink', args=[self.association.pk])
        text = '{}\n — [{}]({}#{})'.format(
                self.contribution.contribution.text, self.contribution.author,
                permalink_url, ref(self.contribution))
        text = re.sub('^', '> ', text, flags=re.MULTILINE)
        return {'subject': subject, 'text': text}

    def get_permission_object(self):
        self.association = get_object_or_404(
                Association, pk=self.kwargs.get('association_pk'))
        self.contribution = get_object_or_404(
                Contribution, pk=self.kwargs.get('contribution_pk'))
        self.entity = self.contribution.author
        return self.contribution

{'fraction_non_alphanumeric': 0.10113690194220748, 'fraction_numerical': 0.004973945997157745, 'mean_word_length': 3.6052344601962925, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2623217', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1163, 'n_words': 235}