<commit_before>from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateView

from documents.models import Document


class ArchiveView(TemplateView):
    template_name = 'documents/settings/archive.html'

    def get_context_data(self, **kwargs):
        return {
            'document': self.document,
            'project': self.project,
            'organization': self.project.organization
        }

    @method_decorator(login_required)
    def dispatch(self, request, project_pk, document_pk, *args, **kwargs):
        self.document = get_object_or_404(
            Document.objects.active().select_related(
                'project',
                'project__organization'
            ),
            pk=document_pk
        )
        if not self.document.can_manage(request.user):
            raise PermissionDenied(_('You do not have permission to archive this document'))
        self.project = self.document.project

        return super(ArchiveView, self).dispatch(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        self.document.set_active(False)
        return redirect(
            reverse(
                'projects:document_archive',
                args=[
                    self.document.project.pk,
                    self.document.pk
                ]
            )
        )
<commit_msg>* If the document is being archived, then redirect to the project page.<commit_after>from django.contrib.auth.decorators import login_required
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404, redirect
from django.urls import reverse
from django.utils.decorators import method_decorator
from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateView

from documents.models import Document


class ArchiveView(TemplateView):
    template_name = 'documents/settings/archive.html'

    def get_context_data(self, **kwargs):
        return {
            'document': self.document,
            'project': self.project,
            'organization': self.project.organization
        }

    @method_decorator(login_required)
    def dispatch(self, request, project_pk, document_pk, *args, **kwargs):
        self.document = get_object_or_404(
            Document.objects.active().select_related(
                'project',
                'project__organization'
            ),
            pk=document_pk
        )
        if not self.document.can_manage(request.user):
            raise PermissionDenied(_('You do not have permission to archive this document'))
        self.project = self.document.project

        return super(ArchiveView, self).dispatch(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        self.document.set_active(False)
        return redirect(
            reverse(
                'projects:project',
                args=[
                    self.document.project.pk,
                ]
            )
        )

{'fraction_non_alphanumeric': 0.08567073170731708, 'fraction_numerical': 0.003658536585365854, 'mean_word_length': 2.442812172088143, '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': '3432027', 'n_tokens_mistral': 863, 'n_tokens_neox': 811, 'n_words': 201}