2016-08-02 1 views
0

간단한 질문이 있습니다. django-cms에 하위 플러그인의 개수 제한을 정의 할 수 있는지 알고 싶습니다. 내 플러그인에는 하위 플러그인이 있지만 자식 플러그인의 수를 최대 2 개로 제한하고 싶습니다. cms_plugins.py에 몇 가지 구성을 추가하는 것이 가능합니까? 양식을 추가하고 손으로 검증하지 않고도? django-cms에서 중첩 된 플러그인의 수를 제한 할 수 있습니까?

나는 settings.py이 추가 :

sidebar = PlaceholderField('ipp_article_sidebar', 
          related_name='IPP_ARTICLE_SIDEBAR') 

하지만 난 여전히 2 개 이상의 차일을 추가 할 수 있습니다

CMS_PLACEHOLDER_CONF = { 
    'Ipp_Article_Sidebar': { 
     'plugins': ['ArticlesParentCMSPlugin', 'ArticlesChildCMSPlugin'], 
     'name': gettext("Right Side Content"), 
     'limits': { 
      'ArticlesParentCMSPlugin': 1, 
      'ArticlesChildCMSPlugin': 2 
     } 
    }, 
} 

내 자리는 모델에 속한다.

+0

내가 내 질문에 업데이트 @mishbah – mishbah

+0

당신이 좀 걸릴 수 있습니다 http://docs.django-cms.org/en/develop/reference/configuration.html#cms-placeholder-conf보기? :) – patricia

답변

0

현재이 기능은 Django CMS에서 중첩 된 플러그인에 대해서는 수행 할 수 없습니다.

비슷한 것을 필요로하고 템플릿을 재정 의하여 빠른 해결 방법을 만들었습니다. https://github.com/divio/django-cms/issues/5102#issuecomment-278303995

는 단순히 Plugin 클래스에 max_children = <number>을 추가하고 기존의 장고 CMS 템플릿을 대체 할 템플릿 폴더 templates/cms/toolbar/에 새로운 dragitem.html 템플릿을 생성 : 나는 Github에서에 비슷한 질문에 대한 반응을 추가했다. 아래 diff를 참조하십시오.

최대 자식 수에 도달하면 + 아이콘이 제대로 비활성화됩니다.

--- env/lib/python3.5/site-packages/cms/templates/cms/toolbar/dragitem.html  2016-09-15 12:06:26.132803200 +0200 
+++ templates/cms/toolbar/dragitem.html 2017-02-08 12:26:59.343312100 +0100 
@@ -9,6 +9,17 @@ 
     {% if plugin.child_plugin_instances %} cms-dragitem-collapsable{% endif %}"> 
     {% language request.toolbar.toolbar_language %} 
     {% if not disabled_child %} 
+   {% with max_children=plugin.get_plugin_instance.1.max_children child_count=plugin.child_plugin_instances|length %} 
+    {% if max_children %} 
+     <div class="cms-submenu-btn cms-submenu-add cms-btn 
+      {% if child_count >= max_children %} cms-btn-disabled{% endif %}"> 
+      {% if child_count >= max_children %} 
+       <span class="cms-hover-tooltip" data-cms-tooltip="{% trans "You cannot add plugins to this plugin." %}"></span> 
+      {% else %} 
+       <span class="cms-hover-tooltip cms-hover-tooltip-left cms-hover-tooltip-delay" data-cms-tooltip="{% trans "Add plugin" %}"></span> 
+      {% endif %} 
+     </div> 
+    {% else %} 
      <div class="cms-submenu-btn cms-submenu-add cms-btn 
       {% if not allow_children %} cms-btn-disabled{% endif %}"> 
       {% if not allow_children %} 
@@ -17,6 +28,8 @@ 
       <span class="cms-hover-tooltip cms-hover-tooltip-left cms-hover-tooltip-delay" data-cms-tooltip="{% trans "Add plugin" %}"></span> 
       {% endif %} 
      </div> 
+    {% endif %} 
+   {% endwith %} 
      <div class="cms-submenu-btn cms-submenu-edit cms-btn" data-rel="edit"> 
       <span class="cms-hover-tooltip cms-hover-tooltip-left cms-hover-tooltip-delay" data-cms-tooltip="{% trans "Edit" %}"></span> 
      </div> 
관련 문제