<commit_before>from django.contrib.postgres.fields import ArrayField
from django.utils import timezone
from django.db import models
from website import settings
from osf_models.models.base import BaseModel, ObjectIDMixin
from osf_models.utils.datetime_aware_jsonfield import DateTimeAwareJSONField

from website.addons.base import StorageAddonBase
from website.archiver import (
    ARCHIVER_INITIATED,
    ARCHIVER_SUCCESS,
    ARCHIVER_FAILURE,
    ARCHIVER_FAILURE_STATUSES
)


class ArchiveTarget(ObjectIDMixin, BaseModel):
    """Stores the results of archiving a single addon
    """

    # addon_short_name of target addon
    name = models.CharField(max_length=2048)

    status = models.CharField(max_length=40, default=ARCHIVER_INITIATED)
    # <dict> representation of a website.archiver.AggregateStatResult
    # Format: {
    #     'target_id': <str>,
    #     'target_name': <str>,
    #     'targets': <list>(StatResult | AggregateStatResult),
    #     'num_files': <int>,
    #     'disk_usage': <float>,
    # }
    stat_result = DateTimeAwareJSONField(blank=True)
    errors = ArrayField(models.TextField(), default=list, blank=True)

    def __repr__(self):
        return '<{0}(_id={1}, name={2}, status={3})>'.format(
            self.__class__.__name__,
            self._id,
            self.name,
            self.status
        )


class ArchiveJob(ObjectIDMixin, BaseModel):
    # whether or not the ArchiveJob is complete (success or fail)
    done = models.BooleanField(default=False, verbose_name='completed')
    # whether or not emails have been sent for this ArchiveJob
    sent = models.BooleanField(default=False, verbose_name='emails sent')
    status = models.CharField(max_length=40, default=ARCHIVER_INITIATED)
    datetime_initiated = models.DateTimeField(default=timezone.now, verbose_name='intiated at')

    dst_node = models.ForeignKey('Node', related_name='active', verbose_name='destination node', null=True)
    src_node = models.ForeignKey('Node', verbose_name='source node', null=True)
    initiator = models.ForeignKey('OSFUser', null=True)

    target_addons = models.ManyToManyField('ArchiveTarget')

    def __repr__(self):
        return (
            '<{ClassName}(_id={self._id}, done={self.done}, '
            ' status={self.status}, src_node={self.src_node}, dst_node={self.dst_node})>'<commit_msg>Registration.dst_node will always be a Registration<commit_after>from django.contrib.postgres.fields import ArrayField
from django.utils import timezone
from django.db import models
from website import settings
from osf_models.models.base import BaseModel, ObjectIDMixin
from osf_models.utils.datetime_aware_jsonfield import DateTimeAwareJSONField

from website.addons.base import StorageAddonBase
from website.archiver import (
    ARCHIVER_INITIATED,
    ARCHIVER_SUCCESS,
    ARCHIVER_FAILURE,
    ARCHIVER_FAILURE_STATUSES
)


class ArchiveTarget(ObjectIDMixin, BaseModel):
    """Stores the results of archiving a single addon
    """

    # addon_short_name of target addon
    name = models.CharField(max_length=2048)

    status = models.CharField(max_length=40, default=ARCHIVER_INITIATED)
    # <dict> representation of a website.archiver.AggregateStatResult
    # Format: {
    #     'target_id': <str>,
    #     'target_name': <str>,
    #     'targets': <list>(StatResult | AggregateStatResult),
    #     'num_files': <int>,
    #     'disk_usage': <float>,
    # }
    stat_result = DateTimeAwareJSONField(blank=True)
    errors = ArrayField(models.TextField(), default=list, blank=True)

    def __repr__(self):
        return '<{0}(_id={1}, name={2}, status={3})>'.format(
            self.__class__.__name__,
            self._id,
            self.name,
            self.status
        )


class ArchiveJob(ObjectIDMixin, BaseModel):
    # whether or not the ArchiveJob is complete (success or fail)
    done = models.BooleanField(default=False, verbose_name='completed')
    # whether or not emails have been sent for this ArchiveJob
    sent = models.BooleanField(default=False, verbose_name='emails sent')
    status = models.CharField(max_length=40, default=ARCHIVER_INITIATED)
    datetime_initiated = models.DateTimeField(default=timezone.now, verbose_name='initiated at')

    dst_node = models.ForeignKey('Registration', related_name='archive_jobs',
                                 verbose_name='destination node', null=True, blank=True)
    src_node = models.ForeignKey('Node', verbose_name='source node', null=True, blank=True)
    initiator = models.ForeignKey('OSFUser', null=True)

    target_addons = models.ManyToManyField('ArchiveTarget')

    def __repr__(self):
        return (
            '<{ClassName}(_id={self._id}, done={self.done}, '
            ' status={self.status}, src_node={self.src_node}, dst_node={self.dst_node})>'
{'fraction_non_alphanumeric': 0.10961458765022793, 'fraction_numerical': 0.004973062577704103, 'mean_word_length': 3.915478615071283, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6512193', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1428, 'n_words': 306}