Skip to content

Commit

Permalink
Make archetypes.schemaextender support more generic and handle pr…
Browse files Browse the repository at this point in the history
…obably most use cases.
  • Loading branch information
thet committed Feb 18, 2015
1 parent 3a06ba0 commit 24ba273
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
7 changes: 4 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Changelog
0.3 (unreleased)
----------------

- Add ``_directly_provided`` export field for the object's directly provided
interfaces.
- Make ``archetypes.schemaextender`` support more generic and handle probably
most use cases.
[thet]

- Add more schemaextender Archetype field types from some addons.
- Add ``_directly_provided`` export field for the object's directly provided
interfaces.
[thet]

- Add json_methods module to own Extension folder, which makes it automatically
Expand Down
47 changes: 22 additions & 25 deletions collective/jsonify/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ def get_archetypes_fields(self):
except:
return

try:
from archetypes.schemaextender.interfaces import IExtensionField
except:
IExtensionField = None

import base64

fields = []
Expand All @@ -377,16 +382,18 @@ def get_archetypes_fields(self):
fieldname = unicode(field.__name__)
type_ = field.__class__.__name__

if type_[0] == '_' and type_.endswith('ExtensionField'):
type_ = type_[1: -len('ExtensionField')] + 'Field'
try:
if IExtensionField.providedBy(field):
# archetypes.schemaextender case:
# Try to get the base class of the schemaexter-field, which
# is not an extension field.
type_ = [
it.__name__ for it in field.__class__.__bases__
if not IExtensionField.implementedBy(it)
][0]
except:
pass

string_fieldnames = [
'StringField',
'TextField',
'StringExtField', # lineage.themeselection
'XStringField', # from bda.plone.shop
'XTextField', # from bda.plone.shop
]
fieldnames = [
'BooleanField',
'ComputedField',
Expand All @@ -397,17 +404,14 @@ def get_archetypes_fields(self):
'IntegerField',
'LinesField',
'SimpleDataGridField',
'StringField',
'TALESLines',
'TALESString',
'TextField',
'ZPTField',
'LeadimageCaptionField', # from collective.contentleadimage
'XFloatField', # from bda.plone.shop
'XBooleanField', # from bda.plone.shop
'XSharedStockBooleanField', # from bda.plone.ticketshop
'XSharedStockFloatField', # from bda.plone.ticketshop
]

if type_ in string_fieldnames + fieldnames:
if type_ in fieldnames:
try:
value = field.getRaw(self.context)
except AttributeError:
Expand All @@ -420,7 +424,7 @@ def get_archetypes_fields(self):
if isinstance(value, str):
value = value.decode('utf-8')

if value and type_ in string_fieldnames:
if value and type_ in ['StringField', 'TextField']:
try:
value = self.decode(value)
except AttributeError:
Expand All @@ -439,18 +443,14 @@ def get_archetypes_fields(self):

self[unicode(fieldname)] = value

if value and type_ in string_fieldnames:
if value and type_ in ['StringField', 'TextField']:
try:
ct = field.getContentType(self.context)
self[unicode('_content_type_') + fieldname] = ct
except AttributeError:
pass

elif type_ in [
'DateTimeField',
'XDateTimeField', # from bda.plone.shop
'XSharedBuyablePeriodDateTimeField', # from bda.plone.ticketshop # noqa
]:
elif type_ in ['DateTimeField', ]:
value = str(self._get_at_field_value(field))
if value:
self[unicode(fieldname)] = value
Expand All @@ -460,8 +460,6 @@ def get_archetypes_fields(self):
'FileField',
'AttachmentField',
'ExtensionBlobField',
'LeadimageImageField', # from collective.contentleadimage
'LeadimageBlobImageField', # from collective.contentleadimage
]:
fieldname = unicode('_datafield_' + fieldname)
value = self._get_at_field_value(field)
Expand Down Expand Up @@ -519,7 +517,6 @@ def get_archetypes_fields(self):

elif type_ in [
'ReferenceField',
'CarouselProviderField', # from collective.carousel
]:
# If there are references, add the UIDs to the referenced
# contents
Expand Down

0 comments on commit 24ba273

Please sign in to comment.