Skip to content

Commit

Permalink
WCM-285: move Converter back to filesystem
Browse files Browse the repository at this point in the history
  • Loading branch information
stollero committed Sep 25, 2024
1 parent a136299 commit c6b0946
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 84 deletions.
2 changes: 1 addition & 1 deletion core/src/zeit/cms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '6.40.0.dev0'
__version__ = '6.39.0'
68 changes: 0 additions & 68 deletions core/src/zeit/connector/converter.py

This file was deleted.

77 changes: 76 additions & 1 deletion core/src/zeit/connector/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import os
import os.path

from sqlalchemy.dialects.postgresql import JSONB
import gocept.cache.property
import grokcore.component as grok
import lxml.etree
import sqlalchemy
import zope.app.file.image
import zope.interface

Expand Down Expand Up @@ -268,7 +271,7 @@ def _convert_sql_types(self, properties):
column = Content.column_by_name(*key)
if column is None:
continue
converter = zeit.connector.interfaces.IConverter(column)
converter = IConverter(column)
properties[key] = converter.deserialize(value)

def _guess_type(self, id):
Expand Down Expand Up @@ -316,3 +319,75 @@ def parse_properties(xml):
value += '</tag:rankedTags>'
properties[('keywords', 'http://namespaces.zeit.de/CMS/tagging')] = value
return properties


class IConverter(zope.interface.Interface):
"""Converts webdav values to and from the postgresql database."""

def serialize(value):
pass

def deserialize(value):
pass


@grok.implementer(IConverter)
@grok.adapter(sqlalchemy.Column)
def converter_from_column_type(column):
return IConverter(column.type)


@grok.implementer(IConverter)
class DefaultConverter(grok.Adapter):
grok.context(zope.interface.Interface)

def serialize(self, value):
return value

def deserialize(self, value):
return value


class BoolConverter(DefaultConverter):
grok.context(sqlalchemy.Boolean)

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

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


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

def serialize(self, value):
return str(value)

def deserialize(self, value):
return int(value)


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

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

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


@grok.implementer(IConverter)
class DictConverter(grok.Adapter):
grok.context(JSONB)

def serialize(self, value):
if not value:
return {}
return value

def deserialize(self, value):
if not value:
return {}
return value
10 changes: 0 additions & 10 deletions core/src/zeit/connector/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,6 @@ class IResourceInvalidatedEvent(zope.interface.Interface):
id = zope.interface.Attribute('Unique id of resource')


class IConverter(zope.interface.Interface):
"""Converts webdav values to and from the postgresql database."""

def serialize(value):
pass

def deserialize(value):
pass


@zope.interface.implementer(IResourceInvalidatedEvent)
class ResourceInvalidatedEvent:
def __init__(self, id):
Expand Down
4 changes: 2 additions & 2 deletions core/src/zeit/connector/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import zope.event

from zeit.cms.content.sources import FEATURE_TOGGLES
from zeit.connector.converter import DefaultConverter
from zeit.connector.filesystem import DefaultConverter
from zeit.connector.interfaces import (
ID_NAMESPACE,
UUID_PROPERTY,
Expand Down Expand Up @@ -388,7 +388,7 @@ def _set_properties(self, id, properties):

if FEATURE_TOGGLES.find('write_metadata_columns'):
column = Content.column_by_name(name, namespace)
converter = zeit.connector.interfaces.IConverter(column)
converter = zeit.connector.filesystem.IConverter(column)
value = converter.serialize(value)
else:
converter = DefaultConverter(None)
Expand Down
2 changes: 0 additions & 2 deletions core/src/zeit/connector/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ def from_webdav(self, props):
continue
if ns == INTERNAL_PROPERTY:
continue
if isinstance(v, datetime):
continue
unsorted[ns.replace(self.NS, '', 1)][k] = v
self.unsorted = unsorted

Expand Down

0 comments on commit c6b0946

Please sign in to comment.