<commit_before>from django.contrib.auth.models import User
from django.db import models

from mezzanine.pages.page_processors import processor_for

from hs_core.models import BaseResource, ResourceManager, resource_processor


class CollectionResource(BaseResource):

    objects = ResourceManager('CollectionResource')

    discovery_content_type = 'Collection'  # used during discovery

    class Meta:
        proxy = True
        verbose_name = 'Collection Resource'

    @classmethod
    def get_supported_upload_file_types(cls):
        # no file types are supported
        return ()

    @classmethod
    def allow_multiple_file_upload(cls):
        # cannot upload any file
        return False

    @classmethod
    def can_have_multiple_files(cls):
        # resource can't have any files
        return False

    @property
    def can_be_public_or_discoverable(self):
        return self.metadata.has_all_required_elements() and (self.resources.count() > 0)

    @property
    def deleted_resources(self):
        return CollectionDeletedResource.objects.filter(collection=self)

    @property
    def has_resources(self):
        return self.resources.count() > 0

    @property
    def are_all_contained_resources_published(self):
        if not self.has_resources:
            return False
        return not self.resources.all().filter(raccess__published=False).exists()

    @property
    def can_be_published(self):
        if self.raccess.published:
            return False

        return self.can_be_public_or_discoverable and \
               self.are_all_contained_resources_published

    @property
    def update_text_file(self):
        return self.extra_data.get('update_text_file', 'True')


processor_for(CollectionResource)(resource_processor)


class CollectionDeletedResource(models.Model):
    resource_title = models.TextField(null=False, blank=False)
    deleted_by = models.ForeignKey(User)
    date_deleted = models.DateTimeField(auto_now_add=True)
    collection = models.ForeignKey(BaseResource)
    resource_id = models.CharField(max_length=32)
    resource_type = models.CharField(max_length=50)
    resource_owners = models.ManyToManyField(User, related_name='collectionDeleted')<commit_msg>[#3554] adding helper method to set flag for updating the text file<commit_after>from django.contrib.auth.models import User
from django.db import models

from mezzanine.pages.page_processors import processor_for

from hs_core.models import BaseResource, ResourceManager, resource_processor


class CollectionResource(BaseResource):

    objects = ResourceManager('CollectionResource')

    discovery_content_type = 'Collection'  # used during discovery

    class Meta:
        proxy = True
        verbose_name = 'Collection Resource'

    @classmethod
    def get_supported_upload_file_types(cls):
        # no file types are supported
        return ()

    @classmethod
    def allow_multiple_file_upload(cls):
        # cannot upload any file
        return False

    @classmethod
    def can_have_multiple_files(cls):
        # resource can't have any files
        return False

    @property
    def can_be_public_or_discoverable(self):
        return self.metadata.has_all_required_elements() and (self.resources.count() > 0)

    @property
    def deleted_resources(self):
        return CollectionDeletedResource.objects.filter(collection=self)

    @property
    def has_resources(self):
        return self.resources.count() > 0

    @property
    def are_all_contained_resources_published(self):
        if not self.has_resources:
            return False
        return not self.resources.all().filter(raccess__published=False).exists()

    @property
    def can_be_published(self):
        if self.raccess.published:
            return False

        return self.can_be_public_or_discoverable and \
               self.are_all_contained_resources_published

    @property
    def update_text_file(self):
        return self.extra_data.get('update_text_file', 'True')

    def set_update_text_file(self, flag):
        """Sets the flag to indicate if the text file needs to be updated or not.
        :param  flag:   value must be either 'True' or 'False'
        """
        self.extra_data = {'update_text_file': flag}
        self.save()


processor_for(CollectionResource)(resource_processor)


class CollectionDeletedResource(models.Model):
    resource_title = models.TextField(null=False, blank=False)
    deleted_by = models.ForeignKey(User)
    date_deleted = models.DateTimeField(auto_now_add=True)
    collection = models.ForeignKey(BaseResource)
    resource_id = models.CharField(max_length=32)
    resource_type = models.CharField(max_length=50)
    resource_owners = models.ManyToManyField(User, related_name='collectionDeleted')
{'fraction_non_alphanumeric': 0.07546383156139254, 'fraction_numerical': 0.003335417969564311, 'mean_word_length': 3.526415094339623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3845717', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1297, 'n_words': 299}