本文整理汇总了Python中pybossa.util.handle_content_type函数的典型用法代码示例。如果您正苦于以下问题:Python handle_content_type函数的具体用法?Python handle_content_type怎么用?Python handle_content_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了handle_content_type函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: register
def register():
"""
Register method for creating a PYBOSSA account.
Returns a Jinja2 template
"""
if current_app.config.get('LDAP_HOST', False):
return abort(404)
form = RegisterForm(request.body)
msg = "I accept receiving emails from %s" % current_app.config.get('BRAND')
form.consent.label = msg
if request.method == 'POST' and form.validate():
account = dict(fullname=form.fullname.data, name=form.name.data,
email_addr=form.email_addr.data,
password=form.password.data,
consent=form.consent.data)
confirm_url = get_email_confirmation_url(account)
if current_app.config.get('ACCOUNT_CONFIRMATION_DISABLED'):
return _create_account(account)
msg = dict(subject='Welcome to %s!' % current_app.config.get('BRAND'),
recipients=[account['email_addr']],
body=render_template('/account/email/validate_account.md',
user=account, confirm_url=confirm_url))
msg['html'] = markdown(msg['body'])
mail_queue.enqueue(send_mail, msg)
data = dict(template='account/account_validation.html',
title=gettext("Account validation"),
status='sent')
return handle_content_type(data)
if request.method == 'POST' and not form.validate():
flash(gettext('Please correct the errors'), 'error')
data = dict(template='account/register.html',
title=gettext("Register"), form=form)
return handle_content_type(data)
开发者ID:fiorda,项目名称:pybossa,代码行数:35,代码来源:account.py
示例2: del_category
def del_category(id):
"""Delete a category."""
try:
category = project_repo.get_category(id)
if category:
if len(cached_cat.get_all()) > 1:
ensure_authorized_to('delete', category)
if request.method == 'GET':
response = dict(template='admin/del_category.html',
title=gettext('Delete Category'),
category=category,
form=dict(csrf=generate_csrf()))
return handle_content_type(response)
if request.method == 'POST':
project_repo.delete_category(category)
msg = gettext("Category deleted")
flash(msg, 'success')
cached_cat.reset()
return redirect_content_type(url_for(".categories"))
else:
msg = gettext('Sorry, it is not possible to delete the only'
' available category. You can modify it, '
' click the edit button')
flash(msg, 'warning')
return redirect_content_type(url_for('.categories'))
else:
abort(404)
except HTTPException:
raise
except Exception as e: # pragma: no cover
current_app.logger.error(e)
return abort(500)
开发者ID:fiorda,项目名称:pybossa,代码行数:32,代码来源:admin.py
示例3: tos
def tos():
"""Render help/terms-of-use page."""
cleaned_up_content = Document(render_template('help/tos.html')).summary()
response = dict(template='help/tos.html',
content=cleaned_up_content,
title='Help: Terms of Use')
return handle_content_type(response)
开发者ID:PyBossa,项目名称:pybossa,代码行数:7,代码来源:help.py
示例4: result
def result():
"""Render a results page."""
try:
response = dict(template="/home/_results.html")
return handle_content_type(response)
except TemplateNotFound:
return abort(404)
开发者ID:fiorda,项目名称:pybossa,代码行数:7,代码来源:home.py
示例5: cookies_policy
def cookies_policy():
"""Render help/cookies-policy page."""
cleaned_up_content = Document(render_template('help/cookies_policy.html')).summary()
response = dict(template='help/cookies_policy.html',
content=cleaned_up_content,
title='Help: Cookies Policy')
return handle_content_type(response)
开发者ID:PyBossa,项目名称:pybossa,代码行数:7,代码来源:help.py
示例6: forgot_password
def forgot_password():
"""
Request a forgotten password for a user.
Returns a Jinja2 template.
"""
form = ForgotPasswordForm(request.body)
if form.validate_on_submit():
user = user_repo.get_by(email_addr=form.email_addr.data)
if user and user.email_addr:
msg = dict(subject='Account Recovery',
recipients=[user.email_addr])
if user.twitter_user_id:
msg['body'] = render_template(
'/account/email/forgot_password_openid.md',
user=user, account_name='Twitter')
msg['html'] = render_template(
'/account/email/forgot_password_openid.html',
user=user, account_name='Twitter')
elif user.facebook_user_id:
msg['body'] = render_template(
'/account/email/forgot_password_openid.md',
user=user, account_name='Facebook')
msg['html'] = render_template(
'/account/email/forgot_password_openid.html',
user=user, account_name='Facebook')
elif user.google_user_id:
msg['body'] = render_template(
'/account/email/forgot_password_openid.md',
user=user, account_name='Google')
msg['html'] = render_template(
'/account/email/forgot_password_openid.html',
user=user, account_name='Google')
else:
userdict = {'user': user.name, 'password': user.passwd_hash}
key = signer.dumps(userdict, salt='password-reset')
recovery_url = url_for_app_type('.reset_password',
key=key, _external=True)
msg['body'] = render_template(
'/account/email/forgot_password.md',
user=user, recovery_url=recovery_url)
msg['html'] = render_template(
'/account/email/forgot_password.html',
user=user, recovery_url=recovery_url)
mail_queue.enqueue(send_mail, msg)
flash(gettext("We've sent you an email with account "
"recovery instructions!"),
'success')
else:
flash(gettext("We don't have this email in our records. "
"You may have signed up with a different "
"email or used Twitter, Facebook, or "
"Google to sign-in"), 'error')
if request.method == 'POST' and not form.validate():
flash(gettext('Something went wrong, please correct the errors on the '
'form'), 'error')
data = dict(template='/account/password_forgot.html',
form=form)
return handle_content_type(data)
开发者ID:fiorda,项目名称:pybossa,代码行数:60,代码来源:account.py
示例7: newsletter_subscribe
def newsletter_subscribe():
"""
Register method for subscribing user to PYBOSSA newsletter.
Returns a Jinja2 template
"""
# Save that we've prompted the user to sign up in the newsletter
if newsletter.is_initialized() and current_user.is_authenticated():
next_url = request.args.get('next') or url_for('home.home')
user = user_repo.get(current_user.id)
if current_user.newsletter_prompted is False:
user.newsletter_prompted = True
user_repo.update(user)
if request.args.get('subscribe') == 'True':
newsletter.subscribe_user(user)
flash("You are subscribed to our newsletter!", 'success')
return redirect_content_type(next_url)
elif request.args.get('subscribe') == 'False':
return redirect_content_type(next_url)
else:
response = dict(template='account/newsletter.html',
title=gettext("Subscribe to our Newsletter"),
next=next_url)
return handle_content_type(response)
else:
return abort(404)
开发者ID:keyinfluencerplus,项目名称:tinybee.ai,代码行数:27,代码来源:account.py
示例8: reset_password
def reset_password():
"""
Reset password method.
Returns a Jinja2 template.
"""
key = request.args.get('key')
if key is None:
abort(403)
userdict = {}
try:
timeout = current_app.config.get('ACCOUNT_LINK_EXPIRATION', 3600)
userdict = signer.loads(key, max_age=timeout, salt='password-reset')
except BadData:
abort(403)
username = userdict.get('user')
if not username or not userdict.get('password'):
abort(403)
user = user_repo.get_by_name(username)
if user.passwd_hash != userdict.get('password'):
abort(403)
form = ChangePasswordForm(request.body)
if form.validate_on_submit():
user.set_password(form.new_password.data)
user_repo.update(user)
flash(gettext('You reset your password successfully!'), 'success')
return _sign_in_user(user)
if request.method == 'POST' and not form.validate():
flash(gettext('Please correct the errors'), 'error')
response = dict(template='/account/password_reset.html', form=form)
return handle_content_type(response)
开发者ID:keyinfluencerplus,项目名称:tinybee.ai,代码行数:32,代码来源:account.py
示例9: _show_public_profile
def _show_public_profile(user, form):
user_dict = cached_users.public_get_user_summary(user.name)
projects_contributed = cached_users.public_projects_contributed_cached(user.id)
projects_created = cached_users.public_published_projects_cached(user.id)
can_update = False
if (user.restrict is False and
current_user.is_authenticated() and
current_user.admin):
draft_projects = cached_users.draft_projects(user.id)
projects_created.extend(draft_projects)
can_update = True
if user.restrict is False:
title = "%s · User Profile" % user_dict['fullname']
else:
title = "User data is restricted"
projects_contributed = []
projects_created = []
form = None
response = dict(template='/account/public_profile.html',
title=title,
user=user_dict,
projects=projects_contributed,
projects_created=projects_created,
form=form,
can_update=can_update,
input_form=False)
return handle_content_type(response)
开发者ID:PyBossa,项目名称:pybossa,代码行数:31,代码来源:account.py
示例10: index
def index(window=0):
"""Get the last activity from users and projects."""
if current_user.is_authenticated():
user_id = current_user.id
else:
user_id = None
if window >= 10:
window = 10
info = request.args.get('info')
leaderboards = current_app.config.get('LEADERBOARDS')
if info is not None:
if leaderboards is None or info not in leaderboards:
return abort(404)
top_users = cached_users.get_leaderboard(current_app.config['LEADERBOARD'],
user_id=user_id,
window=window,
info=info)
response = dict(template='/stats/index.html',
title="Community Leaderboard",
top_users=top_users)
return handle_content_type(response)
开发者ID:fiorda,项目名称:pybossa,代码行数:27,代码来源:leaderboard.py
示例11: privacy
def privacy():
"""Render help/privacy policy page."""
# use readability to remove styling and headers
cleaned_up_content = Document(render_template('help/privacy.html')).summary()
response = dict(template='help/privacy.html',
content=cleaned_up_content,
title='Privacy Policy')
return handle_content_type(response)
开发者ID:PyBossa,项目名称:pybossa,代码行数:8,代码来源:help.py
示例12: announcement
def announcement():
"""Manage anncounements."""
announcements = announcement_repo.get_all_announcements()
response = dict(template='admin/announcement.html',
title=gettext("Manage global Announcements"),
announcements=announcements,
csrf=generate_csrf())
return handle_content_type(response)
开发者ID:fiorda,项目名称:pybossa,代码行数:8,代码来源:admin.py
示例13: dashboard
def dashboard():
"""Show PYBOSSA Dashboard."""
try:
if request.args.get('refresh') == '1':
db_jobs = get_dashboard_jobs()
for j in db_jobs:
DASHBOARD_QUEUE.enqueue(j['name'])
msg = gettext('Dashboard jobs enqueued,'
' refresh page in a few minutes')
flash(msg)
active_users_last_week = dashb.format_users_week()
active_anon_last_week = dashb.format_anon_week()
draft_projects_last_week = dashb.format_draft_projects()
published_projects_last_week = dashb.format_published_projects()
update_projects_last_week = dashb.format_update_projects()
new_tasks_week = dashb.format_new_tasks()
new_task_runs_week = dashb.format_new_task_runs()
new_users_week = dashb.format_new_users()
returning_users_week = dashb.format_returning_users()
update_feed = get_update_feed()
response = dict(
template='admin/dashboard.html',
title=gettext('Dashboard'),
active_users_last_week=active_users_last_week,
active_anon_last_week=active_anon_last_week,
draft_projects_last_week=draft_projects_last_week,
published_projects_last_week=published_projects_last_week,
update_projects_last_week=update_projects_last_week,
new_tasks_week=new_tasks_week,
new_task_runs_week=new_task_runs_week,
new_users_week=new_users_week,
returning_users_week=returning_users_week,
update_feed=update_feed,
wait=False)
return handle_content_type(response)
except ProgrammingError as e:
response = dict(template='admin/dashboard.html',
title=gettext('Dashboard'),
wait=True)
return handle_content_type(response)
except Exception as e: # pragma: no cover
current_app.logger.error(e)
return abort(500)
开发者ID:fiorda,项目名称:pybossa,代码行数:44,代码来源:admin.py
示例14: index
def index():
"""Return Global Statistics for the site."""
title = "Global Statistics"
n_auth = site_stats.n_auth_users()
n_anon = site_stats.n_anon_users()
n_total_users = n_anon + n_auth
n_published_projects = cached_projects.n_published()
n_draft_projects = cached_projects.n_count('draft')
n_total_projects = n_published_projects + n_draft_projects
n_tasks = site_stats.n_tasks_site()
n_task_runs = site_stats.n_task_runs_site()
top5_projects_24_hours = site_stats.get_top5_projects_24_hours()
top5_users_24_hours = site_stats.get_top5_users_24_hours()
stats = dict(n_total_users=n_total_users, n_auth=n_auth, n_anon=n_anon,
n_published_projects=n_published_projects,
n_draft_projects=n_draft_projects,
n_total_projects=n_total_projects,
n_tasks=n_tasks,
n_task_runs=n_task_runs)
users = dict(label="User Statistics",
values=[
dict(label='Anonymous', value=[0, n_anon]),
dict(label='Authenticated', value=[0, n_auth])])
projects = dict(label="Projects Statistics",
values=[
dict(label='Published',
value=[0, n_published_projects]),
dict(label='Draft', value=[0, n_draft_projects])])
tasks = dict(label="Task and Task Run Statistics",
values=[
dict(label='Tasks', value=[0, n_tasks]),
dict(label='Answers', value=[1, n_task_runs])])
response = dict(template='/stats/global.html', title=title,
users=json.dumps(users),
projects=json.dumps(projects),
tasks=json.dumps(tasks),
show_locs=False,
top5_users_24_hours=top5_users_24_hours,
top5_projects_24_hours=top5_projects_24_hours,
stats=stats)
return handle_content_type(response)
开发者ID:PyBossa,项目名称:pybossa,代码行数:54,代码来源:stats.py
示例15: update_category
def update_category(id):
"""Update a category."""
try:
category = project_repo.get_category(id)
if category:
ensure_authorized_to('update', category)
form = CategoryForm(obj=category)
form.populate_obj(category)
if request.method == 'GET':
response = dict(template='admin/update_category.html',
title=gettext('Update Category'),
category=category,
form=form)
return handle_content_type(response)
if request.method == 'POST':
form = CategoryForm(request.body)
if form.validate():
slug = form.name.data.lower().replace(" ", "")
new_category = Category(id=form.id.data,
name=form.name.data,
short_name=slug)
project_repo.update_category(new_category)
cached_cat.reset()
msg = gettext("Category updated")
flash(msg, 'success')
return redirect_content_type(url_for(".categories"))
else:
msg = gettext("Please correct the errors")
flash(msg, 'success')
response = dict(template='admin/update_category.html',
title=gettext('Update Category'),
category=category,
form=form)
return handle_content_type(response)
else:
abort(404)
except HTTPException:
raise
except Exception as e: # pragma: no cover
current_app.logger.error(e)
return abort(500)
开发者ID:fiorda,项目名称:pybossa,代码行数:41,代码来源:admin.py
示例16: test_handle_content_type_json
def test_handle_content_type_json(self, mocklast, mockjsonify,
mockrender, mockrequest):
fake_d = {'Content-Type': 'application/json'}
mockrequest.headers.__getitem__.side_effect = fake_d.__getitem__
mockrequest.headers.get.side_effect = fake_d.get
mockrequest.headers.__iter__.side_effect = fake_d.__iter__
mockjsonify.side_effect = myjsonify
res = util.handle_content_type(dict(template='example.html'))
err_msg = "template key should exist"
assert res.get('template') == 'example.html', err_msg
err_msg = "jsonify should be called"
assert mockjsonify.called, err_msg
开发者ID:fiorda,项目名称:pybossa,代码行数:12,代码来源:test_util.py
示例17: api
def api():
"""Render help/api page."""
categories = cached_cat.get_used()
projects = cached_projects.get(categories[0]['short_name'])
if len(projects) > 0:
project_id = choice(projects)['id']
else: # pragma: no cover
project_id = None
response = dict(template='help/api.html',
title="Help: API",
project_id=project_id)
return handle_content_type(response)
开发者ID:PyBossa,项目名称:pybossa,代码行数:12,代码来源:help.py
示例18: home
def home():
"""Render home page with the cached projects and users."""
page = 1
per_page = current_app.config.get('APPS_PER_PAGE', 5)
# Add featured
tmp_projects = cached_projects.get_featured('featured', page, per_page)
if len(tmp_projects) > 0:
data = dict(featured=rank(tmp_projects))
else:
data = dict(featured=[])
response = dict(template='/home/index.html', **data)
return handle_content_type(response)
开发者ID:fiorda,项目名称:pybossa,代码行数:13,代码来源:home.py
示例19: users
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)
开发者ID:fiorda,项目名称:pybossa,代码行数:24,代码来源:admin.py
示例20: _show_own_profile
def _show_own_profile(user):
user_dict = cached_users.get_user_summary(user.name)
rank_and_score = cached_users.rank_and_score(user.id)
user.rank = rank_and_score['rank']
user.score = rank_and_score['score']
user.total = cached_users.get_total_users()
projects_contributed = cached_users.public_projects_contributed_cached(user.id)
projects_published, projects_draft = _get_user_projects(user.id)
cached_users.get_user_summary(user.name)
response = dict(template='account/profile.html', title=gettext("Profile"),
projects_contrib=projects_contributed,
projects_published=projects_published,
projects_draft=projects_draft,
user=user_dict)
return handle_content_type(response)
开发者ID:fiorda,项目名称:pybossa,代码行数:17,代码来源:account.py
注:本文中的pybossa.util.handle_content_type函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论