Beispiel #1
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()
Beispiel #2
0
 def test_wrong_plugin_language(self):
     page = create_page("page", "nav_playground.html", "en", published=True)
     ph_en = page.placeholders.get(slot="body")
     add_plugin(ph_en, "TextPlugin", "en", body="I'm the first")
     title = Title(title="page", slug="page", language="ru", page=page)
     title.save()
     # add wrong plugin language
     add_plugin(ph_en, "TextPlugin", "ru", body="I'm the second")
     page.publish('en')
     superuser = self.get_superuser()
     with self.login_user_context(superuser):
         response = self.client.get('/en/?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
         self.assertEqual(response.status_code, 200)
Beispiel #3
0
 def test_wrong_plugin_language(self):
     page = create_page("page", "nav_playground.html", "en", published=True)
     ph_en = page.placeholders.get(slot="body")
     add_plugin(ph_en, "TextPlugin", "en", body="I'm the first")
     title = Title(title="page", slug="page", language="ru", page=page)
     title.save()
     # add wrong plugin language
     add_plugin(ph_en, "TextPlugin", "ru", body="I'm the second")
     page.publish('en')
     superuser = self.get_superuser()
     with self.login_user_context(superuser):
         response = self.client.get('/en/?%s' % get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
         self.assertEqual(response.status_code, 200)
Beispiel #4
0
def copy_pages():

    pages = PagesPage.objects.order_by('tree_id', 'lft', )
    # remove all the previous pages
    CMSPage.objects.all().delete()

    parents = {}

    for page in pages:
        cmspage = CMSPage()
        # replicate the language independent structure information
        # thanks to the common ancestor we can reuse exactly the same tree
        # information
        cmspage.pk = page.pk
        cmspage.creation_date = page.creation_date
        cmspage.publication_date = page.publication_date
        cmspage.publication_end_date = page.publication_end_date
        cmspage.changed_date = page.last_modification_date
        cmspage.template = 'django_' + page.template
        cmspage.level = page.level
        cmspage.lft = page.lft
        cmspage.rght = page.rght
        cmspage.tree_id = page.tree_id
        cmspage.site_id = 1
        if page.parent_id in parents:
            cmspage.parent = parents[page.parent_id]
        cmspage.save(no_signals=True)
        cmspage.rescan_placeholders()
        parents[cmspage.pk] = cmspage
        # replicate the language dependent data
        for language in page.get_languages():
            cmstitle = Title()
            cmstitle.language = language
            cmstitle.title = page.title(language)
            cmstitle.slug = page.slug(language)
            cmstitle.page = cmspage
            cmstitle.update_path()
            cmstitle.save()
            contents = page.content_by_language(language)
            for content in contents:
                if content.type in ('subtitle', 'text', 'right-column'):
                    placeholder = cmspage.placeholders.get(slot=content.type)
                    # For the main placeholders we need to scan whether content
                    # is markdown or plain HTML
                    # This is a very naif check, but does the trick in this
                    # context
                    if content.body.find('<p>') > -1:
                        add_plugin(placeholder, plugin_type='TextPlugin', language=language, body=content.body)
                    else:
                        add_plugin(placeholder, plugin_type='MarkItUpPlugin', language=language, body=content.body)
                elif content.type not in ('slug', 'title'):
                    # Fallback import
                    placeholder = cmspage.placeholders.get(slot=content.type)
                    add_plugin(placeholder, plugin_type='TextPlugin', language=language, body=content.body)
    def setUp(self):
        settings.APPEND_SLASH = False
        
        self.site = Site.objects.get_current()

        page = Page()
        page.site = self.site
        page.save()
        page.publish()
        self.page = page

        title = Title(title="Hello world!")
        title.page = page
        title.language = u'en'
        title.save()                
Beispiel #6
0
    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, commit=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, commit=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, commit=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)
Beispiel #7
0
    def setUp(self):
        settings.APPEND_SLASH = False

        self.site = Site.objects.get_current()

        page = Page()
        page.site = self.site
        page.save()
        page.publish()
        self.page = page

        title = Title(title="Hello world!")
        title.page = page
        title.language = u'en'
        title.save()
Beispiel #8
0
    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)
Beispiel #9
0
def copy_pages():

    pages = PagesPage.objects.order_by(
        'tree_id',
        'lft',
    )
    # remove all the previous pages
    CMSPage.objects.all().delete()

    parents = {}

    for page in pages:
        cmspage = CMSPage()
        # replicate the language independent structure information
        # thanks to the common ancestor we can reuse exactly the same tree
        # information
        cmspage.pk = page.pk
        cmspage.creation_date = page.creation_date
        cmspage.publication_date = page.publication_date
        cmspage.publication_end_date = page.publication_end_date
        cmspage.changed_date = page.last_modification_date
        cmspage.template = 'django_' + page.template
        cmspage.level = page.level
        cmspage.lft = page.lft
        cmspage.rght = page.rght
        cmspage.tree_id = page.tree_id
        cmspage.site_id = 1
        if page.parent_id in parents:
            cmspage.parent = parents[page.parent_id]
        cmspage.save(no_signals=True)
        cmspage.rescan_placeholders()
        parents[cmspage.pk] = cmspage
        # replicate the language dependent data
        for language in page.get_languages():
            cmstitle = Title()
            cmstitle.language = language
            cmstitle.title = page.title(language)
            cmstitle.slug = page.slug(language)
            cmstitle.page = cmspage
            cmstitle.update_path()
            cmstitle.save()
            contents = page.content_by_language(language)
            for content in contents:
                if content.type in ('subtitle', 'text', 'right-column'):
                    placeholder = cmspage.placeholders.get(slot=content.type)
                    # For the main placeholders we need to scan whether content
                    # is markdown or plain HTML
                    # This is a very naif check, but does the trick in this
                    # context
                    if content.body.find('<p>') > -1:
                        add_plugin(placeholder,
                                   plugin_type='TextPlugin',
                                   language=language,
                                   body=content.body)
                    else:
                        add_plugin(placeholder,
                                   plugin_type='MarkItUpPlugin',
                                   language=language,
                                   body=content.body)
                elif content.type not in ('slug', 'title'):
                    # Fallback import
                    placeholder = cmspage.placeholders.get(slot=content.type)
                    add_plugin(placeholder,
                               plugin_type='TextPlugin',
                               language=language,
                               body=content.body)