Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F79490951
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
Mon, Aug 26, 16:30
Size
6 KB
Mime Type
text/x-python
Expires
Wed, Aug 28, 16:30 (2 d)
Engine
blob
Format
Raw Data
Handle
20195321
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
Journal
,
Institution
,
OrganizationCondition
,
JournalCondition
,
ConditionSet
,
Institution
from
rest_framework
import
status
from
rest_framework.response
import
Response
from
.serializers
import
JournalSerializer
,
InstitSerializer
,
OrganizationConditionSerializer
,
JournalConditionSerializer
,
ConditionSetSerializer
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
#, RQL_NULL
# from dj_rql.constants import FilterLookups
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
InstitViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
InstitSerializer
queryset
=
Institution
.
objects
.
filter
(
is_funder
=
False
)
class
OrgaCondiFilters
(
RQLFilterClass
):
#Frontend api request:
# http://127.0.0.1:8000/api/organizationcondition/?and(eq(organization.id,1),eq(condition_set.condition_type.id,2))
MODEL
=
OrganizationCondition
FILTERS
=
(
'id'
,
{
'namespace'
:
'organization'
,
'filters'
:
[
'id'
,],
},
{
'namespace'
:
'condition_set'
,
'filters'
:
[
'id'
,
{
'namespace'
:
'condition_type'
,
'filters'
:
[
'id'
,],},
{
'namespace'
:
'term'
,
'filters'
:
[
'id'
,
{
'namespace'
:
'version'
,
'filters'
:
[
'description'
,],
}
],
'ordering'
:
True
,
},
],
},
)
class
JournalCondiFilters
(
RQLFilterClass
):
#Frontend api request:
# http://127.0.0.1:8000/api/journalcondition/?and(eq(journal.id,1),eq(condition_set.condition_type.id,1))
MODEL
=
JournalCondition
FILTERS
=
(
'id'
,
{
'namespace'
:
'journal'
,
'filters'
:
[
'id'
,],
},
{
'namespace'
:
'condition_set'
,
'filters'
:
[
'id'
,
{
'namespace'
:
'condition_type'
,
'filters'
:
[
'id'
,],},
{
'namespace'
:
'term'
,
'filters'
:
[
'id'
,
{
'namespace'
:
'version'
,
'filters'
:
[
'description'
,],
}
],
'ordering'
:
True
,
},
],
},
)
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
OrganizationConditionViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
OrganizationConditionSerializer
queryset
=
OrganizationCondition
.
objects
.
all
()
rql_filter_class
=
OrgaCondiFilters
class
JournalConditionViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
JournalConditionSerializer
queryset
=
JournalCondition
.
objects
.
all
()
rql_filter_class
=
JournalCondiFilters
class
ConditionSetViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
queryset
=
ConditionSet
.
objects
.
all
()
serializer_class
=
ConditionSetSerializer
rql_filter_class
=
ConditionSetFilters
class
FunderViewSet
(
viewsets
.
ModelViewSet
):
authentification_classes
=
(
BasicAuthentication
,)
permission_classes
=
[
IsAuthenticatedOrReadOnly
]
serializer_class
=
InstitSerializer
queryset
=
Institution
.
objects
.
filter
(
is_funder
=
True
)
# 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