示例#1
0
  def process(self):
    self.log("Starting to process key: " + self.key)
    data = self._getData()
    post = self._getExistingPost()

    if not post:
      self.log("Post has not been seen before, creating new one.")
      post = Post()
      post.date_published = self._getPublishedDate()
      post.key = ndb.Key("Post", self.subkey)
      post.slug = data.get('slug', self.slug)
      post.published = True
    else:
      self.log("Post has been seen before, updating existing one.")

    # As a precaution, if the post has a status that is draft, ignore it.
    if data.get('status'):
      if data['status'] == "draft":
        self.log("Caught post in Draft mode, ending processing.")
        return

    post.title = data['title']
    post.body = self._renderBody(data.content)
    post.frontmatter = data.to_dict()
    post.put()

    return post.body
    def render(self, context):

        if self.include_draft:
            qs = Post.all().order('-post_date')
        else:
            qs = Post.published().order('-post_date')

        context[self.varname] = qs

        return ''
示例#3
0
def create_blog(oldblog):
    fields = oldblog['fields']
    print("Creating Post from %s." % fields['title'])
    post = Post()
    post.pk = oldblog['pk']
    post.create = fields['created']
    post.modified = fields['modified']
    post.published = fields['publish_on']
    post.slug = fields['slug']
    post.title = fields['title']
    post.subtitle = fields['subtitle']
    post.text = fields['text']
    post.save()
    print("Success!")
示例#4
0
def blog_post(request):
    user = request.user
    if request.method == 'POST':
        details=Post()
        details.title=request.POST['title']
        details.author=user#foreign key posting
        details.photo=request.FILES['photo']
        details.content=request.POST['content']
        details.public=request.POST['checks']#checkbox posting
        details.created=request.POST['created']
        details.updated=request.POST['updated']
        details.published=request.POST['published']
        details.save()
        return HttpResponseRedirect('/post_list/')
    else:
        return render(request,'blog/blog_post.html',{'user':user})
示例#5
0
    def test_create_post(self):
        # Create the post
        post = Post()

        # Set the attributes
        post.title = 'My first post'
        post.slug = 'my-first-post'
        post.excerpt = 'This is the excerpt'
        post.text = 'This is my first blog post'
        post.pub_date = timezone.now()
        post.post_color = 'orange'
        post.tags = 'test-tag'
        post.published = True

        # Save it
        post.save()

        # Check we can find it
        all_posts = Post.objects.all()
        self.assertEquals(len(all_posts), 1)
        only_post = all_posts[0]
        self.assertEquals(only_post, post)

        # Check attributes
        self.assertEquals(only_post.title, 'My first post')
        self.assertEquals(only_post.slug, 'my-first-post')
        self.assertEquals(only_post.excerpt, 'This is the excerpt')
        self.assertEquals(only_post.text, 'This is my first blog post')
        self.assertEquals(only_post.pub_date.day, post.pub_date.day)
        self.assertEquals(only_post.pub_date.month, post.pub_date.month)
        self.assertEquals(only_post.pub_date.year, post.pub_date.year)
        self.assertEquals(only_post.pub_date.hour, post.pub_date.hour)
        self.assertEquals(only_post.pub_date.minute, post.pub_date.minute)
        self.assertEquals(only_post.pub_date.second, post.pub_date.second)
        self.assertEquals(only_post.post_color, 'orange')
        self.assertEquals(only_post.tags, 'test-tag')
        self.assertEquals(only_post.published, True)