<commit_before># -*- coding: utf-8 -*-

"""Akvo RSR is covered by the GNU Affero General Public License.
See more details in the license.txt file located at the root folder of the
Akvo RSR module. For additional details on the GNU license please
see < http://www.gnu.org/licenses/agpl.html >.
"""

from rest_framework import serializers

from akvo.codelists.models import Country
from akvo.codelists.store.codelists_v202 import SECTOR_CATEGORY
from akvo.rsr.models import Keyword, Organisation, Project, ProjectUpdate, Sector
from akvo.utils import codelist_choices


class TypeaheadCountrySerializer(serializers.ModelSerializer):

    class Meta:
        model = Country
        fields = ('code', 'name')


class TypeaheadOrganisationSerializer(serializers.ModelSerializer):

    class Meta:
        model = Organisation
        fields = ('id', 'name', 'long_name')


class TypeaheadProjectSerializer(serializers.ModelSerializer):

    class Meta:
        model = Project
        fields = ('id', 'title', 'subtitle')


class TypeaheadProjectUpdateSerializer(serializers.ModelSerializer):

    class Meta:
        model = ProjectUpdate
        fields = ('id', 'project', 'title')


class TypeaheadKeywordSerializer(serializers.ModelSerializer):

    class Meta:
        model = Keyword
        fields = ('id', 'label')


class TypeaheadSectorSerializer(serializers.ModelSerializer):

    id = serializers.SerializerMethodField()
    name = serializers.SerializerMethodField()

    # Lookup attribute for sector names. Not a serialized attribute.
    sectors = dict(codelist_choices(SECTOR_CATEGORY))

    def get_id(self, obj):
        return obj['sector_code']

    def get_name(self, obj):
        return self.sectors[obj['sector_code']]

    class Meta:
        model = Sector
        fields = ('id', 'name')<commit_msg>[#3126] Hide code numbers for sector<commit_after># -*- coding: utf-8 -*-

"""Akvo RSR is covered by the GNU Affero General Public License.
See more details in the license.txt file located at the root folder of the
Akvo RSR module. For additional details on the GNU license please
see < http://www.gnu.org/licenses/agpl.html >.
"""

from rest_framework import serializers

from akvo.codelists.models import Country
from akvo.codelists.store.codelists_v202 import SECTOR_CATEGORY
from akvo.rsr.models import Keyword, Organisation, Project, ProjectUpdate, Sector
from akvo.utils import codelist_choices


class TypeaheadCountrySerializer(serializers.ModelSerializer):

    class Meta:
        model = Country
        fields = ('code', 'name')


class TypeaheadOrganisationSerializer(serializers.ModelSerializer):

    class Meta:
        model = Organisation
        fields = ('id', 'name', 'long_name')


class TypeaheadProjectSerializer(serializers.ModelSerializer):

    class Meta:
        model = Project
        fields = ('id', 'title', 'subtitle')


class TypeaheadProjectUpdateSerializer(serializers.ModelSerializer):

    class Meta:
        model = ProjectUpdate
        fields = ('id', 'project', 'title')


class TypeaheadKeywordSerializer(serializers.ModelSerializer):

    class Meta:
        model = Keyword
        fields = ('id', 'label')


class TypeaheadSectorSerializer(serializers.ModelSerializer):

    id = serializers.SerializerMethodField()
    name = serializers.SerializerMethodField()

    # Lookup attribute for sector names. Not a serialized attribute.
    sectors = dict(codelist_choices(SECTOR_CATEGORY, show_code=False))

    def get_id(self, obj):
        return obj['sector_code']

    def get_name(self, obj):
        return self.sectors[obj['sector_code']]

    class Meta:
        model = Sector
        fields = ('id', 'name')
{'fraction_non_alphanumeric': 0.0946825827455236, 'fraction_numerical': 0.0032555615843733042, 'mean_word_length': 3.7208706786171577, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7569059', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1000, 'n_words': 299}