Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90362142
serializers.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Oct 31, 23:42
Size
9 KB
Mime Type
text/x-python
Expires
Sat, Nov 2, 23:42 (2 d)
Engine
blob
Format
Raw Data
Handle
22062271
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
serializers.py
View Options
""" 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
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
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
)
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
)
# allow update via post request --> "oa_status": {2},
class
Meta
:
model
=
Journal
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
)
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
(
serializers
.
ModelSerializer
,
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
JournalConditionSerializer
(
serializers
.
ModelSerializer
,
RQLMixin
):
""" REST API serializers for Organisation-condition connections
"""
id
=
serializers
.
IntegerField
(
required
=
False
)
journal
=
JournalSerializer
(
required
=
False
)
condition_set
=
ConditionSetSerializer
(
required
=
False
)
class
Meta
:
model
=
JournalCondition
fields
=
'__all__'
depth
=
4
Event Timeline
Log In to Comment