Hi Patrick,
here's some example code.
Context: Sometimes I put links into the toolbar menu where the editors
can add new things, like tv broadcasts, or clay vases. When the new
thing is a CMSPlugin and should appear on a newly created page, I let
their model class inherit from this mixin and call `ensure_is_in_page`
from the admin class.
class CreatePageMixin(object):
def ensure_is_in_page(self, user, parent_page_id):
try:
self.placeholder.page.pk
except AttributeError:
page = self.create_page(user, parent_page_id)
self.assign_to_page(page)
def create_page(self, user, parent_page_id):
from cms import api # Not available before model creation
try:
parent = Page.objects.get(pk=parent_page_id)
except Page.DoesNotExist:
parent = self.get_parent_page() # to implement if required
page = api.create_page(
self.name,
self.PAGE_TEMPLATE, # define this in each child class
'de', # or any other language
created_by=user,
parent=parent
)
return page
def assign_to_page(self, page):
placeholder = page.placeholders.get(slot=self.PLACEHOLDER)
self.placeholder = placeholder
self.language = 'de'
self.position = 0
self.plugin_type = self.PLUGIN_TYPE
That's probably not exactly what you need but should give you an idea of
what's possible.
Best
Philipp
--
Philipp Zedler
Developer für's Web
Am langen Rain 12
39031 Bruneck
Italien
++39 / 324 / 77 345 96
http://www.zedler.it
--
Message URL:
https://groups.google.com/d/msg/django-cms-developers/topic-id/message-id
Unsubscribe: send a message to
django-cms-developers+unsubscr...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "django CMS developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to django-cms-developers+unsubscr...@googlegroups.com.
To view this discussion on the web, visit
https://groups.google.com/d/msgid/django-cms-developers/cbf94e0f-1eba-d4c9-29b0-8607308546ef%40neue-musik.com.
For more options, visit https://groups.google.com/d/optout.