示例#1
0
    def __call__(self):
        field_list = self.request.form.get('items.fl', '').strip()
        if field_list:
            field_list = field_list.split(',')
        else:
            field_list = ['@type', 'title', 'description', 'review_state']

        obj = IContentListingObject(self.context)
        summary = json_compatible({
            '@id': obj.getURL(),
        })

        for field in field_list:
            accessor = FIELD_ACCESSORS.get(field)
            if accessor is None:
                continue
            if isinstance(accessor, str):
                value = getattr(obj, accessor, None)
                if callable(value):
                    value = value()
            else:
                value = accessor(obj)
            summary[field] = json_compatible(value)

        if ('title' in summary
                and ITranslatedTitleSupport.providedBy(self.context)):
            # Update title to contain translated title in negotiated language
            attr = 'title_{}'.format(get_preferred_language_code())
            summary['title'] = getattr(self.context, attr)

        return summary
示例#2
0
    def __call__(self):
        field_list = self.request.form.get('items.fl', '').strip()
        if field_list:
            field_list = field_list.split(',')
        else:
            field_list = ['@type', 'title', 'description', 'review_state']

        obj = IContentListingObject(self.context)
        summary = json_compatible({
            '@id': obj.getURL(),
        })

        for field in field_list:
            accessor = FIELD_ACCESSORS.get(field)
            if accessor is None:
                continue
            if isinstance(accessor, str):
                value = getattr(obj, accessor, None)
                if callable(value):
                    value = value()
            else:
                value = accessor(obj)
            summary[field] = json_compatible(value)

        if ('title' in summary and
                ITranslatedTitleSupport.providedBy(self.context)):
            # Update title to contain translated title in negotiated language
            attr = 'title_{}'.format(get_preferred_language_code())
            summary['title'] = getattr(self.context, attr)

        return summary
示例#3
0
    def __call__(self):
        # Get the default summary first, then modify it as needed
        summary = super(GeverJSONSummarySerializer, self).__call__()

        # Include portal_type
        summary['@type'] = self.context.portal_type

        if ITranslatedTitleSupport.providedBy(self.context):
            # Update title to contain translated title in negotiated language
            attr = 'title_{}'.format(get_preferred_language_code())
            summary['title'] = getattr(self.context, attr)

        return summary
示例#4
0
    def __call__(self):
        # Get the default summary first, then modify it as needed
        summary = super(GeverJSONSummarySerializer, self).__call__()

        # Include portal_type
        summary['@type'] = self.context.portal_type

        if ITranslatedTitleSupport.providedBy(self.context):
            # Update title to contain translated title in negotiated language
            attr = 'title_{}'.format(get_preferred_language_code())
            summary['title'] = getattr(self.context, attr)

        return summary
示例#5
0
 def get_title(self, obj):
     if ITranslatedTitleSupport.providedBy(obj):
         return ITranslatedTitle(obj).title_de
     return obj.title
示例#6
0
def translated_title(obj):
    if ITranslatedTitleSupport.providedBy(obj):
        attr = 'title_{}'.format(get_preferred_language_code())
        return getattr(obj, attr, obj.Title())
    else:
        return obj.Title()
示例#7
0
def title_fr_indexer(obj):
    if ITranslatedTitleSupport.providedBy(obj):
        return ITranslatedTitle(obj).title_fr
    return None
示例#8
0
 def get_title(self, obj):
     if ITranslatedTitleSupport.providedBy(obj):
         return ITranslatedTitle(obj).title_de
     return obj.title
示例#9
0
def translated_title(obj):
    if ITranslatedTitleSupport.providedBy(obj):
        attr = 'title_{}'.format(get_preferred_language_code())
        return getattr(obj, attr, obj.Title())
    else:
        return obj.Title()