Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
5986ba40
Commit
5986ba40
authored
6 years ago
by
Tomasz Knapik
Committed by
Todd Dembrey
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Implement API outputting questions
parent
feac8b12
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
opentech/apply/funds/models/mixins.py
+0
-1
0 additions, 1 deletion
opentech/apply/funds/models/mixins.py
opentech/apply/funds/serializers.py
+34
-1
34 additions, 1 deletion
opentech/apply/funds/serializers.py
with
34 additions
and
2 deletions
opentech/apply/funds/models/mixins.py
+
0
−
1
View file @
5986ba40
...
@@ -152,7 +152,6 @@ class AccessFormData:
...
@@ -152,7 +152,6 @@ class AccessFormData:
for
field_id
in
self
.
question_field_ids
for
field_id
in
self
.
question_field_ids
if
field_id
not
in
self
.
named_blocks
if
field_id
not
in
self
.
named_blocks
]
]
def
output_answers
(
self
):
def
output_answers
(
self
):
# Returns a safe string of the rendered answers
# Returns a safe string of the rendered answers
return
mark_safe
(
''
.
join
(
self
.
render_answers
()))
return
mark_safe
(
''
.
join
(
self
.
render_answers
()))
This diff is collapsed.
Click to expand it.
opentech/apply/funds/serializers.py
+
34
−
1
View file @
5986ba40
import
collections
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
.models
import
ApplicationSubmission
from
.models
import
ApplicationSubmission
...
@@ -10,6 +12,37 @@ class SubmissionListSerializer(serializers.ModelSerializer):
...
@@ -10,6 +12,37 @@ class SubmissionListSerializer(serializers.ModelSerializer):
class
SubmissionDetailSerializer
(
serializers
.
ModelSerializer
):
class
SubmissionDetailSerializer
(
serializers
.
ModelSerializer
):
questions
=
serializers
.
SerializerMethodField
()
meta_questions
=
serializers
.
SerializerMethodField
()
class
Meta
:
class
Meta
:
model
=
ApplicationSubmission
model
=
ApplicationSubmission
fields
=
(
'
id
'
,
'
title
'
,)
fields
=
(
'
id
'
,
'
title
'
,
'
questions
'
,
'
meta_questions
'
)
def
get_all_questions
(
self
,
obj
,
filter_func
=
None
):
questions
=
collections
.
OrderedDict
()
for
field_id
in
obj
.
question_field_ids
:
if
filter_func
is
not
None
:
if
filter_func
(
field_id
):
continue
field
=
obj
.
field
(
field_id
)
# TODO: Check field to see if answer can be serialized
data
=
obj
.
data
(
field_id
)
questions
[
field_id
]
=
{
'
question
'
:
field
.
value
[
'
field_label
'
],
'
answer
'
:
data
,
}
return
questions
def
get_meta_questions
(
self
,
obj
):
return
self
.
get_all_questions
(
obj
,
filter_func
=
lambda
field_id
:
field_id
not
in
obj
.
named_blocks
)
def
get_questions
(
self
,
obj
):
return
self
.
get_all_questions
(
obj
,
filter_func
=
lambda
field_id
:
field_id
in
obj
.
named_blocks
)
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