本文整理汇总了Python中models.Post.tags方法的典型用法代码示例。如果您正苦于以下问题:Python Post.tags方法的具体用法?Python Post.tags怎么用?Python Post.tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.tags方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_form_operator
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [as 别名]
def post_form_operator(action, form, request, post_id = 0):
if action == 'add':
post = Post(user = request.user)
post.isdraft = True
post.text_raw = post.text_html = ''
post.tags_raw = form.cleaned_data['tags'].lower()
post.title = form.cleaned_data['title']
post.save()
if action == 'edit':
post = Post.objects.get(id__exact = post_id)
post.updated = datetime.now()
post.tags_raw = form.cleaned_data['tags'].lower()
post.title = form.cleaned_data['title']
post.text_raw = form.cleaned_data['text']
post.text_html = parse_text(post.text_raw, post.id)
post.tags = form.cleaned_data['tags'].lower()
post.save()
if action == 'edit':
messages.success(request,'Changes Saved')
return
else:
messages.success(request,'Saved in Drafts')
return post
示例2: store_new_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [as 别名]
def store_new_post(session, title, content, md, tags):
p = Post(title, content, md)
if not isinstance(tags, (list, tuple)):
tags = [tags]
def _get_tag_obj(tag):
t = session.query(Tag).filter(Tag.name == tag)
if t.count() > 0:
# this tag already exists, increase `posts_count`
t = t.one()
t.posts_count += 1
else:
# new tag
t = Tag(tag)
return t
tags = filter(lambda t: '#' not in t, tags)
p.tags = [_get_tag_obj(t) for t in tags]
code = base64.b64encode(os.urandom(64))
p.code = code
session.add(p)
session.commit()
return p
示例3: create_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [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)
示例4: add_initial_data
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [as 别名]
def add_initial_data():
"""Insert initial data into the database"""
# open database session
db_session = DB(db).get_session()
# ask user for an admin username and password
username = raw_input('Please enter the admin username: ')
password = getpass.getpass(prompt='Please enter the admin password: ')
# add user to database
u = User(username, encrypt_password(app.config['SECRET_KEY'], password))
db_session.add(u)
# create statuses
s1 = Status('draft')
s2 = Status('private')
s3 = Status('public')
db_session.add(s1)
db_session.add(s2)
db_session.add(s3)
# create formats
f = Format('rest')
f2 = Format('markdown')
db_session.add(f)
db_session.add(f2)
# Tags
t1 = Tag('imposter')
t2 = Tag('weblog')
# build initial post and put it in the database
initial_post_summary = """
Installed Correctly!
"""
initial_post_content = """
Imposter was installed correctly!
This is just a sample post to show Imposter works.
**Have a lot of fun blogging!**
"""
p1 = Post('Welcome to Imposter!', initial_post_summary, initial_post_content)
p1.slug = slugify(p1.title)
p1.createdate = datetime.now()
p1.lastmoddate = datetime.now()
p1.pubdate = datetime.now()
p1.format = f
p1.status = s3
p1.user = u
p1.tags = [t1, t2]
p1.compile()
db_session.add(p1)
db_session.commit()
示例5: create_tags_posts
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [as 别名]
def create_tags_posts(self):
post1 = Post(title='title one', content='content one', author_id=1, timezone=0)
post2 = Post(title='title two', content='content two', author_id=1, timezone=0)
post3 = Post(title='title three', content='content three', author_id=1, timezone=0)
post1.url = 'post_one'
post1.state_id = 2
post2.url = 'post_two'
post2.state_id = 1
post3.url = 'post_three'
tag_a = Tag(name='tag_a')
tag_b = Tag(name='tag_b')
post1.tags = [tag_a, tag_b]
post2.tags = [tag_a]
with self.get_context():
db.session.add(tag_a)
db.session.add(tag_b)
db.session.add(post1)
db.session.add(post2)
db.session.add(post3)
db.session.commit()
示例6: store_new_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [as 别名]
def store_new_post(session, title, content, tags):
p = Post(title, content)
if not isinstance(tags, (list, tuple)):
tags = [tags]
def _get_tag_obj(tag):
t = session.query(Tag).filter(Tag.name == tag)
if t.count() > 0:
# this tag already exists, increase `posts_count`
t = t.one()
t.posts_count += 1
else:
# new tag
t = Tag(tag)
return t
tags = filter(lambda t: "#" not in t, tags)
p.tags = [_get_tag_obj(t) for t in tags]
session.add(p)
示例7: save
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [as 别名]
def save(cls, request: Request, *args, **kwargs):
""" Метод для сохранения поста
:param request:
:param kwargs:
:return:
"""
if request.get("id", False):
post = blog.get_post(request.get("id"))
else:
post = Post()
post.title = request.get("title")
post.short = request.get("short")
post.imgs = request.get("imgs", [])
post.body = request.get("body", "")
post.tags = request.get("tags", [])
post.category = request.get("category", None)
post.draft = request.get("draft", True)
post.author_id = request.get("author_id", False)
post.author_name = request.get("author_name", False)
post.source = request.get("source", False)
return {"post_id": post.save()}
示例8: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [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)
示例9: save_post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [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
示例10: import_blog
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import tags [as 别名]
def import_blog():
f = request.files["file"]
try:
data = f.stream.read().decode("utf-8")
data = json.loads(data)
links = data.pop("links", [])
medias = data.pop("medias", [])
posts = data.pop("posts", [])
for link in links:
new_link = Link.get_by_href(link["href"])
if new_link:
continue
else:
new_link = Link()
for item in link:
new_link.__dict__[item] = link[item]
new_link.link_id = None
new_link.create_time = \
datetime.fromtimestamp(new_link.create_time)
new_link.save()
for media in medias:
new_media = Media.get_by_fileid(media["fileid"])
if new_media:
continue
else:
new_media = Media()
for item in media:
new_media.__dict__[item] = media[item]
# Notice, media id should not be set to None
new_media.media_id = None
new_media.create_time = \
datetime.fromtimestamp(new_media.create_time)
new_media.save()
for post in posts:
# If posts exist, continue
new_post = Post.get_by_url(post["url"], public_only=False)
if new_post:
continue
else:
new_post = Post()
for item in post:
new_post.__dict__[item] = post[item]
new_post.post_id = None
new_post.create_time = \
datetime.fromtimestamp(new_post.create_time)
new_post.update_time = \
datetime.fromtimestamp(new_post.update_time)
new_post.raw_content = re.sub('<[^<]+?>', "", new_post.content)
newtags = new_post.tags
new_post.tags = ""
new_post.update_tags(newtags)
new_post.save()
# Restore all posts
comments = post["commentlist"]
for comment in comments:
new_comment = Comment()
for item in comment:
new_comment.__dict__[item] = comment[item]
new_comment.post_id = new_post.post_id
new_comment.comment_id = None
new_comment.create_time = \
datetime.fromtimestamp(new_comment.create_time)
new_comment.save()
except Exception as e:
return str(e)
return "Done"