本文整理汇总了Python中models.Post.create方法的典型用法代码示例。如果您正苦于以下问题:Python Post.create方法的具体用法?Python Post.create怎么用?Python Post.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_left_join
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def test_left_join(self):
User.create(name='jack', email='[email protected]')
User.create(name='amy', email='[email protected]')
Post.create(name='Hello world', user_id=1)
query = User.left_join(Post).select(User.name)
result = query.execute()
assert result.count == 2
示例2: test_right_join
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def test_right_join(self):
if db_type != 'sqlite': # sqlite3 current not support right join
User.create(name='jack', email='[email protected]')
User.create(name='amy', email='[email protected]')
Post.create(name='Hello world', user_id=1)
query = Post.right_join(User).select()
result = query.execute()
assert result.count == 2
示例3: posts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def posts():
if request.method == "GET":
return render_template('posts.html', posts=Post.query.all())
elif request.method == "POST":
title = request.form.get('title')
body = request.form.get('body')
user_id = 1 #ask how to get a handle on the logged in user id from here
Post.create(title, body, user_id)
return redirect('/posts')
示例4: create_data
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def create_data(self, count, table=None):
if table is 1: # only create data in table `user`
for i in range(1, count + 1):
User.create(name='name' + str(i), email='email' + str(i))
elif table is 2: # only create data in table `post`
for i in range(1, count + 1):
Post.create(name='name' + str(i), user_id=count + 1 - i)
else: # both, default
for i in range(1, count + 1):
User.create(name='name' + str(i), email='email' + str(i))
for i in range(1, count + 1):
Post.create(name='name' + str(i), user_id=count + 1 - i)
示例5: test_select
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def test_select(self):
assert User.create(name='jack', email='[email protected]')
assert User.create(name='amy', email='[email protected]')
assert Post.create(name='hello world!', user_id=1)
assert [('jack', 'hello world!')] == [
(user.name, post.name) for user, post in (User & Post).select()]
示例6: post_new_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def post_new_post():
title = request.forms.get('title').decode('utf-8')
slug = request.forms.get('slug').decode('utf-8')
post = request.forms.get('post')
tags = request.forms.get('tags').decode('utf-8')
category = request.forms.get('category').decode('utf-8')
post_type = request.forms.get('postype')
set_time = request.forms.get('setime')
if set_time != '1':
t = [int(tt) for tt in set_time.split('-')]
d = datetime.datetime(*t)
published = d
else:
published = datetime.datetime.now()
if post_type == 'HTML':
is_html = 1
content = post.decode('utf-8')
markdown = u'html'
else:
is_html = 0
markdown = post.decode('utf-8')
content = to_markdown(markdown)
category = Category.get(name=category)
post = Post.create(title=title, slug=slug.strip(), content=content,
markdown=markdown, tags=tags, category=category,
is_html=is_html, published=published, comm_count=0)
for tag in post.tags_list():
Tag.create(name=tag.strip(), post_id=post.id)
redirect("/%s" % slug)
示例7: create_data
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def create_data(self, count, table=None):
database.set_autocommit(False)
# lots of insert in a transaction
with database.transaction():
if table is 1: # only create data in table `user`
for i in range(1, count + 1):
User.create(name='name' + str(i), email='email' + str(i))
elif table is 2: # only create data in table `post`
for i in range(1, count + 1):
Post.create(name='name' + str(i), user_id=count + 1 - i)
else: # both, default
for i in range(1, count + 1):
User.create(name='name' + str(i), email='email' + str(i))
for i in range(1, count + 1):
Post.create(name='name' + str(i), user_id=count + 1 - i)
database.set_autocommit(True)
示例8: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def post(self):
raw = { field: self.request.get(field) for field in ['subject', 'content'] }
error, params = self.validate_post(**raw)
if error:
self.render('newpost.html', **params)
else:
p = Post.create(raw['subject'], raw['content'])
p.put()
self.redirect('/%s' % p.key().id())
示例9: create_posts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def create_posts(self):
sync_table(Post)
self.post1 = Post.create(
post_id=uuid.uuid1(),
blog_id='fdd0ba00-13b2-11e6-88a9-0002a5d5c51c',
created_at=datetime.now(),
post_title='I did it!',
content='Stuff goes in here',
tags=['Books', 'Movies', 'Audio']
)
self.post2 = Post.create(
post_id=uuid.uuid1(),
blog_id='fdd0ba00-13b2-11e6-88a9-0002a5d5c51c',
created_at=datetime.now(),
post_title='You did it!',
content='More stuff goes in here',
tags=set(['a', 'b', 'c', 'c'])
)
示例10: add_message
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def add_message():
"""Registers a new message for the user."""
if 'user_id' not in session:
abort(401)
if request.form['text']:
user_id = session['user_id']
text = request.form['text']
date = int(time.time())
Post.create(text=text, date=date, user_id=user_id)
"""
db = get_db()
db.execute('''insert into message (author_id, text, pub_date)
values (?, ?, ?)''', (session['user_id'], request.form['text'],
int(time.time())))
db.commit()
"""
flash('Your message was recorded')
return redirect(url_for('timeline'))
示例11: process_question
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def process_question():
"""Process the questions that user added, and updated the database"""
description = request.form.get('description')
file_name = request.files.get('fileupload_question')
text_option1 = request.form.get('option1')
text_option2 = request.form.get('option2')
fileupload1 = request.files.get('fileupload1')
fileupload2 = request.files.get('fileupload2')
print fileupload1, "this is file uploaded"
print type(fileupload1), "this is the type"
author_id = session['loggedin']
tags = request.form.get('hidden_tags')
print tags, "this is the tag passed in"
choice_data = [(text_option1, fileupload1), (text_option2, fileupload2)]
Post.create(author_id=author_id, description=description, tag_list=tags, choice_data=choice_data,
file_name=file_name)
flash('Your question has been posted')
return redirect(url_for('user_profile', user_id=author_id))
示例12: addpost
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def addpost():
form = addPostForm(request.form)
if request.method == 'POST' and form.validate():
post = Post.create(header=form.name.data,
text=form.text.data,
date=date.today(),
category=form.category.data)
return render_template('addpost.html', form=form,
posts=get_posts(),
recent_posts=get_posts(),
archives=get_archive())
示例13: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def post(self):
title = self.get_argument('title',None)
slug = self.get_argument('slug','')
category_id = self.get_argument('category',1)
content = self.get_argument('content','')
tag = self.get_argument('tag',None)
category = Category.get(id=int(category_id))
post = Post.create(title=title,category=category,slug=slug,content=content,tags=tag)
if tag:
for tag in post.taglist():
Tag.create(name=tag,post=post.id)
self.render('admin/post/add.html')
示例14: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def post(self):
form = PostForm()
if request.method == 'POST':
if form.validate_on_submit():
try:
post = Post.create()
form.populate_obj(post)
post.user = current_user
post.save()
flash(gettext('Post succesfully created'))
return redirect(url_for('PostsView:index'))
except:
flash(gettext('Error while creating the post'), 'error')
else:
flash(gettext('Invalid submission, please check the message below'), 'error')
return render_template('admin/posts/add.html',
title=gettext('Create Post'),
form=form)
示例15: _extract_posts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import create [as 别名]
def _extract_posts(zip_file):
md_files = md_parser.filter_markdown_files(zip_file.namelist())
for md_file in md_files:
with zip_file.open(md_file) as post:
metadata, content = md_parser.parse(post)
if metadata['publish']: yield Post.create(metadata, content)