本文整理汇总了Python中pybossa.util.handle_content_type函数的典型用法代码示例。如果您正苦于以下问题:Python handle_content_type函数的具体用法?Python handle_content_type怎么用?Python handle_content_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了handle_content_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)