-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from eea/develop
Release 2.0
- Loading branch information
Showing
31 changed files
with
150 additions
and
587 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 |
---|---|---|
@@ -1,21 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Module where all interfaces, events and exceptions live.""" | ||
from eea.volto.policy import EEAMessageFactory as _ | ||
from zope import schema | ||
from zope.interface import Interface | ||
from zope.publisher.interfaces.browser import IDefaultBrowserLayer | ||
|
||
|
||
class IEeaVoltoPolicyLayer(IDefaultBrowserLayer): | ||
"""Marker interface that defines a browser layer.""" | ||
|
||
|
||
class IVoltoSettings(Interface): | ||
"""Volto settings necessary to store in the backend""" | ||
|
||
frontend_domain = schema.URI( | ||
title=u"Frontend domain", | ||
description=_(u"Used for rewriting URL's sent in thepassword reset " | ||
u"e-mail by Plone."), | ||
default="http://localhost:3000", | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,2 @@ | ||
""" RestAPI | ||
""" |
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,5 @@ | ||
<configure xmlns="http://namespaces.zope.org/zope"> | ||
<include package="plone.restapi" /> | ||
<include package=".deserializer" /> | ||
<include package=".serializer" /> | ||
</configure> |
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,2 @@ | ||
""" RestAPI deserializer | ||
""" |
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,8 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
i18n_domain="plone.restapi" | ||
> | ||
|
||
<adapter factory=".dxfields.DatetimeFieldDeserializer" /> | ||
|
||
</configure> |
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,66 @@ | ||
""" DXFields | ||
""" | ||
import dateutil | ||
from pytz import timezone, utc | ||
from eea.volto.policy.interfaces import IEeaVoltoPolicyLayer | ||
from plone.app.dexterity.behaviors.metadata import IPublication | ||
from plone.app.event.base import default_timezone | ||
from plone.dexterity.interfaces import IDexterityContent | ||
from plone.restapi.deserializer.dxfields import \ | ||
DatetimeFieldDeserializer as DefaultDatetimeFieldDeserializer | ||
from plone.restapi.interfaces import IFieldDeserializer | ||
from z3c.form.interfaces import IDataManager | ||
from zope.component import adapter, queryMultiAdapter | ||
from zope.interface import implementer | ||
from zope.schema.interfaces import IDatetime | ||
|
||
|
||
@implementer(IFieldDeserializer) | ||
@adapter(IDatetime, IDexterityContent, IEeaVoltoPolicyLayer) | ||
class DatetimeFieldDeserializer(DefaultDatetimeFieldDeserializer): | ||
""" DatetimeFieldDeserializer | ||
""" | ||
def __call__(self, value): | ||
# PATCH | ||
is_publication_field = self.field.interface == IPublication | ||
if is_publication_field: | ||
# because IPublication datamanager strips timezones | ||
tzinfo = timezone(default_timezone()) | ||
else: | ||
dm = queryMultiAdapter((self.context, self.field), IDataManager) | ||
current = dm.get() | ||
if current is not None: | ||
tzinfo = current.tzinfo | ||
else: | ||
tzinfo = None | ||
# END OF PATCH | ||
|
||
# This happens when a 'null' is posted for a non-required field. | ||
if value is None: | ||
self.field.validate(value) | ||
return value | ||
|
||
# Parse ISO 8601 string with dateutil | ||
dt = dateutil.parser.parse(value) | ||
|
||
# Convert to TZ aware in UTC | ||
if dt.tzinfo is not None: | ||
dt = dt.astimezone(utc) | ||
else: | ||
dt = utc.localize(dt) | ||
|
||
# Convert to local TZ aware or naive UTC | ||
if tzinfo is not None: | ||
tz = timezone(tzinfo.zone) | ||
value = tz.normalize(dt.astimezone(tz)) | ||
else: | ||
value = utc.normalize(dt.astimezone(utc)).replace(tzinfo=None) | ||
|
||
# if it's an IPublication field, remove timezone | ||
# info to not break field validation | ||
# PATCH | ||
if is_publication_field: | ||
value = value.replace(tzinfo=None) | ||
# END OF PATCH | ||
self.field.validate(value) | ||
return value |
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,2 @@ | ||
""" RestAPI serializer | ||
""" |
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,8 @@ | ||
<configure | ||
xmlns="http://namespaces.zope.org/zope" | ||
i18n_domain="plone.restapi" | ||
> | ||
|
||
<adapter factory=".dxfields.DateTimeFieldSerializer" /> | ||
|
||
</configure> |
Oops, something went wrong.