Merge pull request #424 from nephila/hotfix/limit_linked_objs

Limit categories / related in forms only to current lang
This commit is contained in:
Iacopo Spalletti 2018-01-25 23:54:46 +01:00 committed by GitHub
commit e29511b584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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'):
fsets[2][1]['fields'][2].append('enable_liveblog')
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')
if callable(filter_function):
fsets = filter_function(fsets, request, obj=obj)

View File

@ -94,7 +94,7 @@ class PostAdminFormBase(ConfigFormBase, TranslatableModelForm):
def available_categories(self):
qs = BlogCategory.objects
if self.app_config:
return qs.namespace(self.app_config.namespace)
return qs.namespace(self.app_config.namespace).active_translations()
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.save()
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.app_config_1.app_data.config.use_related = False