2015-12-09 20 views
1

我有現有的夾層項目與現有的頁面。可以實現AdminPage流暢內容功能而不具有流暢頁面功能?只是想創建夾層頁面,但內容流暢。這可能實現嗎?任何人都可以展示一些如何實現它到Mezzanine AdminPage的例子。如何實現django流利的內容到夾層現有項目

回答

1

由於沒有人有這個問題,我已經弄清楚,併成功實現流利內容到現有的夾層項目。 這很簡單,但調查需要編輯夾層cms的核心來源。畢竟輸出解決方案是簡單的應用程序,擴展夾層頁面在管理員或客戶端。

難度:媒體/專家)

SOLUTION:

(在這個例子中我已經使用的應用程序名稱爲 「cms_coremodul」) PS:有人用版本製作。 Python 3.4與虛擬環境。

閣設置並安裝:

夾層4.0.1

-install流暢,內容不同,需要 (遵循fluent-contents docs)什麼期望插件-version。

pip install django-fluent-contents 

- 也可以選擇安裝功能強大的wysiwyg CKEditor。

pip install django-ckeditor 

-所有安裝後,讓我們轉到setup settings.py並將所有內容遷移。

settings.py

-fluent,內容必須高於你的應用程序及以下夾層應用程序。

INSTALLED_APPS = (
    ... 
    "fluent_contents", 
    "django_wysiwyg", 
    "ckeditor", 
    # all working fluent-contents plugins 
    'fluent_contents.plugins.text',    # requires django-wysiwyg 
    'fluent_contents.plugins.code',    # requires pygments 
    'fluent_contents.plugins.gist', 
    'fluent_contents.plugins.iframe', 
    'fluent_contents.plugins.markup', 
    'fluent_contents.plugins.rawhtml', 
    'fluent_contents.plugins.picture', 
    'fluent_contents.plugins.oembeditem', 
    'fluent_contents.plugins.sharedcontent', 
    'fluent_contents.plugins.googledocsviewer', 
    ... 
    'here_will_be_your_app', 
) 

-settings爲Django的CKEditor的:

settings.py

# CORE MODUL DEFAULT WYSIWYG EDITOR SETUP 
RICHTEXT_WIDGET_CLASS = "ckeditor.widgets.CKEditorWidget" 
RICHTEXT_FILTER_LEVEL = 3 
DJANGO_WYSIWYG_FLAVOR = "ckeditor" 

# CKEditor config 
CKEDITOR_CONFIGS = { 
    'awesome_ckeditor': { 
     'toolbar': 'Full', 
    }, 
    'default': { 
     'toolbar': 'Standard', 
     'width': '100%', 
    },   
} 

的流暢,內容是完整的settings.py的-after設置允許遷移了一切:

python manage.py migrate 

- 如果會出現關於流利內容依賴關係的任何錯誤/錯誤,請安裝該依賴項並再次遷​​移。

製作新的應用FOR FLUENT-內容:

  • 創建夾層項目的新的應用程序(相同的Django):

    蟒蛇manage.py的startApp nameofyourapp

models.py

# -*- coding: utf-8 -*- 
from __future__ import unicode_literals 
from django.db import models 
from mezzanine.pages.models import Page 
from django.utils.translation import ugettext_lazy as _ 
from fluent_contents.models import PlaceholderRelation, ContentItemRelation 
from mezzanine.core.fields import FileField 
from . import appconfig 

class CoreModulPage(Page): 

    template_name = models.CharField("Template choice", max_length=255, choices=appconfig.TEMPLATE_CHOICES, default=appconfig.COREMODUL_DEFAULT_TEMPLATE) 

    # Accessing the data of django-fluent-contents 
    placeholder_set = PlaceholderRelation() 
    contentitem_set = ContentItemRelation() 

    class Meta: 
     verbose_name = _("Core page") 
     verbose_name_plural = _("Core pages") 

admin.py

from django.contrib import admin 
from django.http.response import HttpResponse 
from mezzanine.pages.admin import PageAdmin 

import json 

# CORE MODUL IMPORT 
from fluent_contents.admin import PlaceholderEditorAdmin 
from fluent_contents.analyzer import get_template_placeholder_data 
from django.template.loader import get_template 
from .models import CoreModulPage 
from . import appconfig 
from fluent_contents.admin.placeholdereditor import PlaceholderEditorInline 

