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
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
Please login first before commenting.