当前位置: 首页>>代码示例>>Python>>正文


Python Post.delete方法代码示例

本文整理汇总了Python中models.Post.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Post.delete方法的具体用法?Python Post.delete怎么用?Python Post.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Post的用法示例。


在下文中一共展示了Post.delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit_or_create_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
def edit_or_create_post(request):
    try:
        user = TestProfile.objects.get(email=request.user.email)
        post = Post.objects.get(user=user)
        provided, type = json.loads(post.provided), json.loads(post.house_type)
    except Post.DoesNotExist:
        post = None
        type = None
        provided = None
    except TestProfile.DoesNotExist:
        user = None

    if request.POST.get('add'):
        if user is not None and post is None:
            user.num_posts += 1
            post = Post(user=user, region=user.region, sub_region='Berkeley', distance='',
                        title=request.POST.get('title'),
                        house_type=json.dumps(request.POST.getlist('housing_type[]')),
                        provided=json.dumps(request.POST.getlist('provided[]')),
                        proximity='10 minute walk',
                        num_people=1,
                        notes=request.POST.get('notes'))
            post.save()
            provided, type = json.loads(post.provided), json.loads(post.house_type)
            print(provided)
    elif request.POST.get('delete'):
        if user.num_posts > 0:
            user.num_posts -= 1
        if post is not None:
            post.delete()
    user.save()
    context = {'user': user, 'post': post, 'type': type, 'provided': provided}
    return render(request, 'temporary_housing/edit_or_create_post.html', context)
开发者ID:mitchkarns,项目名称:bnb,代码行数:35,代码来源:views.py

示例2: delete

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
def delete(user, id):
	post = Post.find_by_id(id)
	if post:
		Post.delete(user,id)
		return redirect('/home')
	else:
		abort(404)
开发者ID:kevinmangan,项目名称:Tweeter,代码行数:9,代码来源:routes.py

示例3: delete_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
    def delete_post(cls, post_id, user_id):
        error_msg = None
        posts = Post.all().order('-created').fetch(limit=10)
        updated_post_list = posts
        post = Post.get_by_id(post_id)
        if user_id == post.created_by:

            # delete comments of the post
            comments = Comment.all().filter('post_id =', post_id).fetch(limit=10)
            for c in comments:
                Comment.delete(c)

            # delete likes of the post
            likes = Like.all().filter('post_id =', post_id).fetch(limit=10)
            for l in likes:
                Like.delete(l)

            # delete the post
            updated_post_list = cls.update_list_on_delete(
                object_list=posts,
                object_id=post_id
            )
            Post.delete(post)

        else:
            error_msg = 'You can delete only your own posts'

        return updated_post_list, error_msg
开发者ID:daliavi,项目名称:udacity-blog,代码行数:30,代码来源:service.py

示例4: test_post_crud_methods

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
    def test_post_crud_methods(self):
        message = 'Test message'
        user = UserFactory.create(remote_id=TRAVIS_USER_ID)
        mock_post = PostFactory.create(text=message, wall_owner=user)

        #create by objects api
        post = Post.objects.create(
                **PostFactory.get_mock_params_dict(
                    mock_post, commit_remote=True)
        )

        self.assertTrue(post.remote_id > 0)
        self.assertEqual(post.text, message)

        fetched_post = Post.remote.fetch(ids=[post.remote_id]).first()
        self.assertEqual(fetched_post.text, post.text)

        # Update
        edited_message = 'Edited message with CRUD'
        post = Post.objects.get(id=post.id)
        post.text = edited_message
        post.save(commit_remote=True)
        self.assertEqual(post.text, edited_message)

        fetched_post = Post.remote.fetch(ids=[post.remote_id]).first()
        self.assertEqual(fetched_post.text, edited_message)

        # Delete
        post.delete()
        post1 = Post.objects.get(id=post.id)
        self.assertTrue(post1.archived)

        fetched_post = Post.remote.fetch(ids=[post.remote_id])
        self.assertFalse(fetched_post)

        # Restore
        post.restore()
        post1 = Post.objects.get(id=post.id)
        self.assertFalse(post1.archived)

        fetched_post = Post.remote.fetch(ids=[post1.remote_id])
        self.assertTrue(fetched_post)

        post.delete()

        # Create with save()
        post = Post()
        post.__dict__.update(PostFactory.get_mock_params_dict(mock_post))
        post.text = message + message
        post.save(commit_remote=True)

        self.assertTrue(post.remote_id > 0)
        self.assertEqual(post.text, message + message)

        fetched_post = Post.remote.fetch(ids=[post.remote_id]).first()
        self.assertEqual(fetched_post.text, post.text)

        post.delete()
