Skip to content

Commit

Permalink
WCM-285: revert back to behaviour sql type not being converted to webdav
Browse files Browse the repository at this point in the history
- this is the intented behaviour, we do not want the dav anymore because we should prevent needless casting where possible
  • Loading branch information
stollero committed Sep 23, 2024
1 parent 73d6e51 commit 0941314
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
5 changes: 5 additions & 0 deletions core/src/zeit/cms/content/dav.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,20 @@ def toProperty(self, value):
class BoolProperty:
def __init__(self, context, properties, propertykey):
self.context = context
self.has_sql_type = ConnectorModel.column_by_name(*propertykey) is not None

def fromProperty(self, value):
if self.has_sql_type and FEATURE_TOGGLES.find('read_metadata_columns'):
return value
return self._fromProperty(value)

@staticmethod
def _fromProperty(value):
return value.lower() in ('yes', 'true')

def toProperty(self, value):
if self.has_sql_type and FEATURE_TOGGLES.find('write_metadata_columns'):
return value
return self._toProperty(value)

@staticmethod
Expand Down
14 changes: 6 additions & 8 deletions core/src/zeit/connector/converter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import datetime

from sqlalchemy.dialects.postgresql import JSONB
import grokcore.component as grok
import sqlalchemy
Expand Down Expand Up @@ -28,30 +26,30 @@ def deserialize(self, value):
class BoolConverter(DefaultConverter):
grok.context(sqlalchemy.Boolean)

def serialize(self, value: bool) -> str:
def serialize(self, value):
return zeit.cms.content.dav.BoolProperty._toProperty(value)

def deserialize(self, value: str) -> bool:
def deserialize(self, value):
return zeit.cms.content.dav.BoolProperty._fromProperty(value)


class IntConverter(DefaultConverter):
grok.context(sqlalchemy.Integer)

def serialize(self, value: int) -> str:
def serialize(self, value):
return str(value)

def deserialize(self, value: str) -> int:
def deserialize(self, value):
return int(value)


class DatetimeConverter(DefaultConverter):
grok.context(sqlalchemy.TIMESTAMP)

def serialize(self, value: datetime.datetime) -> str:
def serialize(self, value):
return zeit.cms.content.dav.DatetimeProperty._toProperty(value)

def deserialize(self, value: str) -> datetime.datetime:
def deserialize(self, value):
return zeit.cms.content.dav.DatetimeProperty._fromProperty(value)


Expand Down
2 changes: 1 addition & 1 deletion core/src/zeit/connector/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from zeit.cms.content.sources import FEATURE_TOGGLES
from zeit.connector.interfaces import ID_NAMESPACE, CannonicalId
from zeit.connector.models import ContentWithMetadataColumns as Content
from zeit.connector.models import Content
import zeit.cms.config
import zeit.cms.content.dav
import zeit.connector.interfaces
Expand Down
19 changes: 2 additions & 17 deletions core/src/zeit/connector/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from sqlalchemy.orm import declared_attr, mapped_column, relationship
import pytz
import sqlalchemy
import zope.component

from zeit.cms.content.sources import FEATURE_TOGGLES
from zeit.connector.interfaces import INTERNAL_PROPERTY, DeleteProperty, LockStatus
Expand Down Expand Up @@ -177,17 +176,6 @@ def lock_status(self):

NS = 'http://namespaces.zeit.de/CMS/'

@staticmethod
def converter(column):
if 'converter' in column.info:
return zope.component.queryAdapter(
column.type,
zeit.connector.interfaces.IConverter,
column.info['converter'],
)
else:
return zeit.connector.interfaces.IConverter(column)

def to_webdav(self):
if self.unsorted is None:
return {}
Expand All @@ -205,9 +193,7 @@ def to_webdav(self):
if FEATURE_TOGGLES.find('read_metadata_columns'):
for column in self._columns_with_name():
namespace, name = column.info['namespace'], column.info['name']
value = getattr(self, column.name)
converter = self.converter(column)
props[(name, self.NS + namespace)] = converter.serialize(value)
props[(name, self.NS + namespace)] = getattr(self, column.name)

if self.lock:
props[('lock_principal', INTERNAL_PROPERTY)] = self.lock.principal
Expand Down Expand Up @@ -235,8 +221,7 @@ def from_webdav(self, props):
namespace, name = column.info['namespace'], column.info['name']
value = props.get((name, self.NS + namespace), self)
if value is not self:
converter = self.converter(column)
setattr(self, column.name, converter.deserialize(value))
setattr(self, column.name, value)

unsorted = collections.defaultdict(dict)
for (k, ns), v in props.items():
Expand Down

0 comments on commit 0941314

Please sign in to comment.