Login

FeinCMS inherit region content from translated language

Author:
schmidsi
Posted:
May 21, 2010
Language:
Python
Version:
1.2
Tags:
feincms inherit region page moodboard language mulit-language translation
Score:
0 (after 0 ratings)

Small hack to inherit region content from the translated object.

code should be placed in models.py, where the Page object is created.

use feincms version 1.1.2 and above

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from feincms.models import ContentProxy
from feincms.module.page.models import Page


class InheritLanguageContentProxy(ContentProxy):
    def get_content(self, item, attr):
        try:
            region = item.template.regions_dict[attr]
        except KeyError:
            return []

        def collect_items(obj):
            contents = obj._content_for_region(region)
            
            # if the obj is a translation of another object, try to get the content of it
            if region.inherited and not contents and hasattr(obj, 'translation_of_id') and obj.translation_of_id:
                return collect_items(obj.translation_of)
            # go to parent if this model has a parent attribute
            if region.inherited and not contents and hasattr(obj, 'parent_id') and obj.parent_id:
                return collect_items(obj.parent)

            return contents

        contents = collect_items(item)
        contents.sort(key=lambda c: c.ordering)
        return contents
Page.content_proxy_class = InheritLanguageContentProxy

More like this

Comments

Please login first before commenting.