本文整理汇总了Python中flask.Markup.format方法的典型用法代码示例。如果您正苦于以下问题:Python Markup.format方法的具体用法?Python Markup.format怎么用?Python Markup.format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.Markup
的用法示例。
在下文中一共展示了Markup.format方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_announcement
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import format [as 别名]
def new_announcement():
"""Create new announcement."""
def respond():
response = dict(template='admin/new_announcement.html',
title=gettext("Write a new post"),
form=form)
return handle_content_type(response)
form = AnnouncementForm()
del form.id
# project_sanitized, owner_sanitized = sanitize_project_owner(project, owner, current_user)
if request.method != 'POST':
ensure_authorized_to('create', Announcement())
return respond()
if not form.validate():
flash(gettext('Please correct the errors'), 'error')
return respond()
announcement = Announcement(title=form.title.data,
body=form.body.data,
published=form.published.data,
media_url=form.media_url.data,
user_id=current_user.id)
ensure_authorized_to('create', announcement)
announcement_repo.save(announcement)
msg_1 = gettext('Annnouncement created!')
markup = Markup('<i class="icon-ok"></i> {}')
flash(markup.format(msg_1), 'success')
return redirect_content_type(url_for('admin.announcement'))
示例2: get_killmail_descriptions
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import format [as 别名]
def get_killmail_descriptions():
description = Markup(u"Acceptable Killmail Links:<ul>")
desc_entry = Markup(u"<li>{}</li>")
killmail_descs = [desc_entry.format(km.description) for km in\
current_app.killmail_sources]
description += Markup(u"").join(killmail_descs)
description += Markup(u"</ul>")
return description
示例3: index
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import format [as 别名]
def index():
li = Markup("""<li><a href="{}">{}</a></li>""")
results = db.metadata.tables.keys()
results.sort()
results = [li.format(url_for("app.view_table", table_name=tbl_name), tbl_name) for tbl_name in results]
results = Markup("<ul>") + Markup("\n").join(results) + Markup("</ul>")
return render_template("layout.html", content=results)
示例4: generate_links
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import format [as 别名]
def generate_links(query_list, model=None, model_key=None):
link = Markup("""<a href="{}">{}</a> - <a href="{}">Delete</a>""")
model_key = [key.key for key in model_key.columns][0]
for entry in query_list:
key = getattr(entry, model_key, 1)
name = model.__name__
edit_url = url_for('admin.edit', model_name=name, model_url_key=key)
delete_url = url_for('admin.delete', model_name=name, model_url_key=key)
yield link.format(edit_url, entry, delete_url)
示例5: delete_announcement
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import format [as 别名]
def delete_announcement(id):
announcement = announcement_repo.get_by(id=id)
if announcement is None:
raise abort(404)
ensure_authorized_to('delete', announcement)
announcement_repo.delete(announcement)
msg_1 = gettext('Announcement deleted!')
markup = Markup('<i class="icon-ok"></i> {}')
flash(markup.format(msg_1), 'success')
return redirect_content_type(url_for('admin.announcement'))
示例6: play
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import format [as 别名]
def play():
logged = False
user_log = ''
if (session):
if 'logged_in' not in session:
return redirect(url_for('login'))
else:
if session['logged_in']:
logged = True
user_log = Markup('<a class="nav-link" href="/profile"> Hello, {0} </a>'.format(session['user_name']))
else:
return redirect(url_for('login'))
else:
return redirect(url_for('login'))
difficulty = request.args.get("diff")
song_id = request.args.get("sg")
if not song_id or not difficulty:
# display error page
pass
song = get_song_details(song_id)
word_list = get_words_to_hide(song_id, int(difficulty))
song_tags = get_tags_for_song(song_id)
lyrics = song.lyrics.replace('\n', '<br>')
html_to_replace = Markup('<div class="form-group"> \
<div class="input-group"> \
<input type="text" id="{0}" class="missing-word form-control" size="{1}" maxlength="{1}" data-word="{3}"> \
<span class="glyphicon glyphicon-eye-open input-group-addon" data-toggle="tooltip" data-placement="bottom" aria-hidden="true" title="{2}"> \
</span> \
</div> \
</div>')
i = 0
for word in word_list:
hint = get_hint_for_word(word, int(difficulty))
lyrics, k = re.subn(r'\s({0})\s'.format(word),
html_to_replace.format("word-{0}".format(i), len(word) + 1, hint, word),
lyrics, count=max([1, int(difficulty) - 1]))
i += k
m, s = divmod(int(song.length), 60)
song_duration = "%02d:%02d" % (m, s)
video_url = song.video_url[song.video_url.index('v=') + 2:]
keep_ids, _ = get_user_keep(session['user_id'])
keep_next = get_next_keep(session['user_id'], song_id)
keep_count = get_keep_count_for_song(song_id)
play_count = get_play_count_for_song(song_id)
return render_template('play.html', logged_in=logged, profile_login=user_log, user_id=session['user_id'],
song_id=song_id, lyrics=lyrics,
song_tags=song_tags, song_artist=song.artist,
song_title=song.title, release_year=song.release_year, song_duration=song_duration,
video_url=video_url, num_of_words=i, difficulty=int(difficulty),
keep_ids=keep_ids, keep_next=keep_next, keep_count=keep_count, play_count=play_count)
示例7: update_announcement
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import format [as 别名]
def update_announcement(id):
announcement = announcement_repo.get_by(id=id)
if announcement is None:
raise abort(404)
def respond():
response = dict(template='admin/new_announcement.html',
title=gettext("Edit a post"),
form=form)
return handle_content_type(response)
form = AnnouncementForm()
if request.method != 'POST':
ensure_authorized_to('update', announcement)
form = AnnouncementForm(obj=announcement)
return respond()
if not form.validate():
flash(gettext('Please correct the errors'), 'error')
return respond()
ensure_authorized_to('update', announcement)
announcement = Announcement(id=form.id.data,
title=form.title.data,
body=form.body.data,
published=form.published.data,
media_url=form.media_url.data,
user_id=current_user.id)
announcement_repo.update(announcement)
msg_1 = gettext('Announcement updated!')
markup = Markup('<i class="icon-ok"></i> {}')
flash(markup.format(msg_1), 'success')
return redirect_content_type(url_for('admin.announcement'))
示例8: users
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import format [as 别名]
def users(user_id=None):
"""Manage users of PYBOSSA."""
form = SearchForm(request.body)
users = [user for user in user_repo.filter_by(admin=True)
if user.id != current_user.id]
if request.method == 'POST' and form.user.data:
query = form.user.data
found = [user for user in user_repo.search_by_name(query)
if user.id != current_user.id]
[ensure_authorized_to('update', found_user) for found_user in found]
if not found:
markup = Markup('<strong>{}</strong> {} <strong>{}</strong>')
flash(markup.format(gettext("Ooops!"),
gettext("We didn't find a user matching your query:"),
form.user.data))
response = dict(template='/admin/users.html', found=found, users=users,
title=gettext("Manage Admin Users"),
form=form)
return handle_content_type(response)
response = dict(template='/admin/users.html', found=[], users=users,
title=gettext("Manage Admin Users"), form=form)
return handle_content_type(response)
示例9: generate_pages
# 需要导入模块: from flask import Markup [as 别名]
# 或者: from flask.Markup import format [as 别名]
def generate_pages(current_page, num_of_pages,
search=None, showPaused=None, window=7):
"""
Generates the HTML for a paging component using a similar logic to the paging
auto-generated by Flask managed views. The paging component defines a number of
pages visible in the pager (window) and once the user goes to a page beyond the
largest visible, it would scroll to the right the page numbers and keeps the
current one in the middle of the pager component. When in the last pages,
the pages won't scroll and just keep moving until the last page. Pager also contains
<first, previous, ..., next, last> pages.
This component takes into account custom parameters such as search and showPaused,
which could be added to the pages link in order to maintain the state between
client and server. It also allows to make a bookmark on a specific paging state.
:param current_page:
the current page number, 0-indexed
:param num_of_pages:
the total number of pages
:param search:
the search query string, if any
:param showPaused:
false if paused dags will be hidden, otherwise true to show them
:param window:
the number of pages to be shown in the paging component (7 default)
:return:
the HTML string of the paging component
"""
void_link = 'javascript:void(0)'
first_node = Markup("""<li class="paginate_button {disabled}" id="dags_first">
<a href="{href_link}" aria-controls="dags" data-dt-idx="0" tabindex="0">«</a>
</li>""")
previous_node = Markup("""<li class="paginate_button previous {disabled}" id="dags_previous">
<a href="{href_link}" aria-controls="dags" data-dt-idx="0" tabindex="0"><</a>
</li>""")
next_node = Markup("""<li class="paginate_button next {disabled}" id="dags_next">
<a href="{href_link}" aria-controls="dags" data-dt-idx="3" tabindex="0">></a>
</li>""")
last_node = Markup("""<li class="paginate_button {disabled}" id="dags_last">
<a href="{href_link}" aria-controls="dags" data-dt-idx="3" tabindex="0">»</a>
</li>""")
page_node = Markup("""<li class="paginate_button {is_active}">
<a href="{href_link}" aria-controls="dags" data-dt-idx="2" tabindex="0">{page_num}</a>
</li>""")
output = [Markup('<ul class="pagination" style="margin-top:0px;">')]
is_disabled = 'disabled' if current_page <= 0 else ''
output.append(first_node.format(href_link="?{}"
.format(get_params(page=0,
search=search,
showPaused=showPaused)),
disabled=is_disabled))
page_link = void_link
if current_page > 0:
page_link = '?{}'.format(get_params(page=(current_page - 1),
search=search,
showPaused=showPaused))
output.append(previous_node.format(href_link=page_link,
disabled=is_disabled))
mid = int(window / 2)
last_page = num_of_pages - 1
if current_page <= mid or num_of_pages < window:
pages = [i for i in range(0, min(num_of_pages, window))]
elif mid < current_page < last_page - mid:
pages = [i for i in range(current_page - mid, current_page + mid + 1)]
else:
pages = [i for i in range(num_of_pages - window, last_page + 1)]
def is_current(current, page):
return page == current
for page in pages:
vals = {
'is_active': 'active' if is_current(current_page, page) else '',
'href_link': void_link if is_current(current_page, page)
else '?{}'.format(get_params(page=page,
search=search,
showPaused=showPaused)),
'page_num': page + 1
}
output.append(page_node.format(**vals))
is_disabled = 'disabled' if current_page >= num_of_pages - 1 else ''
page_link = (void_link if current_page >= num_of_pages - 1
else '?{}'.format(get_params(page=current_page + 1,
search=search,
showPaused=showPaused)))
output.append(next_node.format(href_link=page_link, disabled=is_disabled))
output.append(last_node.format(href_link="?{}"
.format(get_params(page=last_page,
#.........这里部分代码省略.........