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
7178c5f3
Commit
7178c5f3
authored
Jun 30, 2018
by
florimondmanca
Browse files
Options
Downloads
Patches
Plain Diff
add edition documents endpoint
parent
4242721e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
projects/serializers.py
+14
-1
14 additions, 1 deletion
projects/serializers.py
projects/views.py
+60
-6
60 additions, 6 deletions
projects/views.py
with
74 additions
and
7 deletions
projects/serializers.py
+
14
−
1
View file @
7178c5f3
...
@@ -4,7 +4,8 @@ from django.db import transaction
...
@@ -4,7 +4,8 @@ from django.db import transaction
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
core.fields
import
MarkdownField
from
core.fields
import
MarkdownField
from
dynamicforms.serializers
import
FormDetailSerializer
,
FormEntrySerializer
from
dynamicforms.serializers
import
(
FileSerializer
,
FormDetailSerializer
,
FormEntrySerializer
)
from
profiles.serializers
import
TutorSerializer
from
profiles.serializers
import
TutorSerializer
from
users.fields
import
UserField
from
users.fields
import
UserField
from
users.serializers
import
UserSerializer
from
users.serializers
import
UserSerializer
...
@@ -144,6 +145,18 @@ class EditionDetailSerializer(EditionListSerializer):
...
@@ -144,6 +145,18 @@ class EditionDetailSerializer(EditionListSerializer):
edition_form
=
EditionFormDetailSerializer
()
edition_form
=
EditionFormDetailSerializer
()
class
EditionDocumentsSerializer
(
serializers
.
ModelSerializer
):
"""
Serializer for information about an edition form
'
s documents.
"""
recipient
=
TutorSerializer
(
source
=
'
edition_form.recipient
'
)
deadline
=
serializers
.
DateField
(
source
=
'
edition_form.deadline
'
)
files
=
FileSerializer
(
many
=
True
,
source
=
'
edition_form.form.files
'
)
class
Meta
:
# noqa
model
=
Edition
fields
=
(
'
recipient
'
,
'
deadline
'
,
'
files
'
)
class
ProjectDetailSerializer
(
ProjectSerializer
):
class
ProjectDetailSerializer
(
ProjectSerializer
):
"""
Detail serializer for project objects.
"""
"""
Detail serializer for project objects.
"""
...
...
This diff is collapsed.
Click to expand it.
projects/views.py
+
60
−
6
View file @
7178c5f3
"""
Projects views.
"""
"""
Projects views.
"""
from
django.core.exceptions
import
ObjectDoesNotExist
from
django.shortcuts
import
redirect
from
django.shortcuts
import
redirect
from
django.utils.timezone
import
now
from
django.utils.timezone
import
now
from
django.core.exceptions
import
ObjectDoesNotExist
from
django_filters
import
rest_framework
as
filters
from
django_filters
import
rest_framework
as
filters
from
django_filters.rest_framework.backends
import
DjangoFilterBackend
from
django_filters.rest_framework.backends
import
DjangoFilterBackend
from
rest_framework
import
mixins
,
permissions
,
viewsets
,
statu
s
from
rest_framework
import
mixins
,
permissions
,
status
,
viewset
s
from
rest_framework.decorators
import
action
from
rest_framework.decorators
import
action
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
...
@@ -14,7 +14,7 @@ from dynamicforms.serializers import FormEntrySerializer
...
@@ -14,7 +14,7 @@ from dynamicforms.serializers import FormEntrySerializer
from
.models
import
Edition
,
Participation
,
Project
from
.models
import
Edition
,
Participation
,
Project
from
.serializers
import
(
EditionDetailSerializer
,
EditionListSerializer
,
from
.serializers
import
(
EditionDetailSerializer
,
EditionListSerializer
,
ParticipationSerializer
,
ProjectDetailSerializer
,
ParticipationSerializer
,
ProjectDetailSerializer
,
ProjectSerializer
)
ProjectSerializer
,
EditionDocumentsSerializer
)
class
ProjectViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
class
ProjectViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
...
@@ -268,7 +268,7 @@ class EditionViewSet(viewsets.ReadOnlyModelViewSet):
...
@@ -268,7 +268,7 @@ class EditionViewSet(viewsets.ReadOnlyModelViewSet):
@action
(
methods
=
[
'
get
'
],
detail
=
True
)
@action
(
methods
=
[
'
get
'
],
detail
=
True
)
def
form
(
self
,
request
,
pk
=
None
):
def
form
(
self
,
request
,
pk
=
None
):
"""
Return
the
edition
'
s form.
"""
Return
an
edition
'
s form.
If the edition does not have a form,
If the edition does not have a form,
returns a `404 Not Found` error response.
returns a `404 Not Found` error response.
...
@@ -282,10 +282,64 @@ class EditionViewSet(viewsets.ReadOnlyModelViewSet):
...
@@ -282,10 +282,64 @@ class EditionViewSet(viewsets.ReadOnlyModelViewSet):
form
=
edition
.
edition_form
.
form
form
=
edition
.
edition_form
.
form
except
ObjectDoesNotExist
:
except
ObjectDoesNotExist
:
return
Response
(
return
Response
(
{
'
detail
'
:
'
No form set on this edition.
'
},
status
=
404
)
{
'
detail
'
:
'
No form set on this edition.
'
},
status
=
status
.
HTTP_404_NOT_FOUND
)
else
:
else
:
return
redirect
(
'
api:form-detail
'
,
str
(
form
.
pk
))
return
redirect
(
'
api:form-detail
'
,
str
(
form
.
pk
))
@action
(
methods
=
[
'
get
'
],
detail
=
True
)
def
documents
(
self
,
request
,
pk
=
None
):
"""
Return list of files attached an edition
'
s form.
The recipient of the documents and the registration deadline
are returned as well.
### Example response
{
"
recipient
"
: {
"
user
"
: {
"
id
"
: 3,
"
email
"
:
"
john.doe@example.com
"
,
"
profile_type
"
: null,
"
first_name
"
:
"
John
"
,
"
last_name
"
:
"
Doe
"
,
"
gender
"
: null,
"
phone_number
"
:
"
+33 6 12 34 56 78
"
,
"
date_of_birth
"
: null,
"
url
"
:
"
http://localhost:8000/api/users/3/
"
},
"
address
"
: {
"
line1
"
:
"
Rue de Rivoli
"
,
"
line2
"
:
""
,
"
post_code
"
:
"
75001
"
,
"
city
"
:
"
Paris
"
,
"
country
"
: {
"
code
"
:
"
FR
"
,
"
name
"
:
"
France
"
}
},
"
promotion
"
: 2020,
"
tutoring_groups
"
: [1],
"
url
"
:
"
http://localhost:8000/api/tutors/1/
"
},
"
deadline
"
:
"
2018-07-29
"
,
"
files
"
: [
{
"
id
"
: 3,
"
name
"
:
"
Autorisation parentale
"
,
"
file
"
:
"
http://...
"
,
"
form
"
: 4
}
]
}
"""
edition
=
self
.
get_object
()
serializer
=
EditionDocumentsSerializer
(
edition
,
context
=
{
'
request
'
:
request
})
data
=
serializer
.
data
return
Response
(
data
)
class
ParticipationViewSet
(
mixins
.
CreateModelMixin
,
class
ParticipationViewSet
(
mixins
.
CreateModelMixin
,
viewsets
.
ReadOnlyModelViewSet
):
viewsets
.
ReadOnlyModelViewSet
):
...
@@ -373,4 +427,4 @@ class ParticipationViewSet(mixins.CreateModelMixin,
...
@@ -373,4 +427,4 @@ class ParticipationViewSet(mixins.CreateModelMixin,
participation
=
self
.
get_object
()
participation
=
self
.
get_object
()
serializer
=
FormEntrySerializer
(
participation
.
entry
)
serializer
=
FormEntrySerializer
(
participation
.
entry
)
data
=
serializer
.
data
data
=
serializer
.
data
return
Response
(
data
,
status
=
status
.
HTTP_200_OK
)
return
Response
(
data
)
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