class CoreModulAdmin(PlaceholderEditorAdmin, PageAdmin): 

    ################################# 
    #CORE MODUL - PAGE LOGIC 
    ################################# 
    corepage = CoreModulPage.objects.all() 
    # CORE FLUENT-CONTENTS 
    # This is where the magic happens. 
    # Tell the base class which tabs to create 
    def get_placeholder_data(self, request, obj): 
     # Tell the base class which tabs to create 
     template = self.get_page_template(obj) 
     return get_template_placeholder_data(template) 

    def get_page_template(self, obj): 
     # Simple example that uses the template selected for the page. 
     if not obj: 
      return get_template(appconfig.COREMODUL_DEFAULT_TEMPLATE) 
     else: 
      return get_template(obj.template_name or appconfig.COREMODUL_DEFAULT_TEMPLATE) 

    # Allow template layout changes in the client, 
    # showing more power of the JavaScript engine. 

    # THIS LINES ARE OPTIONAL 
    # It sets your own path to admin templates and static of fluent-contents 
    # 
    # START OPTIONAL LINES 
    # this "PlaceholderEditorInline.template" is in templates folder of your app 
    PlaceholderEditorInline.template = "cms_plugins/cms_coremodul/admin/placeholder/inline_tabs.html" 
    # this "PlaceholderEditorInline.Media.js" 
    # and "PlaceholderEditorInline.Media.css" is in static folder of your app 
    PlaceholderEditorInline.Media.js = (
      'cms_plugins/cms_coremodul/admin/js/jquery.cookie.js', 
      'cms_plugins/cms_coremodul/admin/js/cp_admin.js', 
      'cms_plugins/cms_coremodul/admin/js/cp_data.js', 
      'cms_plugins/cms_coremodul/admin/js/cp_tabs.js', 
      'cms_plugins/cms_coremodul/admin/js/cp_plugins.js', 
      'cms_plugins/cms_coremodul/admin/js/cp_widgets.js', 
      'cms_plugins/cms_coremodul/admin/js/fluent_contents.js', 
     ) 

    PlaceholderEditorInline.Media.css = { 
      'screen': (
       'cms_plugins/cms_coremodul/admin/css/cp_admin.css', 
      ), 
     } 

    PlaceholderEditorInline.extend = False # No need for the standard 'admin/js/inlines.min.js' here. 
    # 
    # END OPTIONAL LINES 

    # template to change rendering template for contents (combobox in page to choose desired template to render) 
    change_form_template = "cms_plugins/cms_coremodul/admin/page/change_form.html" 

    class Media: 
     js = (
      'cms_plugins/cms_coremodul/admin/js/coremodul_layouts.js', 
     ) 



    def get_layout_view(self, request): 
     """ 
     Return the metadata about a layout 
     """ 
     template_name = request.GET['name'] 

     # Check if template is allowed, avoid parsing random templates 
     templates = dict(appconfig.TEMPLATE_CHOICES) 
     if not templates.has_key(template_name): 
      jsondata = {'success': False, 'error': 'Template was not found!'} 
      status = 404 
     else: 
      # Extract placeholders from the template, and pass to the client. 
      template = get_template(template_name) 
      placeholders = get_template_placeholder_data(template) 

      jsondata = { 
       'placeholders': [p.as_dict() for p in placeholders], 
      } 
      status = 200 

     jsonstr = json.dumps(jsondata) 
     return HttpResponse(jsonstr, content_type='application/json', status=status) 


admin.site.register(CoreModulPage, CoreModulAdmin) 

appconfig.py

- 你在你的應用程序來創建新appconfig.py文件。

from django.conf import settings 
from django.core.exceptions import ImproperlyConfigured 


TEMPLATE_CHOICES = getattr(settings, "TEMPLATE_CHOICES",()) 
COREMODUL_DEFAULT_TEMPLATE = getattr(settings, "COREMODUL_DEFAULT_TEMPLATE", TEMPLATE_CHOICES[0][0] if TEMPLATE_CHOICES else None) 


if not TEMPLATE_CHOICES: 
    raise ImproperlyConfigured("Value of variable 'TEMPLATE_CHOICES' is not set!") 

if not COREMODUL_DEFAULT_TEMPLATE: 
    raise ImproperlyConfigured("Value of variable 'COREMODUL_DEFAULT_TEMPLATE' is not set!") 

settings.py: - 此行添加到您的settings.py夾層項目。

# CORE MODUL TEMPLATE LIST 
TEMPLATE_CHOICES = (
    ("pages/coremodulpage.html", "CoreModulPage"), 
    ("pages/coremodulpagetwo.html", "CoreModulPage2"), 
) 

# CORE MODUL default template setup (if drop-down not exist in admin interface) 
COREMODUL_DEFAULT_TEMPLATE = TEMPLATE_CHOICES[0][0] 

- 將您的應用程序擴展到INSTALLED_APPS(將您的應用程序添加到INSTALLED_APPS)。

INSTALLED_APPS = (
    ... 
    "yourappname_with_fluentcontents", 
) 

爲您您的應用程序的內容創建模板:

-template一個佔位符:

coremodulpage.html:

{% extends "pages/page.html" %} 
{% load mezzanine_tags fluent_contents_tags %} 

{% block main %}{{ block.super }} 
{% page_placeholder page.coremodulpage "main" role='m' %} 
{% endblock %} 

-template有兩個佔位符(一邊):

{% extends "pages/page.html" %} 
{% load mezzanine_tags fluent_contents_tags %} 

{% block main %}{{ block.super }} 
{% page_placeholder page.coremodulpage "main" role='m' %} 
<aside> 
    {% page_placeholder page.coremodulpage "sidepanel" role='s' %} 
</aside> 
{% endblock %} 

-after您的應用程序設置可以讓使遷移:

-1.Make您的應用程序遷移:

python manage.py makemigrations yourappname 

-2.Make您的應用程序遷移到數據庫:

python manage.py migrate 

FINALY COMPLETE! - 嘗試使用安裝了Fluent內容插件的新類型管理頁面。 - 在Admin的頁面類型下拉列表中,選擇核心頁面。如果您已經創建了模板以呈現帶有下拉框的佔位符顯示的流暢內容選項卡。現在您可以選擇所需的插件並創建頁面的模塊化內容。