开发者ID:rkmarvin,项目名称:django-vkontakte-wall,代码行数:60,代码来源:tests.py

示例5: test_post_crud_methods

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
    def test_post_crud_methods(self):
        group = GroupFactory(remote_id=GROUP_CRUD_ID)
        user = UserFactory(remote_id=USER_AUTHOR_ID)

        def assert_local_equal_to_remote(post):
            post_remote = Post.remote.fetch(ids=[post.remote_id])[0]
            self.assertEqual(post_remote.remote_id, post.remote_id)
            self.assertEqual(post_remote.text, post.text)

        self.assertEqual(Post.objects.count(), 0)

        # create
        post = Post(text='Test message', wall_owner=group, author=user, date=datetime.now())
        post.save(commit_remote=True)
        self.objects_to_delete += [post]

        self.assertEqual(Post.objects.count(), 1)
        self.assertNotEqual(len(post.remote_id), 0)
        assert_local_equal_to_remote(post)

        # create by manager
        post = Post.objects.create(text='Test message created by manager', wall_owner=group, author=user, date=datetime.now(), commit_remote=True)
        self.objects_to_delete += [post]

        self.assertEqual(Post.objects.count(), 2)
        self.assertNotEqual(len(post.remote_id), 0)
        assert_local_equal_to_remote(post)

        # create by manager on user's wall
        post = Post.objects.create(text='Test message', wall_owner=user, author=user, date=datetime.now(), commit_remote=True)
        self.objects_to_delete += [post]

        self.assertEqual(Post.objects.count(), 3)
        self.assertNotEqual(len(post.remote_id), 0)
        assert_local_equal_to_remote(post)

        # update
        post.text = 'Test message updated'
        post.save(commit_remote=True)

        self.assertEqual(Post.objects.count(), 3)
        assert_local_equal_to_remote(post)

        # delete
        post.delete(commit_remote=True)

        self.assertEqual(Post.objects.count(), 3)
        self.assertTrue(post.archived)
        self.assertEqual(Post.remote.fetch(ids=[post.remote_id]).count(), 0)

        # restore
        post.restore(commit_remote=True)
        self.assertFalse(post.archived)

        self.assertEqual(Post.objects.count(), 3)
        assert_local_equal_to_remote(post)
开发者ID:Core2Duo,项目名称:django-vkontakte-wall,代码行数:58,代码来源:tests.py

示例6: delete_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
def delete_post(id=None):
    # Delete post #id from database
    query = Post.delete().where(Post.id == id)
    query.execute()

    # return JSON status OK
    return jsonify(**STATUS_OK)
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:9,代码来源:views.py

示例7: PostVisibilityTests

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
class PostVisibilityTests(TestCase):
    def setUp(self):
        self.fake_user = User(username='FakeUser', password='FakePassword')
        self.fake_user.save()
        self.fake_post = Post(title='Fake Post', author=self.fake_user, content='This is a fake post used for testing')

    def test_post_publish_method_sets_is_published_to_True(self):
        self.fake_post.publish()
        self.assertTrue(self.fake_post.is_published)

    def test_post_unpublish_method_sets_is_publised_to_False(self):
        self.fake_post.unpublish()
        self.assertFalse(self.fake_post.is_published)

    def test_post_delete_method_sets_is_deleted_to_True(self):
        self.fake_post.delete()
        self.assertTrue(self.fake_post.is_deleted)
开发者ID:SheaMeyers,项目名称:PatchmanBlog,代码行数:19,代码来源:tests.py

示例8: delete

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
    def delete(self, id):
        post = Post.get_by_id(id)
        if post is None:
            flash(gettext('The post was not found'), 'error')
            return redirect(url_for('PostsView:index'))
        if not post.can_edit():
            abort(401)

        try:
            title  = post.title
            Post.delete(post.id)
            flash(gettext('The post "%(title)s" was removed', title=title))
        except:
            flash(gettext('Error while removing the post'), 'error')

        if request.method == 'POST':
            return redirect(url_for('PostsView:index'))
        return jsonify(redirect_to=url_for('PostsView:index'))
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:20,代码来源:views.py

