我们从Python开源项目中,提取了以下21个代码示例,用于说明如何使用app.models.Post()。
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()
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")
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")
def make_shell_context(): return dict(app=app, db=db, User=User, Follow=Follow, Role=Role, Permission=Permission, Post=Post, Comment=Comment)
def make_shell_context(): return dict(app=app, db=db, User=User, Role=Role, Post=Post, \ Follow=Follow, Permission=Permission, Admin=Admin)
def make_shell_context(): return dict(db=db, User=User, Follow=Follow, Role=Role, Permission=Permission, Post=Post, Comment=Comment)
def make_shell_context(): return dict(app=app, db=db, User=User, Role=Role, Permission=Permission, Post=Post)
def make_shell_context(): return dict(app = app, db = db, User = User, Role = Role, Post = Post)
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")
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)
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)
def make_shell_context(): return dict(app=app, db=db, User=User, Role=Role, Post=Post, Follow=Follow)
def make_shell_context(): return dict(app=app, db=db, User=User, Role=Role, Category=Category, Comment=Comment, Post=Post, Lable=Lable)
def make_shell_context(): return dict(app=app, db=db, User=User, Role=Role, Post=Post, Follow=Follow, Comment=Comment)
def make_shell_context(): return dict(app=app, db=db, User=User, Role=Role, Follow = Follow, Permission=Permission, Post=Post, Comment=Comment, Category=Category)
def make_shell_context(): return dict(app=app,db=db,User=User,Role=Role,Permission=Permission,Post=Post,Follow=Follow)
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()