<commit_before># Copyright 2013,2014 Music Technology Group - Universitat Pompeu Fabra
#
# This file is part of Dunya
#
# Dunya is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free Software
# Foundation (FSF), either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see http://www.gnu.org/licenses/

from makam import models
import docserver.models
from data.models import WithImageMixin
from django.db.models import Q
from data import utils

from rest_framework import generics
from rest_framework import serializers
from django.shortcuts import redirect
from django.http import Http404
from django.core.exceptions import ObjectDoesNotExist

class ArtistInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Artist
        fields = ['mbid', 'name']

class ComposerInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Composer
        fields = ['mbid', 'name']

class WorkInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Work
        fields = ['mbid', 'title']

class ReleaseRecordingInnerSerializer(serializers.ModelSerializer):
    mbid = serializers.ReadOnlyField(source='recording.mbid')
    title = serializers.ReadOnlyField(source='recording.title')
    class Meta:
        model = models.ReleaseRecording
        fields = ['mbid', 'title', 'track']

class RecordingInnerSerializer(serializers.ModelSerializer):
    artists = serializers.SerializerMethodField('artists_list')

    class Meta:
        model = models.Recording
        fields = ['mbid', 'title', 'artists']

    def artists_list(self, ob):
        artists = [perf.artist for perf in ob.instrumentperformance_set.all()]
        for a in ob.artists.all():
            artists.append(a)
        return ArtistInnerSerializer(artists, many=True).data

class FormInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Form
        fields = ['uuid', 'name']

class UsulInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Usul
        fields = ['uuid', 'name']

class MakamInnerSerializer(serializers.ModelSerializer):
    class Meta:<commit_msg>Fix bug on API of releses, gets artists from performance<commit_after># Copyright 2013,2014 Music Technology Group - Universitat Pompeu Fabra
#
# This file is part of Dunya
#
# Dunya is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free Software
# Foundation (FSF), either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see http://www.gnu.org/licenses/

from makam import models
import docserver.models
from data.models import WithImageMixin
from django.db.models import Q
from data import utils

from rest_framework import generics
from rest_framework import serializers
from django.shortcuts import redirect
from django.http import Http404
from django.core.exceptions import ObjectDoesNotExist

class ArtistInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Artist
        fields = ['mbid', 'name']

class ComposerInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Composer
        fields = ['mbid', 'name']

class WorkInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Work
        fields = ['mbid', 'title']

class ReleaseRecordingInnerSerializer(serializers.ModelSerializer):
    mbid = serializers.ReadOnlyField(source='recording.mbid')
    title = serializers.ReadOnlyField(source='recording.title')
    class Meta:
        model = models.ReleaseRecording
        fields = ['mbid', 'title', 'track']

class RecordingInnerSerializer(serializers.ModelSerializer):
    artists = serializers.SerializerMethodField('artists_list')

    class Meta:
        model = models.Recording
        fields = ['mbid', 'title', 'artists']

    def artists_list(self, ob):
        artists = []
        if hasattr(ob, 'instrumentperformance_set'):
            artists = [perf.artist for perf in ob.instrumentperformance_set.all()]
        for a in ob.artists.all():
            artists.append(a)
        return ArtistInnerSerializer(artists, many=True).data

class FormInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Form
        fields = ['uuid', 'name']

class UsulInnerSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Usul
        fields = ['uuid', 'name']

class MakamInnerSerializer(serializers.ModelSerializer):
    class Meta:
{'fraction_non_alphanumeric': 0.08111627906976744, 'fraction_numerical': 0.004465116279069767, 'mean_word_length': 3.869565217391304, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6558055', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1403, 'n_words': 502}