本文整理汇总了Python中models.Tag.slug方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.slug方法的具体用法?Python Tag.slug怎么用?Python Tag.slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tag
的用法示例。
在下文中一共展示了Tag.slug方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_tags
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import slug [as 别名]
def create_tags(self, tags, post_id):
post_tags = ''
if tags is str:
tags = tags.split(',')
tags = set(tags)
for tag in tags:
tag = tag.strip()
if not tag:
continue
the_tag = self.get_tag_by_title(tag)
if not the_tag:
the_tag = Tag()
the_tag.title = tag
the_tag.slug = tag
the_tag.post_count = 1
db.session.add(the_tag)
db.session.commit()
else:
the_tag.post_count += 1
if not the_tag.post_ids:
the_tag.post_ids = '%s' % post_id
else:
ids = the_tag.post_ids.split('|')
ids.append(str(post_id))
ids = list(set(ids))
the_tag.post_ids = '|'.join(ids)
db.session.add(the_tag)
if post_tags == '':
post_tags = '%s' % the_tag.id
else:
ids = post_tags.split('|')
ids.append(str(the_tag.id))
ids = list(set(ids))
post_tags = '|'.join(ids)
db.session.commit()
return post_tags
示例2: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import slug [as 别名]
def post(self):
json = {}
if not self.current_user:
json = {
'error': 1,
'msg': self._('Access denied')
}
self.write(json)
return
title = self.get_argument('title', None)
slug = self.get_argument('slug', None)
# valid arguments
if not title:
json = {
'error': 1,
'msg': self._('Title field can not be empty')
}
self.write(json)
return
elif self.get_tag_by_title(title):
json = {
'error': 1,
'msg': self._('Tag already exists')
}
self.write(json)
return
if not slug:
json = {
'error': 1,
'msg': self._('Slug field can not be empty')
}
self.write(json)
return
elif self.get_tag_by_slug(slug):
json = {
'error': 1,
'msg': self._('Slug already exists')
}
self.write(json)
return
# create tag
tag = Tag()
tag.title = title
tag.slug = slug
self.db.add(tag)
self.db.commit()
# delete cache
keys = ['TagCloud', 'SystemStatus']
self.cache.delete_multi(keys)
json = {
'error': 0,
'msg': self._('Successfully created'),
'tag': {
'id': tag.id,
'title': tag.title,
'slug': tag.slug,
'permalink': tag.permalink,
'post_count': tag.post_count
}
}
self.write(json)