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


Python Post.content方法代码示例

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


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

示例1: create_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
def create_post():
    form = forms.PostForm(request.form)
    if request.method=='POST':
        post = Post()
        post.title = form.title.data
        post.content = form.content.html
        post.toc = form.content.toc
        post.time_stamp = datetime.now()
        post.user_id = current_user.id

        tags = form.tags.data.split(',')
        post.tags = form.tags.data
        ids = []
        for tag in tags:
            t = Tag.query.filter_by(name=tag).first()
            if not t:
                db.session.add(Tag(name=tag))
                db.session.commit()
                t = Tag.query.filter_by(name=tag).first()
            ids.append(t.id)

        db.session.add(post)
        db.session.commit()
        p = current_user.posts.order_by(Post.id.desc()).first()
        for id in ids:
            db.session.add(TagMap(id,p.id))
        db.session.commit()
        #flash('Your post have been accepted.')
        return redirect(url_for('post',id=p.id))
    else:
        return render_template('create_post.html',form=form)
开发者ID:qinms,项目名称:BlogApp,代码行数:33,代码来源:views.py

示例2: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
 def post(self):
     p = Post()
     p.author = users.get_current_user()
     p.content = self.request.get('content')
     p.title = self.request.get('title')
     if self.request.get('is_published', None):
         p.is_published = True
     p.put()
     self.redirect('/admin/blog')
开发者ID:mdwrigh2,项目名称:cthaeh,代码行数:11,代码来源:admin_blog.py

示例3: add_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
def add_post(request):
    post_content = request.POST['post_content']
    post_topic = Topic.objects.get(id=request.POST['topic_id'])
    newPost = Post()
    newPost.author = request.user
    newPost.content = post_content
    newPost.topic = post_topic
    newPost.save()
    return redirect('topic-detail', topic_id=post_topic.id)
开发者ID:jakegny,项目名称:UdemyClasses,代码行数:11,代码来源:views.py

示例4: index

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
def index(request):
    if request.method == 'POST':
# save new post
	title = request.POST['title']
	content = request.POST['content']

	post = Post(title=title)
	post.last_update = datetime.datetime.now()
	post.content = content
	post.save()

# Get all posts from DB
    posts = Post.objects
    return render_to_response('index.html', {'Posts': posts}, context_instance=RequestContext(request))
开发者ID:sq08201329,项目名称:test_project,代码行数:16,代码来源:views.py

示例5: add

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
def add(request):
    if request.method == 'POST':
       # save new post
       title = request.POST['title']
       content = request.POST['content']
       post = Post(title=title)
       post.last_update = datetime.datetime.now() 
       post.content = content
       post.save()
       template = 'index.html'
    else :
        template='add.html'
    
    params = {'Posts': Post.objects}
    return render_to_response(template, params, context_instance=RequestContext(request))
开发者ID:vincentchivas,项目名称:authdesign,代码行数:17,代码来源:views.py

示例6: import_posts

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
def import_posts():
    from models import Post
    save_posts = []
    for entry in posts:
        post = Post()
        post.title = unicode(entry['title'])
        post.content = entry['content']
        post.when_published = entry['when_published']
        post.is_published = True
        post.place = "Mumbai"
        post.path = post.format_post_path()
        post.content_html = post.rendered
        post.checksum = post.hash
        save_posts.append(post)
    db.put(save_posts)
开发者ID:yesudeep,项目名称:greatshipgroup,代码行数:17,代码来源:initial_data.py

示例7: convert_to_entity

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
def convert_to_entity(json):
    if json['status'] != "publish" or json['slug'] == 'placeholder':
        return None
    post = Post(key=get_key(json['slug']))
    post.title = json['title']
    post.content = json['content'].replace("\n", "")
    date = json['modified']
    post.time_added = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
    if len(json['categories']) > 0:
        category = json['categories'][0]
        if category['parent'] != 8:
            return None
        key = categories.get_key(category['slug'])
        post.category = key
    else:
        return None
    date = json['date']
    post.date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
    return post
开发者ID:aapteedea,项目名称:shiloh-ranch,代码行数:21,代码来源:posts.py

示例8: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
    def post(self, title):
        if self.form.validate():
            post = None

            if self.form.post_id.data:
                post = yield Post.asyncQuery(id=self.form.post_id.data).first()
            if post:
                post.modified_time = datetime.datetime.utcnow()
            else:
                post = Post()
                post.create_time = \
                    self.BeiJing2UTCTime(self.form.create_time.data)

            title = self.form.title.data.replace(' ', '-')
            content = self.form.content.data
            markdown_text = self.form.markdown.data
            tags = self.separate_tags(self.form.tags.data)
            category_str = self.form.category.data.capitalize()
            category = yield Category.asyncQuery(
                name=category_str).first()
            if not category:
                category = Category()
                category.name = category_str
                yield category.save()

            post.title = title
            post.content = content
            post.markdown = markdown_text
            post.category = category
            post.tags = tags
            post.author = self.current_user

            yield post.save()
            self.flash("compose finsh!")
            return self.redirect('/blog')
        self.render("compose.html", form=self.form)
开发者ID:chinakyc,项目名称:blog,代码行数:38,代码来源:blog.py

示例9: rss_worker

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
def rss_worker(f):
    """RSS gevent worker function"""
    logging.info("Starting reader process for feed %s", f.id)

    id = f.id
    error_count = f.errors

    # Check ETag, Modified: Attempt Conditional HTTP retrieval
    # to reduce excessive polling
    if f.etag:
        d = feedparser.parse(f.url, etag=f.etag)
    elif f.last_modified:
        d = feedparser.parse(f.url, modified=f.last_modified)
    else:
        d = feedparser.parse(f.url)

    # Check returned HTTP status code
    if 'status' in d and d.status < 400:
        # Site appears to be UP
        logging.info("Feed %s is UP, status %s", f.url, str(d.status))

        # Reset error counter on successful connect
        if error_count > 0:
            q = Feed.update(errors=0).where(Feed.id == id)
            q.execute()

        # Get RSS/ATOM version number
        logging.info("Feed version: %s", d.version)

        # Catch status 301 Moved Permanently, update feed address
        if d.status == 301:
            q = Feed.update(url=d.href).where(Feed.id == id)
            q.execute()

        # Conditional HTTP:
        # Check for Etag in result and write to DB
        if 'etag' in d:
            logging.info("Etag: %s", d.etag)
            q = Feed.update(etag=d.etag).where(Feed.id == id)
            q.execute()

        # Conditional HTTP
        # Check for Last-Modified in result and write to DB
        if 'modified' in d:
            logging.info("Modified %s", d.modified)
            q = Feed.update(last_modified=d.modified).where(Feed.id == id)
            q.execute()

        # Check for feed modification date, write to DB
        if 'published' in d:
            logging.info("Published: %s", d.published)

        if 'updated' in d:
            logging.info("Updated: %s", d.updated)

        # Check for 'not-modified' status code, skip updates if found
        if d.status == 304:
            logging.info("Feed %s -- no updates found, skipping", f.url)
            return

        # If post entries exist, process them
        for post in d.entries:

            post_content = ""
            post_title = post.get('title', 'No title')

            h = html.parser.HTMLParser()
            desc = post.get('description', '')
            desc = h.unescape(desc) # unescape HTML entities
            post_description = re.sub(r'<[^>]*?>', '', desc) # crudely strip HTML tags in description

            post_published = arrow.get(post.get('published_parsed')) or arrow.now()
            if 'content' in post:
                post_content = post.content[0].value
            post_link = post.get('link', '')

            # Get post checksum (title + description + link url)
            check_string = (post_title + post_description + post_link).encode('utf8')
            post_checksum = hashlib.sha224(check_string).hexdigest()

            # If post checksum not found in DB, add post
            if Post.select().where(Post.md5 == post_checksum).count() == 0:
                p = Post()
                p.title = post_title
                p.description = post_description
                p.published = post_published.datetime  # convert from Arrow to datetime for DB
                p.content = post_content
                p.link = post_link
                p.feed = id
                p.md5 = post_checksum
                p.save()

            # TODO: Filter text for dangerous content (e.g. XSRF?)
            # Feedparser already does this to some extent

            # TODO: Spawn websocket message with new posts for web client

    else:
        # Site appears to be down

#.........这里部分代码省略.........
开发者ID:KyubiSystems,项目名称:Wisewolf,代码行数:103,代码来源:server.py

