Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90885880
views.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
Tue, Nov 5, 16:13
Size
6 KB
Mime Type
text/x-python
Expires
Thu, Nov 7, 16:13 (2 d)
Engine
blob
Format
Raw Data
Handle
22152755
Attached To
rOACCT Open Access Compliance Check Tool (OACCT)
views.py
View Options
from
django.contrib.auth.models
import
AbstractUser
from
django.shortcuts
import
render
from
django.contrib.auth
import
authenticate
,
login
,
logout
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
Http404
,
JsonResponse
from
.models
import
*
from
.serializers
import
*
from
rest_framework
import
viewsets
,
filters
,
generics
from
rest_framework.authentication
import
BasicAuthentication
from
rest_framework.permissions
import
IsAuthenticatedOrReadOnly
from
rest_framework
import
status
from
rest_framework.decorators
import
api_view
from
rest_framework.response
import
Response
from
itertools
import
chain
from
django.db.models
import
Count
from
dj_rql.filter_cls
import
RQLFilterClass
from
urllib.parse
import
unquote
class
JournalViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
search_fields
=
[
'name'
]
filter_backends
=
(
filters
.
SearchFilter
,)
queryset
=
Journal
.
objects
.
all
()
serializer_class
=
JournalSerializer
class
OrgaViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
OrgaSerializer
queryset
=
Organization
.
objects
.
filter
(
is_funder
=
False
)
class
ConditionSetFilters
(
RQLFilterClass
):
#Frontend api request:
# http://127.0.0.1:8000/api/conditionset/?and(eq(journal.id,3);eq(organization.id,11);eq(condition_type.id,3))
MODEL
=
ConditionSet
FILTERS
=
(
'id'
,
{
'namespace'
:
'journal'
,
'filters'
:
[
'id'
,],
},
{
'namespace'
:
'organization'
,
'filters'
:
[
'id'
,],
},
{
'namespace'
:
'condition_type'
,
'filters'
:
[
'id'
,],
},
)
class
ConditionSetViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
queryset
=
ConditionSet
.
objects
.
all
()
# queryset = ConditionSet.objects.values('term__version__description')
serializer_class
=
ConditionSetSerializer
# serializer_class = ConditionGroupedSerializer
rql_filter_class
=
ConditionSetFilters
#.objects.values('term__version.description')
class
FunderViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
OrgaSerializer
queryset
=
Organization
.
objects
.
filter
(
is_funder
=
True
)
class
TermViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
TermSerializer
queryset
=
Term
.
objects
.
all
()
class
CountryViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
CountrySerializer
queryset
=
Country
.
objects
.
all
()
class
LanguageViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
LanguageSerializer
queryset
=
Language
.
objects
.
all
()
class
IssnViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
IssnSerializer
queryset
=
Issn
.
objects
.
all
()
class
OaViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
OaSerializer
queryset
=
Oa
.
objects
.
all
()
class
PublisherViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
PublisherSerializer
queryset
=
Publisher
.
objects
.
all
()
class
VersionViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
VersionSerializer
queryset
=
Version
.
objects
.
all
()
class
LicenceViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
LicenceSerializer
queryset
=
Licence
.
objects
.
all
()
class
Cost_factor_typeViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
Cost_factor_typeSerializer
queryset
=
Cost_factor_type
.
objects
.
all
()
class
Cost_factorViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
Cost_factorSerializer
queryset
=
Cost_factor
.
objects
.
all
()
class
ConditionTypeViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
ConditionTypeSerializer
queryset
=
ConditionType
.
objects
.
all
()
class
OrganizationConditionViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
OrganizationConditionSerializer
queryset
=
OrganizationCondition
.
objects
.
all
()
class
JournalConditionViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
JournalConditionSerializer
queryset
=
JournalCondition
.
objects
.
all
()
class
OrganizationConditionViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
OrganizationConditionSerializer
queryset
=
OrganizationCondition
.
objects
.
all
()
# Count number of different version
# OrganizationCondition.objects.annotate(version_count=Count('condition_set__term__version'))
# OrganizationCondition.objects
# .values('condition_set__term__version') #what to group by
# .annotate(version_count=Count('condition_set__term__version')) # what to aggregate
# group by version and count
# OrganizationCondition.objects.values('condition_set__term__version').annotate(version_count=Count('condition_set__term__version'))
# source https://hakibenita.com/django-group-by-sql
# https://docs.djangoproject.com/en/3.2/topics/db/aggregation/
# OrganizationCondition.objects.values('condition_set__term__version').filter(organization_id=1).annotate(version_count=Count('condition_set__term__version'))
Event Timeline
Log In to Comment