Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when publishing content from custom plugin w/ parent/child #5001

Closed
scottrogers opened this issue Feb 12, 2016 · 6 comments
Closed

Issue when publishing content from custom plugin w/ parent/child #5001

scottrogers opened this issue Feb 12, 2016 · 6 comments

Comments

@scottrogers
Copy link

I have created 2 plugins:

class CarouselPlugin(CMSPluginBase):
    model = Carousel
    name = ("Carousel")
    render_template = "carousel.html"
    cache = True
    allow_children = True

    def render(self, context, instance, placeholder):
        context = super(CarouselPlugin, self).render(context, instance, placeholder)
        return context

plugin_pool.register_plugin(CarouselPlugin)


class SlidePlugin(CMSPluginBase):
    model = Slide
    name = ('Slide')
    render_template = "slide.html"
    change_form_template = "change_form.html"
    cache = True
    parent_classes = ('TextPlugin', 'CarouselPlugin')

    def render(self, context, instance, placeholder):

        context = super(SlidePlugin, self).render(context, instance, placeholder)
        return context


plugin_pool.register_plugin(SlidePlugin)

The data comes from these models:

from cms.models.pluginmodel import CMSPlugin

class Carousel(CMSPlugin):
    title = models.CharField(blank=True, max_length=100)
    slug = models.SlugField()
    height = models.IntegerField(blank=True, null=True)

    def __unicode__(self):
        return self.title

class Slide(CMSPlugin):
    BACKGROUND_POSITIONS = (
        (u'top', u'top'),
        (u'center', u'center'),
        (u'bottom', u'bottom'),
    )
    image = models.ImageField(upload_to="carousel/")
    image_position = models.CharField(blank=True, max_length=100, choices=BACKGROUND_POSITIONS)
    content = models.TextField()
    order = models.PositiveIntegerField(default=0, blank=False, null=False)
    carousel = models.ForeignKey('Carousel')
    slug = models.SlugField()


    def __unicode__(self):
        return self.content

    class Meta:
        ordering = ('order',)

    def image_tag(self):
        return u'<img src="' + settings.MEDIA_URL + '%s" width="50" height="auto"/>' % self.image

    image_tag.short_description = 'Slide'
    image_tag.allow_tags = True
  1. I can create content and view it when it's in edit mode, but when publishing the content, I get a 500 error.
  2. I can publish the parent plugin, CarouselPlugin (when it doesnt have a child plugin in it).
  3. When I add a Slide (child to parent plugin), and try to publish that, I get the following error:
    screenshot 2016-02-12 11 07 15

Using django-cms==3.2.0

Any help would be great!

@vivazzi
Copy link

vivazzi commented Feb 20, 2016

Useless code:

def render(self, context, instance, placeholder):
        context = super(CarouselPlugin, self).render(context, instance, placeholder)
        return context

P.S. I think, there is a little information to decide your problem

@scottrogers
Copy link
Author

What else is required?

@vivazzi
Copy link

vivazzi commented Feb 20, 2016

I find next bug: class Slide should not have foreign key to Carousel, because you created two plugins which inherit from base class CMSPlugin.
May be it solved your error

@scottrogers
Copy link
Author

That didnt do anything. Thanks for the thought

@czpython
Copy link
Contributor

@scottrogers
The problem is that plugins already have an ordering specified.
Internally there's a field called position for all plugins, this field along with the path field determine the order of your plugin within the tree and inside a placeholder.

Please remove the order field and the ordering from the meta class.
Then run python manage.py cms fix-tree to fix the plugin positions.
Make sure to backup db just in case given that this command recalculates the plugin positions

Also please upgrade to the latest 3.2.x release as some bugs with fix-tree and the tree were fixed.

@czpython
Copy link
Contributor

@evildmp We should probably update the docs on plugins to include a note about overriding the plugin ordering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants