Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Luis García
collabmap
Commits
654e02c6
Commit
654e02c6
authored
Apr 27, 2020
by
Luis García
Browse files
Add location to results
parent
cf4b79cc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
6 deletions
+35
-6
collabmap/settings.py
collabmap/settings.py
+1
-0
polls/serializers.py
polls/serializers.py
+16
-5
requirements
requirements
+1
-0
surveys/serializers/surveys.py
surveys/serializers/surveys.py
+17
-1
No files found.
collabmap/settings.py
View file @
654e02c6
...
...
@@ -61,6 +61,7 @@ INSTALLED_APPS = [
'corsheaders'
,
'ckeditor'
,
'ckeditor_uploader'
,
'django_cleanup.apps.CleanupConfig'
,
'status.apps.StatusConfig'
,
'core.apps.CoreConfig'
,
#'sc.apps.ScConfig',
...
...
polls/serializers.py
View file @
654e02c6
from
rest_framework.serializers
import
ModelSerializer
,
ValidationError
from
api.utils
import
AsymetricRelatedField
from
.models
import
Poll
,
Question
,
Response
,
Answer
from
datetime
import
date
import
json
from
rest_framework.serializers
import
ModelSerializer
,
ValidationError
,
SerializerMethodField
from
drf_extra_fields.geo_fields
import
PointField
from
api.utils
import
AsymetricRelatedField
from
project.serializers
import
ConsultationSerializer_temp
from
datetime
import
date
from
.models
import
Poll
,
Question
,
Response
,
Answer
class
QuestionSerializer
(
ModelSerializer
):
...
...
@@ -47,8 +49,17 @@ class AnswerSerializer(ModelSerializer):
class
ResponseSerializer
(
ModelSerializer
):
answers
=
AnswerSerializer
(
many
=
True
,
read_only
=
True
)
#location = location = PointField(source='owner.profile.location', )
location
=
SerializerMethodField
(
read_only
=
True
)
class
Meta
:
model
=
Response
fields
=
(
'id'
,
'poll'
,
'created'
,
'answers'
)
fields
=
(
'id'
,
'poll'
,
'created'
,
'answers'
,
'location'
)
ref_name
=
'Poll response'
def
get_location
(
self
,
obj
):
location
=
obj
.
owner
.
profile
.
location
response
=
None
if
location
:
response
=
json
.
loads
(
obj
.
owner
.
profile
.
location
.
geojson
)
return
response
\ No newline at end of file
requirements
View file @
654e02c6
...
...
@@ -10,6 +10,7 @@ django-extensions==2.1.6
django-ckeditor==5.7.1
django-crontab==0.7.1
django-filter==2.1.0
django-cleanup==4.0.0
djangorestframework-jwt==1.11.0
djangorestframework-csv==2.1.0
social-auth-app-django==3.1.0
...
...
surveys/serializers/surveys.py
View file @
654e02c6
...
...
@@ -225,10 +225,12 @@ class ResultsAnswersSerializer(ModelSerializer):
type
=
serializers
.
SerializerMethodField
()
consultation
=
serializers
.
SerializerMethodField
()
survey
=
serializers
.
SerializerMethodField
()
location
=
serializers
.
SerializerMethodField
()
location_wkt
=
serializers
.
SerializerMethodField
()
class
Meta
:
model
=
Answer
fields
=
(
'answer'
,
'question'
,
'type'
,
'consultation'
,
'survey'
,
'created'
)
fields
=
(
'answer'
,
'question'
,
'type'
,
'consultation'
,
'survey'
,
'created'
,
'location'
,
'location_wkt'
)
def
get_answer
(
self
,
obj
):
response
=
obj
.
content
[
'value'
]
...
...
@@ -259,6 +261,20 @@ class ResultsAnswersSerializer(ModelSerializer):
def
get_survey
(
self
,
obj
):
return
obj
.
response
.
survey
.
name
def
get_location
(
self
,
obj
):
location
=
obj
.
response
.
owner
.
profile
.
location
response
=
None
if
location
:
response
=
json
.
loads
(
obj
.
response
.
owner
.
profile
.
location
.
geojson
)
return
response
def
get_location_wkt
(
self
,
obj
):
location
=
obj
.
response
.
owner
.
profile
.
location
response
=
None
if
location
:
response
=
obj
.
response
.
owner
.
profile
.
location
.
wkt
return
response
class
ResultsInputsSerializer
(
Serializer
):
name
=
serializers
.
CharField
(
max_length
=
100
)
description
=
serializers
.
CharField
(
max_length
=
300
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment