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


Python Post.create方法代码示例

本文整理汇总了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
开发者ID:bopo,项目名称:skylark,代码行数:9,代码来源:tests.py

示例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
开发者ID:bopo,项目名称:skylark,代码行数:10,代码来源:tests.py

示例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')
开发者ID:north-bay,项目名称:internets,代码行数:11,代码来源:app.py

示例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)
开发者ID:zhangjinglei,项目名称:skylark,代码行数:14,代码来源:tests.py

示例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()]
开发者ID:bopo,项目名称:skylark,代码行数:9,代码来源:tests.py

示例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)
开发者ID:iTriumph,项目名称:MiniAkio,代码行数:32,代码来源:blog.py

示例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)
开发者ID:bopo,项目名称:skylark,代码行数:18,代码来源:tests.py

示例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())
开发者ID:vcelis,项目名称:cs253,代码行数:11,代码来源:handlers.py

示例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'])
     )
开发者ID:WilliamQLiu,项目名称:django-cassandra-prototype,代码行数:20,代码来源:queries.py

示例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'))
开发者ID:karoon,项目名称:twitter-flask-neo4j,代码行数:22,代码来源:minitwit.py

示例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))
开发者ID:PeggyZheng,项目名称:Opinionated,代码行数:23,代码来源:server.py

示例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())
开发者ID:Zenext,项目名称:Personal-Blog,代码行数:14,代码来源:app.py

示例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')
开发者ID:940825,项目名称:logpress-tornado,代码行数:16,代码来源:admin.py

示例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)
开发者ID:Tibodef,项目名称:PythonBlog,代码行数:21,代码来源:views.py

示例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) 
开发者ID:runway7,项目名称:beacon.old,代码行数:8,代码来源:main.py


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