<commit_before>from django.template.defaultfilters import filesizeformat

from rest_framework import serializers

from mkt.webapps.serializers import SimpleAppSerializer, SimpleESAppSerializer
from mkt.websites.serializers import ESWebsiteSerializer, WebsiteSerializer


class BaseFireplaceAppSerializer(object):
    def get_icons(self, app):
        # Fireplace only requires 64px and 128px icons.
        return {
            64: app.get_icon_url(64),
            128: app.get_icon_url(128)
        }

    # We don't care about the integer value of the file size in fireplace, we
    # just want to display it to the user in a human-readable way.
    def to_representation(self, obj):
        data = super(BaseFireplaceAppSerializer, self).to_representation(obj)
        if obj.file_size:
            data['file_size'] = filesizeformat(obj.file_size)
        else:
            data['file_size'] = None
        return data


class FireplaceAppSerializer(BaseFireplaceAppSerializer, SimpleAppSerializer):

    class Meta(SimpleAppSerializer.Meta):
        fields = ['author', 'categories', 'content_ratings', 'current_version',
                  'description', 'device_types', 'feature_compatibility',
                  'file_size', 'homepage', 'icons', 'id',
                  'is_offline', 'is_packaged', 'last_updated', 'manifest_url',
                  'name', 'payment_required', 'premium_type', 'previews',
                  'price', 'price_locale', 'privacy_policy', 'promo_imgs',
                  'public_stats', 'release_notes', 'ratings', 'slug', 'status',
                  'support_email', 'support_url', 'tags', 'upsell', 'user']
        exclude = []
<commit_msg>leave size formatting for client side (bug 1225144)<commit_after>from django.template.defaultfilters import filesizeformat

from rest_framework import serializers

from mkt.webapps.serializers import SimpleAppSerializer, SimpleESAppSerializer
from mkt.websites.serializers import ESWebsiteSerializer, WebsiteSerializer


class BaseFireplaceAppSerializer(object):
    def get_icons(self, app):
        # Fireplace only requires 64px and 128px icons.
        return {
            64: app.get_icon_url(64),
            128: app.get_icon_url(128)
        }


class FireplaceAppSerializer(BaseFireplaceAppSerializer, SimpleAppSerializer):

    class Meta(SimpleAppSerializer.Meta):
        fields = ['author', 'categories', 'content_ratings', 'current_version',
                  'description', 'device_types', 'feature_compatibility',
                  'file_size', 'homepage', 'icons', 'id',
                  'is_offline', 'is_packaged', 'last_updated', 'manifest_url',
                  'name', 'payment_required', 'premium_type', 'previews',
                  'price', 'price_locale', 'privacy_policy', 'promo_imgs',
                  'public_stats', 'release_notes', 'ratings', 'slug', 'status',
                  'support_email', 'support_url', 'tags', 'upsell', 'user']
        exclude = []

{'fraction_non_alphanumeric': 0.10804442948502188, 'fraction_numerical': 0.012453719286435544, 'mean_word_length': 3.1277777777777778, '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': '7631870', 'n_tokens_mistral': 862, 'n_tokens_neox': 802, 'n_words': 198}