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
8a2befdc
Commit
8a2befdc
authored
Mar 30, 2020
by
Luis García
Browse files
Add center to map API
parent
bb59d6b8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
1 deletion
+15
-1
core/serializers.py
core/serializers.py
+15
-1
No files found.
core/serializers.py
View file @
8a2befdc
...
...
@@ -6,6 +6,10 @@ from django.utils.translation import gettext as _
from
rest_framework
import
serializers
from
drf_extra_fields.geo_fields
import
PointField
from
core.models
import
Profile
,
Map
import
json
from
django.contrib.gis.geos
import
Polygon
from
rest_framework.serializers
import
SerializerMethodField
from
pymbtiles
import
MBtiles
class
UserSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
...
...
@@ -72,9 +76,19 @@ class OwnerSerializer(serializers.ModelSerializer):
exclude
=
(
'id'
,
'username'
,
'password'
,
'email'
,
'first_name'
,
'last_name'
,
'is_active'
,
'is_staff'
,
'is_superuser'
,
'date_joined'
,
'groups'
,
'user_permissions'
,
'last_login'
)
class
MapSerializer
(
serializers
.
ModelSerializer
):
center
=
SerializerMethodField
(
'get_center_mbtiles'
)
def
get_center_mbtiles
(
self
,
object
):
with
MBtiles
(
object
.
file
.
path
)
as
src
:
bounds
=
src
.
meta
[
'bounds'
].
split
(
','
)
pol
=
Polygon
.
from_bbox
(
bounds
)
return
json
.
loads
(
pol
.
centroid
.
json
)
return
''
class
Meta
:
model
=
Map
fields
=
(
'id'
,
'name'
,
'file'
)
fields
=
(
'id'
,
'name'
,
'file'
,
'center'
)
class
PasswordResetSerializer
(
serializers
.
Serializer
):
email
=
serializers
.
EmailField
()
...
...
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