FeinCMS inherit region content from translated language

 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. Different number of extra formsets in add/change view of ModelAdmin. by xormag 1 year, 10 months ago
  2. Set language via HTTP GET Parameter by schmidsi 3 years, 2 months ago
  3. Multilingual Models by Archatas 6 years, 2 months ago
  4. Model inheritance with content type and inheritance-aware manager by dan90 4 years, 8 months ago
  5. Unobtrusive comment moderation, updated for Django 1.0 by shimonrura 4 years, 3 months ago

Comments

(Forgotten your password?)