本文整理汇总了Python中flask_security.current_user.id方法的典型用法代码示例。如果您正苦于以下问题:Python current_user.id方法的具体用法?Python current_user.id怎么用?Python current_user.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_security.current_user
的用法示例。
在下文中一共展示了current_user.id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inject_user_tags
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def inject_user_tags():
if not current_user.is_authenticated:
return {
"user_tags": None
}
else:
user_tags = Tag.query.filter(Tag.user == current_user.id,
Tag.count > 0).all()
user_tags.sort(key=lambda k: k.text.lower())
user_tags = [{'text': tag.text.encode('utf-8'),
'value': tag.text.encode('utf-8'),
'count': tag.count} for tag in user_tags if
tag.text != '']
return {
"user_tags": user_tags
}
示例2: bookmark_edit
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def bookmark_edit(bookmark_id=None):
if bookmark_id:
bookmark_id = hashids.decode(str(bookmark_id))[0] # Apparently, hashids.decode doesn't accept unicode input
bookmarkobj = _get_user_object_or_404(Bookmark,
bookmark_id,
current_user.id)
if bookmarkobj.tags:
bookmarkobj.tags_2 = ','.join(bookmarkobj.tags).encode('utf-8')
form = EditBookmarkForm(obj=bookmarkobj,
csrf_enabled=False)
if form.validate_on_submit():
bookmark.edit(id=bookmark_id,
title=form.title.data,
description=form.description.data,
tags=form.tags_1.data,
user_id=current_user.id)
return redirect(url_for('bookmark_list'))
return render_template("manager/bookmark_edit.html",
form=form,
bookmark_obj=bookmarkobj)
示例3: view
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def view(map_identifier, topic_identifier, association_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
association = topic_store.get_association(map_identifier, association_identifier)
return render_template("association/view.html", topic_map=topic_map, topic=topic, association=association,)
示例4: view_member
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def view_member(map_identifier, topic_identifier, association_identifier, member_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
association = topic_store.get_association(map_identifier, association_identifier)
member = association.get_member(member_identifier)
return render_template(
"association/view_member.html", topic_map=topic_map, topic=topic, association=association, member=member,
)
示例5: delete
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def delete(map_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
if not topic_map.owner:
abort(403)
if request.method == "POST":
# Remove map from topic store
topic_store.delete_topic_map(map_identifier, current_user.id)
# Delete the map's directory
topic_map_directory = os.path.join(bp.root_path, RESOURCES_DIRECTORY, str(map_identifier))
if os.path.isdir(topic_map_directory):
shutil.rmtree(topic_map_directory)
flash("Map successfully deleted.", "success")
return redirect(url_for("map.index"))
return render_template("map/delete.html", topic_map=topic_map)
示例6: post
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def post(self, id):
'''Add comment and optionally close an issue given its ID'''
issue = Issue.objects.get_or_404(id=id)
form = api.validate(IssueCommentForm)
message = Message(
content=form.comment.data,
posted_by=current_user.id
)
issue.discussion.append(message)
message_idx = len(issue.discussion) - 1
close = form.close.data
if close:
CloseIssuePermission(issue).test()
issue.closed_by = current_user._get_current_object()
issue.closed = datetime.now()
issue.save()
if close:
on_issue_closed.send(issue, message=message_idx)
else:
on_new_issue_comment.send(issue, message=message_idx)
return issue
示例7: post
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def post(self, id):
'''Add comment and optionally close a discussion given its ID'''
discussion = Discussion.objects.get_or_404(id=id)
form = api.validate(DiscussionCommentForm)
message = Message(
content=form.comment.data,
posted_by=current_user.id
)
discussion.discussion.append(message)
message_idx = len(discussion.discussion) - 1
close = form.close.data
if close:
CloseDiscussionPermission(discussion).test()
discussion.closed_by = current_user._get_current_object()
discussion.closed = datetime.now()
discussion.save()
if close:
on_discussion_closed.send(discussion, message=message_idx)
else:
on_new_discussion_comment.send(discussion, message=message_idx)
return discussion
示例8: _execute_task
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def _execute_task(execution_id, execution_parameters,
context, execution_creator, scheduled_time=None):
# Get the host ip info and return them
sm = get_storage_manager()
managers = sm.list(models.Manager)
context['rest_host'] = [manager.private_ip for manager in managers]
context['rest_token'] = execution_creator.get_auth_token()
context['tenant'] = _get_tenant_dict()
context['task_target'] = MGMTWORKER_QUEUE
execution_parameters['__cloudify_context'] = context
message = {
'cloudify_task': {'kwargs': execution_parameters},
'id': execution_id,
'dlx_id': None,
'execution_creator': current_user.id
}
if scheduled_time:
message_ttl = _get_time_to_live(scheduled_time)
message['dlx_id'] = execution_id
_send_task_to_dlx(message, message_ttl)
return
_send_mgmtworker_task(message)
示例9: stocks
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def stocks():
# We want the price of 5+ stocks
# http://finance.google.com/finance/info?client=ig&q=NASDAQ%3AAAPL,GOOG,MSFT,AMZN,TWTR
if Stock.query.first() is None:
print("No stock data found in DB")
request = requests.get('http://finance.google.com/finance/info?client=ig&q=NASDAQ%3AAAPL,GOOG,MSFT,AMZN,TWTR,EA,FB,NVDA,CSCO')
request.encoding = 'utf-8' # We need to change encoding as this API uses ISO and i use utf-8 everywhere else
o = request.text[4:] # The response object contains some characters at start that we cant parse. Trim these off
result = json.loads(o) # After we trim the characters, turn back into JSON
for i in result:
# Now! Thats what I call Pythonic
u = Stock(ticker=i['t'], last=i['l'], market=i['e'], timestamp=datetime.datetime.now())
db.session.add(u)
db.session.commit()
else:
print("Found stock data in DB")
# do something
# query db for stocks
Stocks = UserStocks.query.filter_by(id=current_user.id).all()
# pass into html using render_template
return render_template("stocks.html", Stocks=Stocks)
示例10: chart
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def chart():
labels = []
valuesAmount = []
valuesInEur = []
# valuesInGBP = []
valuesInUSD = []
valuesInCNY = []
Currencies = UserCurrency.query.filter_by(id=current_user.id).all()
for row in Currencies:
labels.append(row.ticker)
valuesAmount.append(row.amount)
valuesInEur.append(row.priceInEUR)
# valuesInGBP.append(row.priceInGBP)
valuesInUSD.append(row.priceInUSD)
valuesInCNY.append(row.priceInCHY)
print(len(valuesAmount))
colors = ["#F7464A", "#46BFBD", "#FDB45C", "#FEDCBA", "#ABCDEF", "#DDDDDD", "#ABCABC"]
return render_template('charts.html', set=list(zip(valuesAmount, valuesInEur, valuesInUSD, valuesInCNY, labels, colors)))
示例11: revert
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def revert(link):
""" the link to make the latest version the one selected.
"""
if wiki_for(link).locked and not current_user.has_role('admin'):
flash('Wiki page locked.')
return current_app.login_manager.unauthorized()
latest = request.args.get('latest', None)
if latest is not None:
oldone = wiki_for(link)
newone = (current_session
.query(Wiki)
.filter(Wiki.link == link)
.filter(Wiki.id == int(latest))
.first())
oldone.latest = 0
newone.latest = 1
current_session.add(newone)
current_session.add(oldone)
current_session.commit()
return redirect(url_for('wiki.index', link=link, id=newone.id))
else:
abort(404)
示例12: get_query
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def get_query(self):
if not current_user.has_role("package_admin"):
return (
super(VersionView, self)
.get_query()
.join(self.model.package)
.join(Package.maintainers)
.filter(User.id == current_user.id)
)
return super(VersionView, self).get_query()
示例13: get_count_query
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def get_count_query(self):
if not current_user.has_role("package_admin"):
return (
super(VersionView, self)
.get_count_query()
.join(self.model.package)
.join(Package.maintainers)
.filter(User.id == current_user.id)
)
return super(VersionView, self).get_count_query()
# Actions
示例14: settings
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def settings():
user_details = User.query.get(current_user.id)
bookmarks_per_page_form = PerPageForm(obj=user_details)
import_bookmark_file_form = BookmarkImportForm()
regenerate_api_key_form = RegenerateApiKeyForm()
change_password_form = ChangePasswordForm()
return render_template("manager/settings.html", per_page=bookmarks_per_page_form,
import_form=import_bookmark_file_form,
regenerate_api_key_form=regenerate_api_key_form,
change_password_form=change_password_form, user_api_key=user_details.api_key,
user_email=user_details.email)
示例15: bookmarks_per_page
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import id [as 别名]
def bookmarks_per_page():
form = PerPageForm(request.form)
if form.validate_on_submit():
bookmark.per_page(user_id=current_user.id, per_page=form.bookmarks_per_page.data)
return redirect(url_for('settings'))