-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# -*- coding: utf-8 -*- | ||
from plone.dexterity.interfaces import IDexterityContent | ||
from plone.formwidget.geolocation.geolocation import Geolocation | ||
from plone.formwidget.geolocation.interfaces import IGeolocationField | ||
from plone.restapi.interfaces import IFieldDeserializer | ||
from plone.restapi.deserializer.dxfields import DefaultFieldDeserializer | ||
from zope.component import adapter | ||
from zope.interface import Interface | ||
from zope.interface import implementer | ||
|
||
|
||
@adapter(IGeolocationField, IDexterityContent, Interface) | ||
@implementer(IFieldDeserializer) | ||
class GeolocationDeserializer(DefaultFieldDeserializer): | ||
def __call__(self, value): | ||
if not isinstance(value, dict): | ||
raise ValueError(u"Invalid geolocation dict: {}".format(value)) | ||
|
||
if "latitude" not in value or "longitude" not in value: | ||
raise ValueError(u"Geolocation dict must have latitude & longitude keys") | ||
|
||
return Geolocation(value["latitude"], value["longitude"]) |