예제 #1
0
파일: views.py 프로젝트: ianluddy/spud_blog
def update_post(request, post_id=None, title=None, body=None, published=False, tags=None):
    """
    Add/Edit Blog Post
    :param: post_id [LONG] id of post to update [optional]
    :param: title [STR] post title [optional]
    :param: body [STR] post body [optional]
    :param: published [BOOL] post published flag [optional]
    :param: tags [LIST] list of tags[optional]
    :return: success [BOOL] success or failure
    """
    # Create or retrieve Post
    if post_id:
        post = Post.get_by_id(post_id, parent=get_blog_key())
    else:
        post = Post(parent=get_blog_key())

    # Update Post
    if body is not None:
        post.body = body
    if title is not None:
        post.title = title
    if tags is not None:
        post.tags = tags
    post.published = published

    # Persist
    try:
        post.put()
        success = True
    except Exception:
        success = False
        logging.error("Error saving post", exc_info=True)

    return HttpResponse(success)
예제 #2
0
    def test_can_create_simple_post(self):
        post = Post()
        post.title = "should be title"
        post.subtitle = "should be subtitle"
        post.created = datetime.now()
        post.body = "should be body"
        
        post.save()
        
        post_find = Post.objects.get(title=post.title)
        self.assertEquals(post_find.title, post.title)
        self.assertEquals(post_find.id, post.id)
        self.assertEquals(post_find.subtitle, post.subtitle)
        self.assertEquals(post_find.body, post.body)
        self.assertEquals(post_find.created, post.created)

        post.delete()
예제 #3
0
    def test_can_add_tags_to_post(self):
        tag1 = Tag(name='my first tag', slug='my-first-tag')
        tag1.save()
        tag2 = Tag(name='my second tag', slug='my-second-tag')
        tag2.save()

        post = Post()
        post.title = "should be title"
        post.subtitle = 'should be subtitle'
        post.created = datetime.now()
        post.body =  "should be body"
        post.save()

        post.tags = [tag1, tag2]

        post_found = Post.objects.get(title=post.title)
        self.assertIn(tag1, post_found.tags.all())
        self.assertIn(tag2, post_found.tags.all())
        self.assertEquals(len(post_found.tags.all()), 2)