<commit_before>"""Defines the serializers for products"""
from __future__ import unicode_literals

import rest_framework.fields as fields
import rest_framework.serializers as serializers

from storage.serializers import ScaleFileBaseSerializer
from util.rest import ModelIdSerializer


class ProductFileBaseSerializer(ScaleFileBaseSerializer):
    """Converts product file model fields to REST output"""
    is_operational = serializers.BooleanField()
    is_published = serializers.BooleanField()
    has_been_published = serializers.BooleanField()

    published = serializers.DateTimeField()
    unpublished = serializers.DateTimeField()

    job_type = ModelIdSerializer()
    job = ModelIdSerializer()
    job_exe = ModelIdSerializer()


class ProductFileSerializer(ProductFileBaseSerializer):
    """Converts product file model fields to REST output"""
    from job.serializers import JobTypeBaseSerializer

    job_type = JobTypeBaseSerializer()


class ProductFileDetailsSerializer(ProductFileSerializer):
    """Converts product file model fields to REST output"""
    from source.serializers import SourceFileSerializer

    sources = SourceFileSerializer(many=True)
    ancestors = ProductFileSerializer(many=True, source='ancestor_products')
    descendants = ProductFileSerializer(many=True, source='descendant_products')


class ProductFileUpdateField(fields.Field):
    """Field for displaying the update information for a product file"""

    type_name = 'UpdateField'
    type_label = 'update'

    def to_representation(self, value):
        """Converts the model to its update information

        :param value: the product file model
        :type value: :class:`product.models.ProductFile`
        :rtype: dict
        :returns: the dict with the update information
        """

        if value.is_deleted:
            action = 'DELETED'
            when = value.deleted
        elif value.is_published:
            action = 'PUBLISHED'
            when = value.published
        else:
            action = 'UNPUBLISHED'
            when = value.unpublished

        return {'action': action, 'when': when}


class ProductFileUpdateSerializer(ProductFileSerializer):
    """Converts product file updates to REST output"""
    from source.serializers import SourceFileBaseSerializer

    update = ProductFileUpdateField(source='*')
    source_files = SourceFileBaseSerializer(many=True)
<commit_msg>Added supererdeded ScaleFile fields to BaseSerializer<commit_after>"""Defines the serializers for products"""
from __future__ import unicode_literals

import rest_framework.fields as fields
import rest_framework.serializers as serializers

from storage.serializers import ScaleFileBaseSerializer
from util.rest import ModelIdSerializer


class ProductFileBaseSerializer(ScaleFileBaseSerializer):
    """Converts product file model fields to REST output"""
    is_operational = serializers.BooleanField()
    is_published = serializers.BooleanField()
    has_been_published = serializers.BooleanField()

    published = serializers.DateTimeField()
    unpublished = serializers.DateTimeField()

    is_superseded = serializers.BooleanField()
    superseded = serializers.DateTimeField()

    job_type = ModelIdSerializer()
    job = ModelIdSerializer()
    job_exe = ModelIdSerializer()


class ProductFileSerializer(ProductFileBaseSerializer):
    """Converts product file model fields to REST output"""
    from job.serializers import JobTypeBaseSerializer

    job_type = JobTypeBaseSerializer()


class ProductFileDetailsSerializer(ProductFileSerializer):
    """Converts product file model fields to REST output"""
    from source.serializers import SourceFileSerializer

    sources = SourceFileSerializer(many=True)
    ancestors = ProductFileSerializer(many=True, source='ancestor_products')
    descendants = ProductFileSerializer(many=True, source='descendant_products')


class ProductFileUpdateField(fields.Field):
    """Field for displaying the update information for a product file"""

    type_name = 'UpdateField'
    type_label = 'update'

    def to_representation(self, value):
        """Converts the model to its update information

        :param value: the product file model
        :type value: :class:`product.models.ProductFile`
        :rtype: dict
        :returns: the dict with the update information
        """

        if value.is_deleted:
            action = 'DELETED'
            when = value.deleted
        elif value.is_published:
            action = 'PUBLISHED'
            when = value.published
        else:
            action = 'UNPUBLISHED'
            when = value.unpublished

        return {'action': action, 'when': when}


class ProductFileUpdateSerializer(ProductFileSerializer):
    """Converts product file updates to REST output"""
    from source.serializers import SourceFileBaseSerializer

    update = ProductFileUpdateField(source='*')
    source_files = SourceFileBaseSerializer(many=True)

{'fraction_non_alphanumeric': 0.07560828473758295, 'fraction_numerical': 0.0, 'mean_word_length': 3.969030969030969, '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': '333519', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1207, 'n_words': 353}