Python app.models 模块,Post() 实例源码

我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用app.models.Post()

项目:CivilServant    作者:mitmedialab    | 项目源码 | 文件源码
def archive_eligible_submissions(self, eligible_submissions):
        existing_post_ids = set([sub.id for sub in self.db_session.query(Post).filter(
            Post.id.in_(list(eligible_submissions.keys())))])

        # list of praw objects
        to_archive_posts = [eligible_submissions[sid] for sid in eligible_submissions if sid not in existing_post_ids]

        for post in to_archive_posts:
            post_info = post.json_dict if("json_dict" in dir(post)) else post['data'] ### TO HANDLE TEST FIXTURES
            new_post = Post(
                    id = post_info['id'],
                    subreddit_id = post_info['subreddit_id'].strip("t5_"), # janky
                    created = datetime.datetime.fromtimestamp(post_info['created_utc']),        
                    post_data = json.dumps(post_info))
            self.db_session.add(new_post)
        self.db_session.commit()
项目:website    作者:lasa    | 项目源码 | 文件源码
def new_post():
    form = NewPostForm()

    if form.validate_on_submit():
        data = {"title": form.title.data,
                "body": form.bodyhtml.data,
                "author": current_user.id_,
                "timestamp": datetime.datetime.now()}

        newpost = Post(**data)
        db.session.add(newpost)
        db.session.commit()
        time.sleep(0.5)
        return redirect("/news")

    return utils.render_with_navbar("post/form.html", form=form, heading="News Item")
项目:website    作者:lasa    | 项目源码 | 文件源码
def edit_post():
    postid = request.args.get("postid")
    if not postid:
        return redirect("/newpost")

    current_post = Post.query.filter_by(id_=postid).first()
    if not current_post:
        return redirect("/newpost")

    data = {"title": current_post.title,
            "body": current_post.body}

    form = NewPostForm(**data)

    if form.validate_on_submit():
        new_data = {"title": form.title.data,
                    "body": form.body.data}

        for key, value in new_data.items():
            setattr(current_post, key, value)
        db.session.commit()
        time.sleep(0.5)
        return redirect("/news?postid="+postid)

    return utils.render_with_navbar("post/form.html", form=form, heading="News Item")
项目:circleci-demo-python-flask    作者:CircleCI-Public    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Follow=Follow, Role=Role,
                Permission=Permission, Post=Post, Comment=Comment)
项目:Simpleblog    作者:Blackyukun    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Post=Post, \
                Follow=Follow, Permission=Permission, Admin=Admin)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Follow=Follow, Role=Role,
                Permission=Permission, Post=Post, Comment=Comment)
项目:smart-iiot    作者:quanpower    | 项目源码 | 文件源码
def make_shell_context():
    return dict(db=db, User=User, Follow=Follow, Role=Role,
                Permission=Permission, Post=Post, Comment=Comment)
项目:copyflask_web    作者:superchilli    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Permission=Permission,
                Post=Post)
项目:webapp    作者:superchilli    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Follow=Follow, Role=Role, Permission=Permission,
                Post=Post, Comment=Comment)
项目:project    作者:Junctionzc    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app = app, db = db, User = User, Role = Role, Post = Post)
项目:website    作者:lasa    | 项目源码 | 文件源码
def delete_post():
    postid = request.args.get("postid")
    if not postid:
        return redirect("/news")

    post = Post.query.filter_by(id_=postid)
    post.delete()
    db.session.commit()
    time.sleep(0.5)
    return redirect("/news")
项目:django-markdown-editor    作者:agusmakmun    | 项目源码 | 文件源码
def post_form_view(request):
    if request.method == 'POST':
        form = PostForm(request.POST)
        if form.is_valid():
            form.save()
            title = form.cleaned_data['title']
            return HttpResponse('%s successfully  saved!' % title)
    else:
        form = PostForm()
        context = {'form': form, 'title': 'Post Form'}
    return render(request, 'custom_form.html', context)
项目:django-markdown-editor    作者:agusmakmun    | 项目源码 | 文件源码
def test_markdownify(request):
    post = Post.objects.last()

    if post is not None:
        context = {'post': post}
    else:
        context = {
            'post': {
                'title': 'Fake Post',
                'description': """It **working**! :heart: [Python Learning](https://python.web.id)"""
            }
        }
    return render(request, 'test_markdownify.html', context)
项目:LivroFlask    作者:antoniocsz    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Follow=Follow, Role=Role, Permission=Permission, Post=Post, Comment=Comment)
项目:flask-blog    作者:zhuwei05    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role,
        Post=Post, Follow=Follow)
项目:flask_blog    作者:menghao2015    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Category=Category, Comment=Comment, Post=Post, Lable=Lable)
项目:Blog_Flask    作者:xiaohu2015    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Post=Post, Follow=Follow, Comment=Comment)
项目:blog    作者:hukaixuan    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Follow=Follow, Role=Role,
                Permission=Permission, Post=Post, Comment=Comment)
项目:Faiwong-s-blog    作者:Fai-Wong    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app, db=db, User=User, Role=Role, Follow = Follow,
                Permission=Permission, Post=Post, Comment=Comment, Category=Category)
项目:MyFlasky    作者:aliasxu    | 项目源码 | 文件源码
def make_shell_context():
    return dict(app=app,db=db,User=User,Role=Role,Permission=Permission,Post=Post,Follow=Follow)
项目:Flask_Bootstrap_Blog    作者:Tim9Liu9    | 项目源码 | 文件源码
def forged():
    from forgery_py import basic, lorem_ipsum, name, internet, date
    from random import randint

    db.drop_all()
    db.create_all()

    Role.seed()

    guests = Role.query.first()

    def generate_comment(func_author, func_post):
        return Comment(body=lorem_ipsum.paragraphs(),
                       created=date.date(past=True),
                       author=func_author(),
                       post=func_post())

    def generate_post(func_author):
        return Post(title=lorem_ipsum.title(),
                    body=lorem_ipsum.paragraphs(),
                    created=date.date(),
                    author=func_author())

    def generate_user():
        return User(name=internet.user_name(),
                    email=internet.email_address(),
                    password=basic.text(6, at_least=6, spaces=False),
                    role=guests)

    users = [generate_user() for i in range(0, 5)]
    db.session.add_all(users)

    random_user = lambda: users[randint(0, 4)]

    posts = [generate_post(random_user) for i in range(0, randint(50, 200))]
    db.session.add_all(posts)

    random_post = lambda: posts[randint(0, len(posts) - 1)]

    comments = [generate_comment(random_user, random_post) for i in range(0, randint(2, 100))]
    db.session.add_all(comments)

    db.session.commit()