Esempio n. 1
0
 def handle(self, *args, **kwargs):
     #
     #
     # kill all
     Post.objects.all().delete()
     Tag.objects.all().delete()
     #
     #
     # now import
     for mdfile in os.listdir(MDFILES):
         if mdfile == '.DS_Store':
             continue
         f = '%s/%s' % (MDFILES, mdfile)
         with codecs.open(f, encoding='UTF-8') as md:
             contents = md.read()
             parts = contents.split('---')
             header = yaml.load(parts[0])
         # build the post
         try:
             # make post
             p = Post()
             # created
             p.created = header['created']
             # title
             p.title = header['title']
             # url
             slug = mdfile.split('/').pop().split('.')[0]
             if slug.startswith('201'):
                 slug = slug[11:]
             p.slug = slug
             # description
             p.description = header['description']
             # contents
             p.source_content = parts[1]
             # status
             p.status = p.PUBLISHED
             # save it
             p.save()
             # tags
             try:
                 for tag in header['tags']:
                     tag, created = Tag.objects.get_or_create(tag=tag)
                     if created:
                         tag.slug = slugify(tag)
                         tag.save()
                     p.tags.add(tag)
             except KeyError:
                 pass
         except TypeError:
             # is an scrappy idea
             # make post
             if mdfile == 'index.html':
                 continue
             p = Post()
             p.title = mdfile[11:]
             p.slug = slugify(p.title)
             p.contents = contents
             p.save()
Esempio n. 2
0
 def test_slug_created(self):
     post = Post()
     post.title = 'Test'
     post.description = 'Test'
     post.save()
     # we now have a date
     self.assertEqual(post.slug, 'test')
Esempio n. 3
0
 def test_edit_url(self):
     """edit url returns correctly"""
     p = Post()
     p.title = 'This is a test post'
     p.slug = 'this-is-test-post'
     p.source_content = 'Hm, ha ha.'
     p.save()
     self.assertEqual(p.edit_url(), '/blog/edit/1/')
Esempio n. 4
0
 def test_markdown_rendering(self):
     """The source is rendered into markdown on saving"""
     post = Post()
     post.title = 'Test'
     post.slug = 'test'
     post.source_content = "# Hello"
     post.save()
     # we now have markdown
     self.assertHTMLEqual('<h1 id="hello">Hello</h1>', post.rendered_content)
Esempio n. 5
0
 def test_date_if_blank(self):
     """If no date is supplied for a post then
     datetime.now() is applied"""
     post = Post()
     post.title = 'Test'
     post.slug = 'test'
     post.source_content = "#Hello"
     post.save()
     # we now have a date
     self.assertTrue(post.created)
Esempio n. 6
0
 def test_use_date_if_supplied(self):
     """If a date is supplied at the time of creation
     then it will be used when saving"""
     post_date = datetime.now()
     post = Post()
     post.title = 'Test'
     post.slug = 'test'
     post.source_content = "#Hello"
     post.created = post_date
     post.save()
     # we now have a date
     self.assertEqual(post_date, post.created)
Esempio n. 7
0
    def test_cache_page_month_cache_enabled_false(self):
        """if no cache is enabled in the settings then
        no caching takes place"""
        # make the date
        d = datetime(
            year=2012,
            month=6,
            day=18,
            minute=2,
            hour=3,
            second=10)
        # request the page
        request = self.rf.get(
            reverse('omblog:month', args=[d.year, d.month]))
        response = views.month(request, d.year, d.month)
        self.assertNotContains(response, 'THISISATESTPOST')

        # now create a blog post
        p = Post()
        p.title = 'THISISATESTPOST'
        p.slug = 'slug'
        p.source_content = 'This is a test post'
        p.status = p.PUBLISHED
        p.description = 'test post'
        p.created = d
        p.save()

        # now it contains the content
        response = views.month(request, d.year, d.month)
        self.assertContains(response, 'THISISATESTPOST')

        # enabled it again
        settings.OMBLOG_CACHE_ENABLED = True
        reload(o_settings)

        # change the post to hidden and get view again
        p.status = p.HIDDEN
        p.save()

        # not contains
        response = views.month(request, d.year, d.month)
        self.assertNotContains(response, 'THISISATESTPOST')

        # change post status again and save
        p.status = p.PUBLISHED
        p.save()

        # not contains, because the page is cached
        response = views.month(request, d.year, d.month)
        self.assertNotContains(response, 'THISISATESTPOST')
Esempio n. 8
0
 def test_pygments(self):
     """Pygments works as expected"""
     post = Post()
     post.title = 'Test'
     post.slug = 'test'
     post.source_content = '# Hello \n\n <code lang="jibberish">boom</code>'
     post.save()
     self.assertHTMLEqual(
         """<h1 id="hello">
         Hello
         </h1><p>
         <div class="highlight">
         <pre>
         boom
         </pre>
         </div>""",
         post.rendered_content)
    def test_video_tag(self):
        """The video tag allows a html5 video tag to be outputted using
        {% video http://h264.url http://webm.url http://poster.url %}
        """
        p = Post()
        p.title = 'test post '
        p.source_content = '{% video http://w.video.mp4 http://w.video.webm http://w.poster.jpg %}'
        p.save()
        html = """<p><video controls="controls" poster="http://w.poster.jpg" preload>
<source src="http://w.video.mp4" type='video/mp4; codecs="avc1.42E01E,mp4a.40.2"'>
<source src="http://w.video.webm"  type='video/webm; codecs="vp8, vorbis"'>
<object id="flashvideo" width="720" height="540" data="http://releases.flowplayer.org/swf/flowplayer-3.2.10.swf" type="application/x-shockwave-flash">
<param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.10.swf">
<param name="allowfullscreen" value="true">
<param name="allowscriptaccess" value="always">
<param name="flashvars" value='config={"clip":{"url":"http://w.video.mp4}}'>
</object>
</video></p>"""
        self.assertHTMLEqual(p.rendered_content, html)
Esempio n. 10
0
    def test_cache_page_index_cache_enabled_false(self):
        """if no cache is enabled in the settings then
        no caching takes place"""
        # request the page
        request = self.rf.get(reverse('omblog:index'))
        response = views.index(request)
        self.assertNotContains(response, 'THISISATESTPOST')

        # now create a blog post
        p = Post()
        p.title = 'THISISATESTPOST'
        p.slug = 'slug'
        p.source_content = 'This is a test post'
        p.status = p.PUBLISHED
        p.description = 'test post'
        p.save()

        # now it contains the content
        response = views.index(request)
        self.assertContains(response, 'THISISATESTPOST')

        # enabled it again
        settings.OMBLOG_CACHE_ENABLED = True
        reload(o_settings)

        # change the post to hidden and get view again
        p.status = p.HIDDEN
        p.save()

        # not contains
        response = views.index(request)
        self.assertNotContains(response, 'THISISATESTPOST')

        # change post status again and save
        p.status = p.PUBLISHED
        p.save()

        # not contains, because the page is cached
        response = views.index(request)
        self.assertNotContains(response, 'THISISATESTPOST')