示例10: post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
    def post(self):
        """
        Create new post
        """
        json = {}
        if not self.current_user:
            json = {
                'error': 1,
                'msg': self._('Access denied')
            }
            self.write(json)
            return
        type = self.get_argument('type', Post.TYPE_POST)
        title = self.get_argument('title', None)
        content = self.get_argument('content', '')
        slug = self.get_argument('slug', None)
        format = self.get_argument('format', 'standard')
        excerpt = self.get_argument('excerpt', '')
        thumbnail = self.get_argument('thumbnail', '')
        category_id = self.get_argument('category', None)
        tags = self.get_argument('tags', '')
        date = self.get_argument('date', None)
        comment_open = bool(int(self.get_argument('comment_open', '1')))
        if type not in [Post.TYPE_POST, Post.TYPE_PAGE]:
            type = Post.TYPE_POST
        if format not in ['standard', 'aside', 'gallery', 'link', 'image', 'quote', 'status', 'video', 'audio', 'chat']:
            format = 'standard'
        # valid arguments
        if not slug:
            json = {
                'error': 1,
                'msg': self._('Slug field can not be empty')
            }
            self.write(json)
            return
        elif self.get_post_by_slug(slug):
            json = {
                'error': 1,
                'msg': self._('Slug already exists')
            }
            self.write(json)
            return
        if type == Post.TYPE_POST and not category_id:
            json = {
                'error': 1,
                'msg': self._('Category field can not be empty')
            }
            self.write(json)
            return
        if type == Post.TYPE_POST:
            category = self.get_category_by_id(category_id)
            if not category:
                json = {
                    'error': 1,
                    'msg': self._('No such category')
                }
                self.write(json)
                return
        if date:
            if validators.date(date):
                date = datetime.strptime(date, '%Y-%m-%d')
            elif validators.datetime(date):
                date = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
            else:
                date = datetime.utcnow()
        else:
            date = datetime.utcnow()
        # now create post
        post = Post()
        post.type = type
        post.created = date
        post.title = title
        post.slug = slug
        post.content = content
        post.html = wrap_content(content)
        post.format = format
        post.excerpt = excerpt
        post.thumbnail = thumbnail
        post.comment_open = comment_open
        if type == Post.TYPE_POST:
            post.category_id = category.id
        else:
            post.category_id = 1  # default category
        # update category post count
        if type == Post.TYPE_POST:
            category.post_count += 1
            self.db.add(category)
        # commit
        self.db.add(post)
        self.db.commit()
        # create tags
        if type == Post.TYPE_POST and tags:
            post.tag_ids = self.create_tags(tags.split(','), post.id)
            self.db.add(post)
            self.db.commit()
        # delete cache
        keys = ['PostList:1', 'CategoryPostList:%s:1' %
                category.id, 'SystemStatus', 'ArchiveHTML', 'TagCloud']
        self.cache.delete_multi(keys)

#.........这里部分代码省略.........
开发者ID:messense,项目名称:YaBlog,代码行数:103,代码来源:api.py

示例11: save_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
def save_post():
	try:
		# print "RECEBIDO", request.form
		title = request.form['title']
		content = request.form['content']
		featured = 'N'
		if "featured" in request.form:
			featured = 'Y'
			#Limpa o cache para atualizar na proxima chamada da capa.
			#cache.delete("featured_posts")
			print "FEATURED POST"
		resume = request.form['resume']
		slug = request.form['slug']
		tags = request.form['tags']

		add = False
		if 'id' in request.form:
			post = Post.query.get(request.form['id'])
			cache.delete('view-post-%s' % slug) #Remove this post from cache for update in next view
		else:
			add =  True
			post = Post()
			post.date_created = datetime.today()
			post.short_url = util.encurtar(url_for('blog.view_post',  slug=slug))

		post.title = title
		post.content = content
		post.resume = resume
		post.featured = featured
		post.slug = slug
		post.date_updated = datetime.today()
		#post.picture = '' #don't clear this field if edit
		post.tags = tags

		try:
			global uploaded_files
			photo = request.files.get('postfile')
			if photo:
				print "SALVANDO A IMAGEM DO POST"
				filename = uploaded_files.save(photo)
				post.picture = uploaded_files.path(filename)
				post.picture_url = uploaded_files.url(filename)
				#print 'UPLOADED:', uploaded_files.path(filename)

				#Gerar um thumbnail para mostrar dentro do post
				#200x150 - Dentro do post
				#220x100 - Lista de posts
			else:
				print "POST SEM IMAGEM"

		except UploadNotAllowed:
			flash("The upload was not allowed")

		if add:
			db.session.add(post)
		else:
			db.session.merge(post)
		db.session.commit()
		# flash('Post salvo com sucesso')
		# return redirect(url_for('blog.view_post',  slug=slug))

		data = {}
		data['message'] = "Post salvo com sucesso! <a href='%s'>Visualizar</a>" % url_for('blog.view_post',  slug=slug)
		data['id'] = post.id
		return jsonify(data)

	except IntegrityError as e:
		db.session.rollback()
		data = {}
		data['message'] = "O Slug informado ja existe. Altere e tente novamente."
		return jsonify(data)
	except:
		db.session.rollback()
		print "Unexpected error:", sys.exc_info()[0]
    	raise
开发者ID:berlotto,项目名称:asciiblog,代码行数:77,代码来源:__init__.py

示例12: make_post

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [as 别名]
def make_post(request, board_id):
  post = Post()
  post.board = get_object_or_404(Board, pk=board_id)
  post.content = request.POST['content']
  post.save()
  return redirect('/show_board/%s' % board_id)
开发者ID:wcauchois,项目名称:privy,代码行数:8,代码来源:views.py

示例13: editpost

# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import content [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


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