Limit categories / related in forms only to current lang

This commit is contained in:
Iacopo Spalletti 2018-01-24 03:23:06 +01:00
parent ba8ef29dd5
commit e9c8934e8c
No known key found for this signature in database
GPG key ID: BDCBC2EB289F60C6
3 changed files with 6 additions and 2 deletions

View file

@ -332,7 +332,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
if apps.is_installed('djangocms_blog.liveblog'): if apps.is_installed('djangocms_blog.liveblog'):
fsets[2][1]['fields'][2].append('enable_liveblog') fsets[2][1]['fields'][2].append('enable_liveblog')
filter_function = get_setting('ADMIN_POST_FIELDSET_FILTER') filter_function = get_setting('ADMIN_POST_FIELDSET_FILTER')
if related: if related and Post.objects.namespace(config.namespace).active_translations().exists():
fsets[1][1]['fields'][0].append('related') fsets[1][1]['fields'][0].append('related')
if callable(filter_function): if callable(filter_function):
fsets = filter_function(fsets, request, obj=obj) fsets = filter_function(fsets, request, obj=obj)

View file

@ -94,7 +94,7 @@ class PostAdminFormBase(ConfigFormBase, TranslatableModelForm):
def available_categories(self): def available_categories(self):
qs = BlogCategory.objects qs = BlogCategory.objects
if self.app_config: if self.app_config:
return qs.namespace(self.app_config.namespace) return qs.namespace(self.app_config.namespace).active_translations()
return qs return qs

View file

@ -304,6 +304,10 @@ class AdminTest(BaseTest):
self.app_config_1.app_data.config.use_related = True self.app_config_1.app_data.config.use_related = True
self.app_config_1.save() self.app_config_1.save()
fsets = post_admin.get_fieldsets(request) fsets = post_admin.get_fieldsets(request)
self.assertFalse('related' in fsets[1][1]['fields'][0])
Post.objects.language('en').create(title='post x', app_config=self.app_config_1)
fsets = post_admin.get_fieldsets(request)
self.assertTrue('related' in fsets[1][1]['fields'][0]) self.assertTrue('related' in fsets[1][1]['fields'][0])
self.app_config_1.app_data.config.use_related = False self.app_config_1.app_data.config.use_related = False