Login

FeinCMS inherit region content from translated language

Author:
schmidsi
Posted:
May 21, 2010
Language:
Python
Version:
1.2
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

  1. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 8 months ago

Comments

Please login first before commenting.