本文整理汇总了Python中models.Tags类的典型用法代码示例。如果您正苦于以下问题:Python Tags类的具体用法?Python Tags怎么用?Python Tags使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tags类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_modify_blog
def api_modify_blog(blog_id):
check_admin()
blog = Blogs.get(blog_id)
if not blog:
raise APIValueError(blog_id, 'blog is not exist.')
i= ctx.request.input(title='', tags='', content='')
title = i['title'].strip()
tags = i['tags'].strip()
content = i['content'].strip()
if not title:
raise APIValueError('title', 'title can not be empty.')
if not content:
raise APIValueError('content', 'content can not be empty.')
summary = _get_summary(content)
blog.title = title
blog.summary = summary
blog.content = content
blog.tags = tags
blog.update()
db.execute('delete from `tags` where `blog`=?', blog_id)
if tags:
for tag in tags.split(','):
tag = Tags(tag=tag, blog=blog_id)
tag.insert()
return dict(id=blog_id)
示例2: edit_post
def edit_post(id):
form = PostForm()
if users.is_current_user_admin() and form.validate_on_submit():
tags = Tags()
categories = Categories()
updating_post = BlogPost.get(int(id))
title = request.json['title']
body = request.json['body']
raw_category = request.json['category']
editing_tags = request.json['tags']
raw_summary = request.json['summary']
tags_keys = tags.update(editing_tags, updating_post)
category_key = categories.update(raw_category, updating_post.category)
updating_post.edit(title, body, datetime.now(), tags_keys,
category_key, raw_summary, raw_answers=request.json['answers'])
return jsonify(updating_post.to_json()) # dangerous
示例3: next
def next():
if request.method == "POST":
# TODO: helper
tags = set(map(unicode.lower, request.form.getlist("tags")))
Cluster.objects(pk=request.form["_id"]).update_one(
push__tags=ShredTags(
user=g.user.id,
tags=list(tags),
recognizable_chars=request.form.get("recognizable_chars", ""),
angle=int(request.form.get("angle", 0))),
inc__users_count=1,
add_to_set__users_processed=g.user.id)
User.objects(pk=g.user.id).update_one(
inc__processed=1, inc__tags_count=len(tags),
add_to_set__tags=list(tags))
session["processed"] = session.get("processed", 0) + 1
for tag in tags:
Tags.objects(pk=tag).update_one(
set_on_insert__is_base=False,
set_on_insert__created_by=g.user.id,
set_on_insert__created_at=Tags().created_at,
inc__usages=1,
add_to_set__shreds=request.form["_id"],
upsert=True)
start = datetime.strptime(request.form["tagging_start"],
'%Y-%m-%d %H:%M:%S.%f')
end = datetime.utcnow()
TaggingSpeed.objects.create(
user=g.user.id,
cluster=request.form["_id"],
tags_count=len(tags),
msec=(end - start).total_seconds() * 1000)
cluster = Cluster.next_for_user(g.user, app.config['USERS_PER_SHRED'])
auto_tags = cluster and cluster.get_auto_tags() or []
return render_template(
"_shred.html",
cluster=cluster,
auto_tags=auto_tags,
all_tags=get_tags(),
tagging_start=datetime.utcnow(),
# TODO: move to context processor
processed_per_session=session.get("processed", 0),
processed_total=User.objects(id=g.user.id).first()["processed"],
rating=list(User.objects.order_by(
"-processed").values_list("id")).index(g.user.id) + 1
)
示例4: _blog_fetch_callback
def _blog_fetch_callback(self, rpc):
content = rpc.get_result().content
d = feedparser.parse(StringIO(content))
s = Signatures.get_single()
signatures_and_times = dict(zip(s.hashes, s.times))
posts = []
tags_entity = Tags.get_single()
tags = set(tags_entity.available)
for entry in d['entries']:
blog_post = BlogPost.blog_post_from_feed_entry(entry)
signature_time = signatures_and_times.get(blog_post.signature)
if signature_time:
signature_time = datetime.datetime.fromtimestamp(signature_time).strftime('%m/%d/%Y %H:%M')
posts.append((blog_post, signature_time))
for tag in blog_post.tags:
tags.add(tag.lower())
template_values = {"posts":posts}
tags_entity.available = list(tags)
tags_entity.save()
template = jinja_environment.get_template('moderate.html')
self.response.out.write(template.render(template_values))
示例5: request_json
def request_json(**kwargs):
if request.json:
global r
r = Resource()
for k, v in kwargs.iteritems():
r.rid = v # Now automatically updated
r.title = request.json['title']
r.link = str(request.json['link'])
# Insert Tags to Tags Object
r.tags = []
for item in request.json['tags']:
t = Tags()
t.tag_name = item['tag_name']
r.tags.append(t)
r.description = request.json['description']
r.save(upsert=True)
示例6: tags_cloud
def tags_cloud():
'''Get dict of tags, numbers.'''
tags = Tags.all()
tags_dict = []
for tag in tags:
tags_dict.append({'name': tag.name, 'size': tag.count * 10})
return tags_dict
示例7: get_tag_synonyms
def get_tag_synonyms():
mapping = {}
for t in Tags.objects(synonyms__exists=True):
for s in t["synonyms"]:
mapping[s] = t["title"]
return mapping
示例8: next
def next():
if request.method == "POST":
tags = set(map(unicode.lower, request.form.getlist("tags")))
Shreds.objects(pk=request.form["_id"]).update_one(
push__tags=ShredTags(user=g.user.id, tags=list(tags),
recognizable_chars=request.form
.get("recognizable_chars", "")),
inc__users_count=1,
add_to_set__summarized_tags=list(tags),
add_to_set__users_processed=g.user.id)
User.objects(pk=g.user.id).update_one(
inc__processed=1, inc__tags_count=len(tags),
add_to_set__tags=list(tags))
session["processed"] = session.get("processed", 0) + 1
for tag in tags:
Tags.objects(pk=tag.capitalize()).update_one(
set_on_insert__is_base=False,
set_on_insert__created_by=g.user.id,
set_on_insert__created_at=Tags().created_at,
inc__usages=1,
add_to_set__shreds=request.form["_id"],
upsert=True)
start = datetime.strptime(request.form["tagging_start"],
'%Y-%m-%d %H:%M:%S.%f')
end = datetime.utcnow()
TaggingSpeed.objects.create(
user=g.user.id,
shred=request.form["_id"],
tags_count=len(tags),
msec=(end - start).total_seconds() * 1000)
shred = get_next_shred()
return render_template("shred.html",
shred=shred,
auto_tags=get_auto_tags(shred),
all_tags=get_tags(),
tagging_start=datetime.utcnow(),
processed_per_session=session.get("processed", 0),
processed_total=User.objects(id=g.user.id)\
.first()["processed"],
rating=list(User.objects.order_by("-processed")\
.values_list("id")).index(g.user.id) + 1
)
示例9: insert
def insert(request):
status=None
if request.method == 'POST':
# save new post
Usr_Name = request.POST.get('name','')
Usr_Mobile = request.POST.get('mobile','')
Usr_Remark = request.POST.get('remark','')
tags = request.POST.get('tags','')
pre_id = request.POST.get('pre_id','')
p_uuid = uuid.uuid1()
p = People(Usr_Name = Usr_Name,Usr_Mobile = Usr_Mobile,Usr_Remark=Usr_Remark,active = 0,isdel = 0,uuid = p_uuid,)
p.save()
for tag in tags.replace(u',',',').split(','):
try:
t = Tags.objects.get(tag = tag)
except Tags.DoesNotExist:
newtag = Tags(tag=tag)
newtag.save()
p.tags.add(newtag)
p.save()
else:
p.tags.add(t)
p.save()
if request.user.is_superuser:
status="ok"
p.Cluster_id = 0
p.save()
return render_to_response('usernet/index.html', {'status':status,},
context_instance=RequestContext(request))
if pre_id =='':
pre_id = request.user
if pre_id != '':
try:
pre = People.objects.filter(Usr_Mobile = pre_id,active = 1)
except People.DoesNotExist:
print "error"
else:
p.Prev_Usr=pre[0]
p.Cluster_id = pre[0].Cluster_id
p.save()
status="ok"
# Get all posts from DB
return render_to_response('usernet/index.html', {'status':status,},
context_instance=RequestContext(request))
示例10: get
def get(self):
tags = Tags.get_single()
template_values = {"tags_enabled":tags.enabled,
"tags_available":tags.available}
template = jinja_environment.get_template('tags.html')
self.response.out.write(template.render(template_values))
示例11: api_create_blog
def api_create_blog():
check_admin()
i= ctx.request.input(title='', tags='', content='')
title = i['title'].strip()
tags = i['tags'].strip()
content = i['content'].strip()
if not title:
raise APIValueError('title', 'title can not be empty.')
if not content:
raise APIValueError('content', 'content can not be empty.')
summary = _get_summary(content)
blog = Blogs(title=title, tags=tags, summary=summary, content=content)
id = blog.insert_id()
if tags:
for tag in tags.split(','):
tag = Tags(tag=tag, blog=id)
tag.insert()
return dict(id=id)
示例12: delete_post
def delete_post(id):
if users.is_current_user_admin():
posts = Posts()
tags = Tags()
categories = Categories()
updating_post = BlogPost.get(int(id))
categories.delete(updating_post.category)
posts.delete(updating_post.key)
tags.update(updating_post.get_tag_names())
return jsonify(msg="OK")
示例13: get
def get(self):
bm = Bookmarks.get_by_id(int(self.request.get('bm')))
tag = Tags.get_by_id(int(self.request.get('tag')))
# if users.get_current_user() == bm.user:
bm.tags.remove(tag.key)
bm.put()
template = jinja_environment.get_template('tags.html')
values = {'bm': bm}
tags = template.render(values)
self.response.write(tags)
示例14: import_tags
def import_tags(drop=False):
if drop:
Tags.objects(is_base=True).delete()
added = 0
updated = 0
with open("fixtures/base_tags.json", "r") as f:
tags = json.load(f)
for tag in tags:
_, created = Tags.objects.get_or_create(
title=tag["title"], defaults=tag)
if created:
added += 1
else:
updated += 1
Tags.ensure_index(["is_base", "usages", "category"])
return added, updated
示例15: rpc_get_indexes_for_tag
def rpc_get_indexes_for_tag(self, tag):
"""
Get search strings for the specified tag.
@argument tag
@returns
"""
indexes = Tags.get_indexes(tag)
if not indexes:
return {}
return indexes