示例9: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
def post(request, id, title=None):
    if request.method == 'POST' and 'type' in request.POST:
        if request.POST['type'] == 'reply':
            try:
                parent_id = int(request.POST['reply_to'])
            except:
                parent_id = id
            parent = Post.objects.get(pk=parent_id)
            comment = Post(
                user=request.user,
                content=request.POST['content'],
                heading="Re:"+parent.heading,
                parent=parent,
                is_comment=True,
                forum=parent.forum
            )
            comment.save()
        elif request.POST['type'] == 'delete':
            del_id = int(request.POST['delete_id'])
            comment = Post.objects.get(pk=del_id)
            if request.user.is_staff or comment.user == request.user:
                comment.delete()
                if del_id == int(id):
                    return HttpResponseRedirect('/forum/category/general/')

    post = Post.objects.get(pk=id)

    if post.is_comment:
        post = post.get_root()

    if post.hits is None:
        post.hits = 1
    else:
        post.hits = post.hits + 1
    post.save()

    replies = post.get_descendants().select_related("parent")

    reply_numbers = []
    for r in replies:
        reply_numbers.append([r.created, r.pk])

    reply_numbers.sort(key=lambda l: l[0])

    i = 1
    pk_numbers = {}
    for r in reply_numbers:
        pk_numbers[r[1]] = i
        i += 1

    for r in replies:
        r.number = pk_numbers[r.id]

    for r in replies:
        try:
            r.parent_number = pk_numbers[r.parent.pk]
        except:
            r.parent_number = str(id)

    return render_to_response("forum/post.html", {
        'post': post,
        'replies': replies,
        'categories': Category.objects.all()
    }, context_instance=RequestContext(request))
开发者ID:Applied-GeoSolutions,项目名称:threadedforum,代码行数:66,代码来源:views.py

示例10: get

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
 def get(self, postid):
     Post.delete().where(Post.id == postid).execute()
     Tag.delete().where(Tag.post == postid).execute()
     self.redirect('/admin/posts')
     return
开发者ID:dengmin,项目名称:logpress-tornado,代码行数:7,代码来源:admin.py

示例11: post_del_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
def post_del_post(id):
    Post.delete().where(id=id).execute()
    redirect("/")
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:5,代码来源:blog.py

示例12: delete

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
 def delete(self):
     year, month, day, route = self._get_route_args()
     Post.delete(route)
     return HTTPFound(
         location=self.request.route_url('home'))
开发者ID:daymien,项目名称:pymyblog,代码行数:7,代码来源:views.py

示例13: delete_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
def delete_post(id):
    Post.delete(id)
开发者ID:IuryAlves,项目名称:pygame-site,代码行数:4,代码来源:usecase.py

示例14: editpost

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
def editpost(post_id=None):
    """show the edit page, update the post
    choice of editor:
        while editing an existing post, use post.editor as the editor
        editing a new post, use request.args["editor"] as the editor
    """
    if request.method == "GET":
        if post_id is not None:
            post = Post.get_by_id(post_id=post_id, public_only=False)
            editor = post.editor
            if not post:
                abort(404)
        else:
            post = Post()
            editor = request.args.get("editor", "markdown")

        return render_template('admin/editpost.html',
                               admin_url="post_" + editor,
                               post=post,
                               editor=editor)
    elif request.method == "POST":
        data = request.json
        now_time = datetime.now()
        if data['post_id'] is not None:
            post = Post.get_by_id(
                post_id=int(data["post_id"]),
                public_only=False)
        else:
            post = Post()
            post.create_time = now_time
        post.editor = data.get("editor", "markdown")
        post.update_time = now_time
        post.title = data.get("title", "")
        post.update_tags(data.get("tags", ""))
        post.url = data.get("url", "")
        post.keywords = data.get("keywords", "")
        post.metacontent = data.get("metacontent", "")
        post.content = data.get("content", "")
        post.raw_content = Post.gen_raw_content(post.content, post.editor)
        post.allow_comment = data.get("allow_comment", True)
        post.allow_visit = data.get("allow_visit", True)
        post.is_original = data.get("is_original", True)
        post.need_key = data.get("need_key", False)
        post.password = data.get("password", "")
        post.save()
        return jsonify(success=True,
                       post_id=post.post_id)

    elif request.method == "DELETE":
        # Delete post by id
        if post_id is not None:
            post = Post.get_by_id(int(post_id), public_only=False)
            if post:
                post.delete()
        # Batch Delete method
        else:
            removelist = request.json
            for post_id in removelist:
                post = Post.get_by_id(post_id=int(post_id), public_only=False)
                if post:
                    post.delete()
        return jsonify(success=True)
开发者ID:minyoad,项目名称:Tyou,代码行数:64,代码来源:admin.py

示例15: admin_delete_post_by_id

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import delete [as 别名]
def admin_delete_post_by_id(post_id):
    Post.delete(post_id)
    Comment.delete_by_post_id(post_id)
    posts = Post.query.all()
    return render_template('admin_posts.html', title='Admin', user=current_user, posts=posts)
开发者ID:FengNongtheWindCoder,项目名称:flaskblog,代码行数:7,代码来源:views.py


注:本文中的models.Post.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。