Page MenuHomec4science

serializers.py
No OneTemporary

File Metadata

Created
Tue, May 7, 13:26

serializers.py

"""
This is the Open Access Check Tool (OACT).
The publication of scientific articles as Open Access (OA), usually in the variants "Green OA" and "Gold OA", allows free access to scientific research results and their largely unhindered dissemination. Often, however, the multitude of available publication conditions makes the decision in favor of a particular journal difficult: requirements of the funding agencies and publication guidelines of the universities and colleges must be carefully compared with the offers of the publishing houses, and separately concluded publication agreements can also offer additional benefits. The "OA Compliance Check Tool" provides a comprehensive overview of the possible publication conditions for a large number of journals, especially for the Swiss university landscape, and thus supports the decision-making process.
© All rights reserved. ECOLE POLYTECHNIQUE FEDERALE DE LAUSANNE, Switzerland, Scientific Information and Libraries, 2022
See LICENSE.TXT for more details.
This program 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, 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see
<https://www.gnu.org/licenses/>.
"""
""" REST API serializers
All serializers inherit from WritableNestedModelSerializer to allow writing nested objects
through the API as per https://github.com/beda-software/drf-writable-nested
and RQLMixin to support the Resource Query Language (RQL) https://django-rql.readthedocs.io/en/latest/
"""
from rest_framework import serializers
from dj_rql.drf.serializers import RQLMixin
from .models import *
from drf_writable_nested.serializers import WritableNestedModelSerializer
class CountrySerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for Countries
"""
id = serializers.IntegerField(required=False)
name = serializers.CharField(required=False)
iso_code = serializers.CharField(required=False)
class Meta:
model = Country
fields = '__all__'
depth = 4
class LanguageSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for Languages
"""
id = serializers.IntegerField(required=False)
name = serializers.CharField(required=False)
iso_code = serializers.CharField(required=False)
class Meta:
model = Language
fields = '__all__'
depth = 4
class PublisherSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for Publishers
"""
id = serializers.IntegerField(required=False)
country = CountrySerializer(required=False, many=True)
class Meta:
model = Publisher
fields = '__all__'
depth = 4
class OaSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for OA statuses
"""
id = serializers.IntegerField(required=False, allow_null=True)
description = serializers.CharField(required=False, allow_null=True)
subscription = serializers.BooleanField(required=False)
accepted_manuscript = serializers.BooleanField(required=False)
apc = serializers.BooleanField(required=False)
final_version = serializers.BooleanField(required=False)
class Meta:
model = Oa
fields = '__all__'
depth = 4
class IssnSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for ISSNs
"""
id = serializers.IntegerField(required=False)
class Meta:
model = Issn
fields = '__all__'
depth = 1
class JournalSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for Journals
"""
id = serializers.IntegerField(required=False)
issn = IssnSerializer(required=False, source='classIssn', many=True)
publisher = PublisherSerializer(required=False, many=True)
language = LanguageSerializer(required=False, many=True)
# allow update via post request --> "oa_status": {2},
# oa_status = serializers.PrimaryKeyRelatedField(queryset=Oa.objects.all())
oa_status = OaSerializer(required=False,allow_null=True)
class Meta:
model = Journal
fields = '__all__'
depth = 4
class LicenceSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for Licences
"""
id = serializers.IntegerField(required=False)
name_or_abbrev = serializers.CharField()
website = serializers.URLField(allow_null=True, required=False)
class Meta:
model = Licence
fields = '__all__'
depth = 4
class Cost_factor_typeSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for cost factor types
"""
id = serializers.IntegerField(required=False)
name = serializers.CharField()
class Meta:
model = Cost_factor_type
fields = '__all__'
depth = 4
class VersionSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for article versions
"""
id = serializers.IntegerField(required=False)
description = models.CharField()
class Meta:
model = Version
fields = '__all__'
depth = 4
class OrgaSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for organizations
"""
id = serializers.IntegerField(required=False)
country = CountrySerializer(required=False, many=True)
class Meta:
model = Organization
fields = '__all__'
depth = 4
class Cost_factorSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for cost factors
"""
id = serializers.IntegerField(required=False)
cost_factor_type = Cost_factor_typeSerializer(required=False, allow_null=True)
amount = serializers.IntegerField()
symbol = serializers.CharField()
comment = serializers.CharField(required=False)
class Meta:
model = Cost_factor
fields = '__all__'
depth = 4
class Cost_factorLightSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for cost factors
"""
id = serializers.IntegerField(required=False)
cost_factor_type = serializers.PrimaryKeyRelatedField(queryset=Cost_factor_type.objects.all())
amount = serializers.IntegerField()
symbol = serializers.CharField()
comment = serializers.CharField(required=False)
class Meta:
model = Cost_factor
fields = '__all__'
depth = 4
class TermSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for terms
"""
id = serializers.IntegerField(required=False)
version = VersionSerializer(required=False, many=True)
cost_factor = Cost_factorSerializer(required=False, many=True)
licence = LicenceSerializer(required=False, many=True)
class Meta:
model = Term
fields = '__all__'
depth = 4
class TermLightSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for terms in writing mode, using IDs for relationships
"""
id = serializers.IntegerField(required=False)
version = serializers.PrimaryKeyRelatedField(queryset=Version.objects.all(), many=True)
cost_factor = serializers.PrimaryKeyRelatedField(queryset=Cost_factor.objects.all(), many=True)
licence = serializers.PrimaryKeyRelatedField(queryset=Licence.objects.all(), many=True)
class Meta:
model = Term
fields = '__all__'
depth = 4
class ConditionTypeSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for condition types
"""
id = serializers.IntegerField(required=False)
condition_issuer = serializers.CharField()
class Meta:
model = ConditionType
fields = '__all__'
depth = 4
class ConditionSubTypeSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for condition subtypes
"""
id = serializers.IntegerField(required=False)
label = serializers.CharField()
class Meta:
model = ConditionSubType
fields = '__all__'
depth = 4
class ConditionSetSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for condition sets
"""
id = serializers.IntegerField(required=False)
term = TermSerializer(many=True, read_only=False)
condition_type = ConditionTypeSerializer(read_only=False)
subtype = ConditionSubTypeSerializer(read_only=False)
organization = OrgaSerializer(many=True, read_only=False)
journal = JournalSerializer(many=True, read_only=False)
comment = serializers.CharField(read_only=False)
source = serializers.URLField(read_only=False, allow_blank=True, allow_null=True, required=False)
class Meta:
model = ConditionSet
# pre filter for rql
# fields = ['id','condition_type','term','journal','organization']
# add for informations purpose
fields = '__all__'
depth = 4
class JournalIdSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API light-weight serializer for journals, using only the ID.
Used by the frontend when building the query
"""
id = serializers.IntegerField(required=False, read_only=False)
# allow update via post request --> "oa_status": {2},
class Meta:
model = Journal
fields = ['id']
class OrganizationIdSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API light-weight serializer for organizations, using only the ID.
For use in other serializers
"""
id = serializers.IntegerField(required=False, read_only=False)
# allow update via post request --> "oa_status": {2},
class Meta:
model = Organization
fields = ['id']
class ConditionSetIdSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API light-weight serializer for condition sets, using only the ID.
For use in other serializers
"""
id = serializers.IntegerField(required=False, read_only=False)
# allow update via post request --> "oa_status": {2},
class Meta:
model = ConditionSet
fields = ['id']
class ConditionSetLightSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for condition sets, providing only the information
needed in the frontend to improve performance
"""
id = serializers.IntegerField(required=False)
term = TermSerializer(many=True, read_only=False)
condition_type = ConditionTypeSerializer(read_only=False)
subtype = ConditionSubTypeSerializer(read_only=False)
organization = OrgaSerializer(many=True, read_only=False)
# No journals in this one.
journal = JournalIdSerializer(many=True, read_only=False)
comment = serializers.CharField(read_only=False)
source = serializers.URLField(read_only=False, allow_blank=True, allow_null=True, required=False)
class Meta:
model = ConditionSet
# pre filter for rql
# fields = ['id','condition_type','term','journal','organization']
# add for informations purpose
fields = ['id', 'condition_type', 'subtype', 'term', 'organization', 'journal', 'comment', 'source']
depth = 4
class ConditionSetMiniSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializer for condition sets, providing only the information
needed in the frontend to improve performance
"""
id = serializers.IntegerField(required=False)
term = serializers.PrimaryKeyRelatedField(queryset=Term.objects.all(), many=True)
condition_type = serializers.PrimaryKeyRelatedField(queryset=ConditionType.objects.all())
subtype = serializers.PrimaryKeyRelatedField(queryset=ConditionSubType.objects.all())
organization = serializers.PrimaryKeyRelatedField(queryset=Organization.objects.all(), many=True)
# No journals in this one.
journal = serializers.PrimaryKeyRelatedField(queryset=Journal.objects.all(), many=True)
comment = serializers.CharField(read_only=False)
source = serializers.URLField(read_only=False, allow_blank=True, allow_null=True, required=False)
class Meta:
model = ConditionSet
# pre filter for rql
# fields = ['id','condition_type','term','journal','organization']
# add for informations purpose
fields = ['id', 'condition_type', 'subtype', 'term', 'organization', 'journal', 'comment', 'source']
depth = 4
class JournalLightSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API lighter serializer for journals
"""
id = serializers.IntegerField(required=False)
# allow update via post request --> "oa_status": {2},
oa_status = serializers.PrimaryKeyRelatedField(queryset=Oa.objects.all())
language = serializers.PrimaryKeyRelatedField(queryset=Language.objects.all(), many=True)
publisher = serializers.PrimaryKeyRelatedField(queryset=Publisher.objects.all(), many=True)
starting_year = serializers.IntegerField(required=False)
end_year = serializers.IntegerField(required=False)
class Meta:
model = Journal
fields = ['id', 'name', 'oa_status', 'language', 'publisher', 'starting_year', 'end_year']
depth = 1
class OaSerializer(WritableNestedModelSerializer,RQLMixin):
""" REST API serializers for OA statuses
"""
id = serializers.IntegerField(required=False)
status = serializers.CharField(allow_null=True)
description = serializers.CharField(allow_null=True)
subscription = serializers.BooleanField(required=False)
accepted_manuscript = serializers.BooleanField(required=False)
apc = serializers.BooleanField(required=False)
final_version = serializers.BooleanField(required=False)
class Meta:
model = Oa
fields = '__all__'
depth = 4
class OrganizationConditionSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializers for Organisation-condition connections
"""
id = serializers.IntegerField(required=False)
organization = OrgaSerializer(required=False)
condition_set = ConditionSetSerializer(required=False)
class Meta:
model = OrganizationCondition
fields = '__all__'
depth = 4
class OrganizationConditionBasicSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializers for Organisation-condition connections
"""
id = serializers.IntegerField(required=False, read_only=False)
organization = serializers.PrimaryKeyRelatedField(queryset=Organization.objects.all(), read_only=False)
condition_set = serializers.PrimaryKeyRelatedField(queryset=ConditionSet.objects.all(), read_only=False)
valid_from = serializers.DateField(required=False, read_only=False)
valid_until = serializers.DateField(required=False, read_only=False)
class Meta:
model = OrganizationCondition
fields = '__all__'
depth = 1
class JournalConditionSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializers for Journal-condition connections
"""
id = serializers.IntegerField(required=False)
journal = JournalSerializer(required=False)
condition_set = ConditionSetSerializer(required=False)
class Meta:
model = JournalCondition
fields = '__all__'
depth = 4
class JournalConditionBasicSerializer(WritableNestedModelSerializer, RQLMixin):
""" REST API serializers for minimal Journal-condition connections
"""
id = serializers.IntegerField(required=False, read_only=False)
journal = serializers.PrimaryKeyRelatedField(queryset=Journal.objects.all(), read_only=False)
condition_set = serializers.PrimaryKeyRelatedField(queryset=ConditionSet.objects.all(), read_only=False)
valid_from = serializers.DateField(required=False, read_only=False)
valid_until = serializers.DateField(required=False, read_only=False)
class Meta:
model = JournalCondition
fields = '__all__'
depth = 1

Event Timeline