<commit_before>from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.db import models
from django.shortcuts import redirect
from django.utils import timezone
from uuid import uuid4
from taggit.managers import TaggableManager

from django_kala.managers import ActiveManager
from .defs import get_icon_for_mime, get_alt_for_mime

User = get_user_model()


class Document(models.Model):
    project = models.ForeignKey('projects.Project', on_delete=models.CASCADE)
    name = models.CharField(max_length=255)
    date = models.DateTimeField(default=timezone.now)
    removed = models.DateField(null=True)
    mime = models.CharField(max_length=255, null=True)
    category = models.ForeignKey('projects.Category', null=True, blank=True, on_delete=models.PROTECT)
    is_active = models.BooleanField(default=True)
    uuid = models.UUIDField(unique=True, db_index=True, default=uuid4, editable=False)

    tags = TaggableManager(blank=True)
    objects = ActiveManager()

    class Meta:
        ordering = ['-date', 'name']
        db_table = 'kala_documents'

    def set_active(self, active):
        manager = settings.PLATFORM_MANAGER()
        manager.archive_document(self) if active else manager.retrieve_document(self)

        self.is_active = active
        if not self.is_active:
            self.removed = timezone.now().date()
        self.save()

    def delete(self, using=None, **kwargs):
        DocumentVersion.objects.filter(document=self).delete()
        super(Document, self).delete(using)

    @property
    def description(self):
        if not hasattr(self, 'document'):
            self.document = self.get_latest()
        return self.document.description

    @property
    def user(self):
        if not hasattr(self, 'document'):
            self.document = self.get_latest()
        return self.document.user

    @property
    def created(self):
        if not hasattr(self, 'document'):
            self.document = self.get_latest()<commit_msg>* Do not try and archive the document automatically, this will be done by a task.<commit_after>from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Permission
from django.db import models
from django.shortcuts import redirect
from django.utils import timezone
from uuid import uuid4
from taggit.managers import TaggableManager

from django_kala.managers import ActiveManager
from .defs import get_icon_for_mime, get_alt_for_mime

User = get_user_model()


class Document(models.Model):
    project = models.ForeignKey('projects.Project', on_delete=models.CASCADE)
    name = models.CharField(max_length=255)
    date = models.DateTimeField(default=timezone.now)
    removed = models.DateField(null=True)
    mime = models.CharField(max_length=255, null=True)
    category = models.ForeignKey('projects.Category', null=True, blank=True, on_delete=models.PROTECT)
    is_active = models.BooleanField(default=True)
    uuid = models.UUIDField(unique=True, db_index=True, default=uuid4, editable=False)

    tags = TaggableManager(blank=True)
    objects = ActiveManager()

    class Meta:
        ordering = ['-date', 'name']
        db_table = 'kala_documents'

    def set_active(self, active):
        self.is_active = active
        if not self.is_active:
            self.removed = timezone.now().date()
        self.save()

    def delete(self, using=None, **kwargs):
        DocumentVersion.objects.filter(document=self).delete()
        super(Document, self).delete(using)

    @property
    def description(self):
        if not hasattr(self, 'document'):
            self.document = self.get_latest()
        return self.document.description

    @property
    def user(self):
        if not hasattr(self, 'document'):
            self.document = self.get_latest()
        return self.document.user

    @property
    def created(self):
        if not hasattr(self, 'document'):
            self.document = self.get_latest()
{'fraction_non_alphanumeric': 0.09977827050997783, 'fraction_numerical': 0.003941857600394186, 'mean_word_length': 3.5464725643896977, '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': '903735', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1164, 'n_words': 279}