def save_body(self, placeholder, desc): language = settings.LANGUAGE_CODE try: plugin = CMSPlugin.objects.get(placeholder=placeholder, position=0, language=language) plugin.body = desc except CMSPlugin.DoesNotExist: plugin = CMSPlugin(language=language, plugin_type='TextPlugin', position=0, placeholder=placeholder) plugin.save() if plugin: text = Text() #text.set_base_attr(plugin) text.pk = plugin.pk text.id = plugin.pk text.placeholder = placeholder text.position = plugin.position text.plugin_type = plugin.plugin_type text.tree_id = plugin.tree_id text.lft = plugin.lft text.rght = plugin.rght text.level = plugin.level text.cmsplugin_ptr = plugin text.publisher_public_id = None text.public_id = None text.published = False text.language = language text.body = desc text.save()
def test_delete_with_plugins(self): """ Check that plugins and placeholders get correctly deleted when we delete a page! """ page = create_page("page", "nav_playground.html", "en") page.rescan_placeholders() # create placeholders placeholder = page.placeholders.all()[0] plugin_base = CMSPlugin( plugin_type='TextPlugin', placeholder=placeholder, position=1, language=settings.LANGUAGES[0][0] ) plugin_base.insert_at(None, position='last-child', save=False) plugin = Text(body='') plugin_base.set_base_attr(plugin) plugin.save() self.assertEqual(CMSPlugin.objects.count(), 1) self.assertEqual(Text.objects.count(), 1) self.assertTrue(Placeholder.objects.count() > 0) page.delete() self.assertEqual(CMSPlugin.objects.count(), 0) self.assertEqual(Text.objects.count(), 0) self.assertEqual(Placeholder.objects.count(), 0)
def update(self): import feedparser from time import mktime from datetime import datetime from slugify import slugify from django.contrib.sites.models import Site from cms.models import Page, Title from cms.plugins.text.models import Text try: p_last = self.pages.latest('publication_date') except Page.DoesNotExist: p_last = None try: for e in feedparser.parse(self.url)['entries']: date = e.get('published_parsed') title = e.get('title') body = e.get('summary') url = e.get('link') if date and title and body: date = datetime.fromtimestamp(mktime(date)) if p_last and date <= p_last.publication_date: continue p=Page(site=Site.objects.all()[0], in_navigation=False, published=True, template='page-full.html') p.publication_date = date if self.parent_page: p.parent = self.parent_page p.save() self.pages.add(p) self.save() t=Title(language='en', title=title, slug='%s-%s' % (slugify(title), p.pk), page=p) t.save() pl=p.placeholders.get(slot='page') if url: body = u'%s<p><a href="%s">Lire la suite de l\'article…</a></p>' % (body, url) txt=Text(body=body, language='en', plugin_type='TextPlugin') txt.save() pl.cmsplugin_set.add(txt) pl.save() except: pass self.update_last = datetime.now() self.save()
def test_render_meta_does_not_leak(self): text = Text() link = Link() text._render_meta.text_enabled = False link._render_meta.text_enabled = False self.assertFalse(text._render_meta.text_enabled) self.assertFalse(link._render_meta.text_enabled) link._render_meta.text_enabled = True self.assertFalse(text._render_meta.text_enabled) self.assertTrue(link._render_meta.text_enabled)
def add_plugin(self, user=None, page=None, placeholder=None, language='en', body=''): if not placeholder: if page: placeholder = page.placeholders.get(slot__iexact='Right-Column') else: placeholder = page.placeholders.get(slot__iexact='Right-Column') plugin_base = CMSPlugin( plugin_type='TextPlugin', placeholder=placeholder, position=1, language=language ) plugin_base.insert_at(None, position='last-child', commit=False) plugin = Text(body=body) plugin_base.set_base_attr(plugin) plugin.save() return plugin.pk
def test_11_copy_textplugin(self): """ Test that copying of textplugins replaces references to copied plugins """ page = self.create_page() placeholder = page.placeholders.get(slot='body') plugin_base = CMSPlugin( plugin_type='TextPlugin', placeholder=placeholder, position=1, language=self.FIRST_LANG) plugin_base.insert_at(None, position='last-child', commit=False) plugin = Text(body='') plugin_base.set_base_attr(plugin) plugin.save() plugin_ref_1_base = CMSPlugin( plugin_type='TextPlugin', placeholder=placeholder, position=1, language=self.FIRST_LANG) plugin_ref_1_base.insert_at(plugin_base, position='last-child', commit=False) plugin_ref_1 = Text(body='') plugin_ref_1_base.set_base_attr(plugin_ref_1) plugin_ref_1.save() plugin_ref_2_base = CMSPlugin( plugin_type='TextPlugin', placeholder=placeholder, position=2, language=self.FIRST_LANG) plugin_ref_2_base.insert_at(plugin_base, position='last-child', commit=False) plugin_ref_2 = Text(body='') plugin_ref_2_base.set_base_attr(plugin_ref_2) plugin_ref_2.save() plugin.body = plugin_tags_to_admin_html(' {{ plugin_object %s }} {{ plugin_object %s }} ' % (str(plugin_ref_1.pk), str(plugin_ref_2.pk))) plugin.save() self.assertEquals(plugin.pk, 1) page_data = self.get_new_page_data() #create 2nd language page page_data.update({ 'language': self.SECOND_LANG, 'title': "%s %s" % (page.get_title(), self.SECOND_LANG), }) response = self.client.post(URL_CMS_PAGE_CHANGE % page.pk + "?language=%s" % self.SECOND_LANG, page_data) self.assertRedirects(response, URL_CMS_PAGE) self.assertEquals(CMSPlugin.objects.filter(language=self.FIRST_LANG).count(), 3) self.assertEquals(CMSPlugin.objects.filter(language=self.SECOND_LANG).count(), 0) self.assertEquals(CMSPlugin.objects.count(), 3) self.assertEquals(Page.objects.all().count(), 1) copy_data = { 'placeholder': placeholder.pk, 'language': self.SECOND_LANG, 'copy_from': self.FIRST_LANG, } response = self.client.post(URL_CMS_PAGE + "copy-plugins/", copy_data) self.assertEquals(response.status_code, 200) self.assertEqual(response.content.count('<li '), 3) # assert copy success self.assertEquals(CMSPlugin.objects.filter(language=self.FIRST_LANG).count(), 3) self.assertEquals(CMSPlugin.objects.filter(language=self.SECOND_LANG).count(), 3) self.assertEquals(CMSPlugin.objects.count(), 6) new_plugin = Text.objects.get(pk=6) self.assertEquals(plugin_tags_to_id_list(new_plugin.body), [u'4', u'5'])
def test_render_meta_is_unique(self): text = Text() link = Link() self.assertNotEqual(id(text._render_meta), id(link._render_meta))
def insert_test_content(self): # Insert a page p = Page(site=Site.objects.get_current(), reverse_id=self.test_data['reverse_id'], template=TEMPLATE_NAME, published=True, publisher_state=1, publisher_is_draft=False) p.save() t = Title(page=p, language=settings.LANGUAGES[0][0], slug=self.test_data['slug'], title=self.test_data['title']) t.save() # Placeholders have been inserted on post_save signal: self.test_placeholders = {} for placeholder in p.placeholders.all(): self.test_placeholders[placeholder.slot] = placeholder # Insert another page that is not the home page p2 = Page(parent=p, site=Site.objects.get_current(), reverse_id=self.test_data2['reverse_id'], template=TEMPLATE_NAME, published=True, publisher_state=1, publisher_is_draft=False) p2.save() t2 = Title(page=p2, language=settings.LANGUAGES[0][0], slug=self.test_data2['slug'], title=self.test_data2['title']) t2.save() # Insert some test Text plugins pl = Text(plugin_type='TextPlugin', page=p, language=settings.LANGUAGES[0][0], placeholder=self.test_placeholders['main'], position=0, body=self.test_data['text_main']) pl.insert_at(None, save=True) pl = Text(plugin_type='TextPlugin', page=p, language=settings.LANGUAGES[0][0], placeholder=self.test_placeholders['sub'], position=0, body=self.test_data['text_sub']) pl.insert_at(None, save=True) # Insert another page that is not the home page p3 = Page(parent=p2, site=Site.objects.get_current(), reverse_id=self.test_data3['reverse_id'], template=TEMPLATE_NAME, published=True, publisher_state=1, publisher_is_draft=False) p3.save() t3 = Title(page=p3, language=settings.LANGUAGES[0][0], slug=self.test_data3['slug'], title=self.test_data3['title']) t3.save() # Placeholders have been inserted on post_save signal: self.test_placeholders3 = {} for placeholder in p3.placeholders.all(): self.test_placeholders3[placeholder.slot] = placeholder # # Insert some test Text plugins pl = Text(plugin_type='TextPlugin', page=p3, language=settings.LANGUAGES[0][0], placeholder=self.test_placeholders3['sub'], position=0, body=self.test_data3['text_sub']) pl.insert_at(None, save=True) # Reload test pages self.test_page = Page.objects.get(pk=p.pk) self.test_page2 = Page.objects.get(pk=p2.pk) self.test_page3 = Page.objects.get(pk=p3.pk)