Permalink
Browse files

Ladies and gentleman: plugins in plugins somehow working

  • Loading branch information...
digi604 committed Oct 10, 2012
1 parent 4402fe2 commit 8197993f6cfbc0ee48704c8746b80055cab3bd6f
View
@@ -1154,6 +1154,7 @@ def add_plugin(self, request):
if parent:
plugin.parent = parent
+ plugin.position = CMSPlugin.objects.filter(parent=parent).count()
plugin.save()
if 'reversion' in settings.INSTALLED_APPS and page:
View
@@ -2,16 +2,26 @@
"""
Edit Toolbar middleware
"""
+from cms.plugin_pool import plugin_pool
from cms.cms_toolbar import CMSToolbar
from django.http import HttpResponse
from django.template.loader import render_to_string
def toolbar_plugin_processor(instance, placeholder, rendered_content, original_context):
original_context.push()
+ child_plugin_classes = []
+ if instance.get_plugin_class().allow_children:
+ instance, plugin = instance.get_plugin_instance()
+ print plugin
+ for child_class_name in plugin.get_child_classes(placeholder, original_context.get('request', {}).current_page):
+ cls = plugin_pool.get_plugin(child_class_name)
+ child_plugin_classes.append((cls.__name__, unicode(cls.name)))
+ print child_plugin_classes
data = {
'instance': instance,
- 'rendered_content': rendered_content
+ 'rendered_content': rendered_content,
+ 'child_plugin_classes': child_plugin_classes,
}
original_context.update(data)
output = render_to_string(instance.get_plugin_class().frontend_edit_template, original_context)
@@ -87,6 +87,7 @@ class CMSPlugin(MPTTModel):
lft = models.PositiveIntegerField(db_index=True, editable=False)
rght = models.PositiveIntegerField(db_index=True, editable=False)
tree_id = models.PositiveIntegerField(db_index=True, editable=False)
+ childrens = None
class Meta:
app_label = 'cms'
@@ -162,6 +163,7 @@ def get_plugin_instance(self, admin=None):
return instance, plugin
def render_plugin(self, context=None, placeholder=None, admin=False, processors=None):
+ print "model render plugin", self.__class__
instance, plugin = self.get_plugin_instance()
if instance and not (admin and not plugin.admin_preview):
if not isinstance(placeholder, Placeholder):
View
@@ -94,6 +94,9 @@ class CMSPluginBase(admin.ModelAdmin):
model = CMSPlugin
text_enabled = False
page_only = False
+
+ allow_children = False
+ child_classes = None
opts = {}
module = None #track in which module/application belongs
@@ -205,6 +208,17 @@ def icon_alt(self, instance):
the plugin object in a text editor.
"""
return "%s - %s" % (unicode(self.name), unicode(instance))
+
+ def get_child_classes(self, slot, page):
+ from cms.plugin_pool import plugin_pool
+ if self.child_classes:
+ return self.child_classes
+ else:
+ installed_plugins = plugin_pool.get_all_plugins(slot, page)
+ class_names = []
+ for cls in installed_plugins:
+ class_names.append(str(cls.__name__))
+ return class_names
def __repr__(self):
return smart_str(self.name)
@@ -1,26 +1,36 @@
from cms.plugin_pool import plugin_pool
from cms.plugin_base import CMSPluginBase
-from cms.plugins.column.models import Column, ColumnPlaceholder
-from django.contrib import admin
+from cms.plugins.column.models import MultiColumns, Column
from django.utils.translation import ugettext_lazy as _
-class PlaceholderInline(admin.TabularInline):
- model = ColumnPlaceholder
+class MultiColumnPlugin(CMSPluginBase):
+ model = MultiColumns
+ name = _("Multi Columns")
+ render_template = "cms/plugins/multi_column.html"
+ allow_children = True
+ child_classes = ["ColumnPlugin"]
+
+ def render(self, context, instance, placeholder):
+ context.update({
+ 'instance': instance,
+ 'placeholder':placeholder,
+ })
+ return context
class ColumnPlugin(CMSPluginBase):
model = Column
- name = _("Columns")
+ name = _("Column")
render_template = "cms/plugins/column.html"
- inlines = [PlaceholderInline]
- frontend_edit_template = "cms/plugins/column_frontend_edit.html"
+ allow_children = True
def render(self, context, instance, placeholder):
- placeholders = instance.placeholder_inlines.all()
+ print "column render"
context.update({
- 'placeholders': placeholders,
'instance': instance,
- })
+ 'placeholder':placeholder,
+ })
return context
+plugin_pool.register_plugin(MultiColumnPlugin)
plugin_pool.register_plugin(ColumnPlugin)
@@ -1,74 +0,0 @@
-# -*- coding: utf-8 -*-
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-
-class Migration(SchemaMigration):
-
- def forwards(self, orm):
- # Adding model 'Column'
- db.create_table('cmsplugin_column', (
- ('cmsplugin_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['cms.CMSPlugin'], unique=True, primary_key=True)),
- ('num_columns', self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=2)),
- ))
- db.send_create_signal('column', ['Column'])
-
- # Adding model 'Placeholder'
- db.create_table('column_placeholder', (
- ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
- ('column', self.gf('django.db.models.fields.related.ForeignKey')(related_name='placeholder_inlines', to=orm['column.Column'])),
- ('name', self.gf('django.db.models.fields.CharField')(max_length=255)),
- ('width', self.gf('django.db.models.fields.CharField')(max_length=255)),
- ('placeholder', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cms.Placeholder'])),
- ))
- db.send_create_signal('column', ['Placeholder'])
-
-
- def backwards(self, orm):
- # Deleting model 'Column'
- db.delete_table('cmsplugin_column')
-
- # Deleting model 'Placeholder'
- db.delete_table('column_placeholder')
-
-
- models = {
- 'cms.cmsplugin': {
- 'Meta': {'object_name': 'CMSPlugin'},
- 'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
- 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
- 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
- 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
- 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
- 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
- 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
- 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
- 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
- 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
- },
- 'cms.placeholder': {
- 'Meta': {'object_name': 'Placeholder'},
- 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
- },
- 'column.column': {
- 'Meta': {'object_name': 'Column', 'db_table': "'cmsplugin_column'", '_ormbases': ['cms.CMSPlugin']},
- 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
- 'num_columns': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '2'})
- },
- 'column.placeholder': {
- 'Meta': {'object_name': 'Placeholder'},
- 'column': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'placeholder_inlines'", 'to': "orm['column.Column']"}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
- 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']"}),
- 'width': ('django.db.models.fields.CharField', [], {'max_length': '255'})
- }
- }
-
- complete_apps = ['column']
@@ -1,85 +0,0 @@
-# -*- coding: utf-8 -*-
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-
-class Migration(SchemaMigration):
-
- def forwards(self, orm):
- # Deleting field 'Placeholder.name'
- db.delete_column('column_placeholder', 'name')
-
- # Deleting field 'Placeholder.width'
- db.delete_column('column_placeholder', 'width')
-
- # Adding field 'Placeholder.slot'
- db.add_column('column_placeholder', 'slot',
- self.gf('django.db.models.fields.CharField')(default='name', max_length=50, db_index=True),
- keep_default=False)
-
- # Adding field 'Placeholder.default_width'
- db.add_column('column_placeholder', 'default_width',
- self.gf('django.db.models.fields.PositiveSmallIntegerField')(null=True),
- keep_default=False)
-
-
- # Changing field 'Placeholder.placeholder'
- db.alter_column('column_placeholder', 'placeholder_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['cms.Placeholder'], null=True))
-
- def backwards(self, orm):
-
- # User chose to not deal with backwards NULL issues for 'Placeholder.name'
- raise RuntimeError("Cannot reverse this migration. 'Placeholder.name' and its values cannot be restored.")
-
- # User chose to not deal with backwards NULL issues for 'Placeholder.width'
- raise RuntimeError("Cannot reverse this migration. 'Placeholder.width' and its values cannot be restored.")
- # Deleting field 'Placeholder.slot'
- db.delete_column('column_placeholder', 'slot')
-
- # Deleting field 'Placeholder.default_width'
- db.delete_column('column_placeholder', 'default_width')
-
-
- # User chose to not deal with backwards NULL issues for 'Placeholder.placeholder'
- raise RuntimeError("Cannot reverse this migration. 'Placeholder.placeholder' and its values cannot be restored.")
-
- models = {
- 'cms.cmsplugin': {
- 'Meta': {'object_name': 'CMSPlugin'},
- 'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
- 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
- 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
- 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
- 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
- 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
- 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
- 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
- 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
- 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
- },
- 'cms.placeholder': {
- 'Meta': {'object_name': 'Placeholder'},
- 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
- },
- 'column.column': {
- 'Meta': {'object_name': 'Column', 'db_table': "'cmsplugin_column'", '_ormbases': ['cms.CMSPlugin']},
- 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
- 'num_columns': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '2'})
- },
- 'column.placeholder': {
- 'Meta': {'object_name': 'Placeholder'},
- 'column': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'placeholder_inlines'", 'to': "orm['column.Column']"}),
- 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
- 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
- }
- }
-
- complete_apps = ['column']
@@ -1,67 +0,0 @@
-# -*- coding: utf-8 -*-
-import datetime
-from south.db import db
-from south.v2 import SchemaMigration
-from django.db import models
-
-
-class Migration(SchemaMigration):
-
- def forwards(self, orm):
- # Deleting field 'Column.num_columns'
- db.delete_column('cmsplugin_column', 'num_columns')
-
- # Adding field 'Column.name'
- db.add_column('cmsplugin_column', 'name',
- self.gf('django.db.models.fields.CharField')(default='name', max_length=100),
- keep_default=False)
-
-
- def backwards(self, orm):
- # Adding field 'Column.num_columns'
- db.add_column('cmsplugin_column', 'num_columns',
- self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=2),
- keep_default=False)
-
- # Deleting field 'Column.name'
- db.delete_column('cmsplugin_column', 'name')
-
-
- models = {
- 'cms.cmsplugin': {
- 'Meta': {'object_name': 'CMSPlugin'},
- 'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
- 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
- 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
- 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
- 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
- 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
- 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
- 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
- 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
- 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
- },
- 'cms.placeholder': {
- 'Meta': {'object_name': 'Placeholder'},
- 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
- },
- 'column.column': {
- 'Meta': {'object_name': 'Column', 'db_table': "'cmsplugin_column'", '_ormbases': ['cms.CMSPlugin']},
- 'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
- 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
- },
- 'column.placeholder': {
- 'Meta': {'object_name': 'Placeholder'},
- 'column': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'placeholder_inlines'", 'to': "orm['column.Column']"}),
- 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
- 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
- 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
- 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
- }
- }
-
- complete_apps = ['column']
Oops, something went wrong.

0 comments on commit 8197993

Please sign in to comment.