Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
oser-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hamza Touizrat
oser-backend
Commits
0f823788
Commit
0f823788
authored
7 years ago
by
florimondmanca
Browse files
Options
Downloads
Patches
Plain Diff
add edition form endpoint, add participation entry endpoint
parent
95f6ba86
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
projects/views.py
+52
-4
52 additions, 4 deletions
projects/views.py
with
52 additions
and
4 deletions
projects/views.py
+
52
−
4
View file @
0f823788
"""
Projects views.
"""
from
django.shortcuts
import
redirect
from
django.utils.timezone
import
now
from
rest_framework
import
mixins
,
permissions
,
viewsets
from
rest_framework.response
import
Response
from
rest_framework.decorators
import
action
from
django.core.exceptions
import
ObjectDoesNotExist
from
django_filters
import
rest_framework
as
filters
from
django_filters.rest_framework.backends
import
DjangoFilterBackend
from
rest_framework
import
mixins
,
permissions
,
viewsets
,
status
from
rest_framework.decorators
import
action
from
rest_framework.response
import
Response
from
d
jango_filters
import
rest_framework
as
filt
er
s
from
d
ynamicforms.serializers
import
FormEntrySerializ
er
from
.models
import
Edition
,
Participation
,
Project
from
.serializers
import
(
EditionDetailSerializer
,
EditionListSerializer
,
...
...
@@ -263,6 +266,26 @@ class EditionViewSet(viewsets.ReadOnlyModelViewSet):
serializer
=
self
.
get_serializer
(
queryset
,
many
=
True
)
return
Response
(
serializer
.
data
)
@action
(
methods
=
[
'
get
'
],
detail
=
True
)
def
form
(
self
,
request
,
pk
=
None
):
"""
Return the edition
'
s form.
If the edition does not have a form,
returns a `404 Not Found` error response.
### Example response
See [forms: read](#forms-read).
"""
edition
=
self
.
get_object
()
try
:
form
=
edition
.
edition_form
.
form
except
ObjectDoesNotExist
:
return
Response
(
{
'
detail
'
:
'
No form set on this edition.
'
},
status
=
404
)
else
:
return
redirect
(
'
api:form-detail
'
,
str
(
form
.
pk
))
class
ParticipationViewSet
(
mixins
.
CreateModelMixin
,
viewsets
.
ReadOnlyModelViewSet
):
...
...
@@ -326,3 +349,28 @@ class ParticipationViewSet(mixins.CreateModelMixin,
permission_classes
=
(
permissions
.
IsAuthenticated
,)
filter_backends
=
(
DjangoFilterBackend
,)
filter_fields
=
(
'
user
'
,
'
state
'
,)
@action
(
methods
=
[
'
get
'
],
detail
=
True
)
def
form_entry
(
self
,
request
,
pk
=
None
):
"""
Return the answers to the edition form for a participation.
### Example response
{
"
id
"
: 20,
"
form
"
: 4,
"
submitted
"
:
"
2018-06-30T09:43:28.779628+02:00
"
,
"
answers
"
: [
{
"
id
"
: 79,
"
question
"
: 40,
"
entry
"
: 20,
"
answer
"
:
"
Florimond
"
}
]
}
"""
participation
=
self
.
get_object
()
serializer
=
FormEntrySerializer
(
participation
.
entry
)
data
=
serializer
.
data
return
Response
(
data
,
status
=
status
.
HTTP_200_OK
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment