コード例 #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
ファイル: summary.py プロジェクト: lukasgraf/opengever.core
    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
ファイル: report.py プロジェクト: 4teamwork/opengever.core
 def get_title(self, obj):
     if ITranslatedTitleSupport.providedBy(obj):
         return ITranslatedTitle(obj).title_de
     return obj.title
コード例 #9
0
ファイル: listing.py プロジェクト: 4teamwork/opengever.core
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()