本文整理汇总了Python中mediagoblin.messages.add_message函数的典型用法代码示例。如果您正苦于以下问题:Python add_message函数的具体用法?Python add_message怎么用?Python add_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_message函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: edit_blog_post
def edit_blog_post(request):
"""
First view for submitting a file.
"""
form = forms.BlogPostEditForm(request.form,
license=request.user.license_preference)
if request.method == 'POST' and form.validate():
media_type = 'blogpost'
entry = request.db.MediaEntry()
entry.media_type = unicode(media_type)
entry.title = unicode(form.title.data)
entry.description = unicode(form.description.data)
entry.license = unicode(form.license.data) or None
entry.uploader = request.user.id
entry.tags = convert_to_tag_list_of_dicts(form.tags.data)
entry.generate_slug()
entry.save()
add_message(request, SUCCESS, _('Woohoo! Submitted!'))
return redirect(request, "mediagoblin.plugins.blog.blog.view",
user=request.user.username)
return render_to_response(
request,
'blog/blogpost_edit.html',
{'form': form,
'app_config': mg_globals.app_config,
'user': request.user})
开发者ID:adviti,项目名称:mediagoblin,代码行数:33,代码来源:views.py
示例2: subscribe_comments
def subscribe_comments(request, media):
add_comment_subscription(request.user, media)
messages.add_message(request, messages.SUCCESS, _("Subscribed to comments on %s!") % media.title)
return redirect(request, location=media.url_for_self(request.urlgen))
开发者ID:vasilenkomike,项目名称:mediagoblin,代码行数:7,代码来源:views.py
示例3: register
def register(request):
"""The registration view.
Note that usernames will always be lowercased. Email domains are lowercased while
the first part remains case-sensitive.
"""
# Redirects to indexpage if registrations are disabled
if not mg_globals.app_config["allow_registration"]:
messages.add_message(
request,
messages.WARNING,
_('Sorry, registration is disabled on this instance.'))
return redirect(request, "index")
register_form = auth_forms.RegistrationForm(request.form)
if request.method == 'POST' and register_form.validate():
# TODO: Make sure the user doesn't exist already
users_with_username = User.query.filter_by(username=register_form.data['username']).count()
users_with_email = User.query.filter_by(email=register_form.data['email']).count()
extra_validation_passes = True
if users_with_username:
register_form.username.errors.append(
_(u'Sorry, a user with that name already exists.'))
extra_validation_passes = False
if users_with_email:
register_form.email.errors.append(
_(u'Sorry, a user with that email address already exists.'))
extra_validation_passes = False
if extra_validation_passes:
# Create the user
user = User()
user.username = register_form.data['username']
user.email = register_form.data['email']
user.pw_hash = auth_lib.bcrypt_gen_password_hash(
register_form.password.data)
user.verification_key = unicode(uuid.uuid4())
user.save()
# log the user in
request.session['user_id'] = unicode(user.id)
request.session.save()
# send verification email
email_debug_message(request)
send_verification_email(user, request)
# redirect the user to their homepage... there will be a
# message waiting for them to verify their email
return redirect(
request, 'mediagoblin.user_pages.user_home',
user=user.username)
return render_to_response(
request,
'mediagoblin/auth/register.html',
{'register_form': register_form})
开发者ID:praveen97uma,项目名称:goblin,代码行数:60,代码来源:views.py
示例4: register_client
def register_client(request):
'''
Register an OAuth client
'''
form = ClientRegistrationForm(request.form)
if request.method == 'POST' and form.validate():
client = OAuthClient()
client.name = unicode(request.form['name'])
client.description = unicode(request.form['description'])
client.type = unicode(request.form['type'])
client.owner_id = request.user.id
client.redirect_uri = unicode(request.form['redirect_uri'])
client.generate_identifier()
client.generate_secret()
client.save()
add_message(request, SUCCESS, _('The client {0} has been registered!')\
.format(
client.name))
return redirect(request, 'mediagoblin.plugins.oauth.list_clients')
return render_to_response(
request,
'oauth/client/register.html',
{'form': form})
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:29,代码来源:views.py
示例5: test_messages
def test_messages(test_app):
"""
Added messages should show up in the request.session,
fetched messages should be the same as the added ones,
and fetching should clear the message list.
"""
# Aquire a request object
test_app.get('/')
context = template.TEMPLATE_TEST_CONTEXT['mediagoblin/root.html']
request = context['request']
# The message queue should be empty
assert request.session.get('messages', []) == []
# First of all, we should clear the messages queue
messages.clear_add_message()
# Adding a message should modify the session accordingly
messages.add_message(request, 'herp_derp', 'First!')
test_msg_queue = [{'text': 'First!', 'level': 'herp_derp'}]
# Alternative tests to the following, test divided in two steps:
# assert request.session['messages'] == test_msg_queue
# 1. Tests if add_message worked
assert messages.ADD_MESSAGE_TEST[-1] == test_msg_queue
# 2. Tests if add_message updated session information
assert messages.ADD_MESSAGE_TEST[-1] == request.session['messages']
# fetch_messages should return and empty the queue
assert messages.fetch_messages(request) == test_msg_queue
assert request.session.get('messages') == []
开发者ID:RichoHan,项目名称:MediaGoblin,代码行数:30,代码来源:test_messages.py
示例6: _finish_verification
def _finish_verification(request):
"""
Complete OpenID Verification Process.
If the verification failed, will return false, otherwise, will return
the response
"""
c = consumer.Consumer(request.session, SQLAlchemyOpenIDStore())
# Check the response from the provider
response = c.complete(request.args, request.base_url)
if response.status == consumer.FAILURE:
messages.add_message(
request,
messages.WARNING,
_('Verification of %s failed: %s' %
(response.getDisplayIdentifier(), response.message)))
elif response.status == consumer.SUCCESS:
# Verification was successfull
return response
elif response.status == consumer.CANCEL:
# Verification canceled
messages.add_message(
request,
messages.WARNING,
_('Verification cancelled'))
return False
开发者ID:ausbin,项目名称:mediagoblin,代码行数:30,代码来源:views.py
示例7: edit_account
def edit_account(request):
user = request.user
form = forms.EditAccountForm(request.form,
wants_comment_notification=user.wants_comment_notification,
license_preference=user.license_preference,
wants_notifications=user.wants_notifications)
if request.method == 'POST' and form.validate():
user.wants_comment_notification = form.wants_comment_notification.data
user.wants_notifications = form.wants_notifications.data
user.license_preference = form.license_preference.data
user.save()
messages.add_message(request,
messages.SUCCESS,
_("Account settings saved"))
return redirect(request,
'mediagoblin.user_pages.user_home',
user=user.username)
return render_to_response(
request,
'mediagoblin/edit/edit_account.html',
{'user': user,
'form': form})
开发者ID:incorpusyehtee,项目名称:mediagoblin,代码行数:26,代码来源:views.py
示例8: deauthorize_applications
def deauthorize_applications(request):
""" Deauthroize OAuth applications """
if request.method == 'POST' and "application" in request.form:
token = request.form["application"]
access_token = AccessToken.query.filter_by(token=token).first()
if access_token is None:
messages.add_message(
request,
messages.ERROR,
_("Unknown application, not able to deauthorize")
)
else:
access_token.delete()
messages.add_message(
request,
messages.SUCCESS,
_("Application has been deauthorized")
)
access_tokens = AccessToken.query.filter_by(user=request.user.id)
applications = [(a.get_requesttoken, a) for a in access_tokens]
return render_to_response(
request,
'mediagoblin/edit/deauthorize_applications.html',
{'applications': applications}
)
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:27,代码来源:views.py
示例9: delete_account
def delete_account(request):
"""Delete a user completely"""
user = request.user
if request.method == 'POST':
if request.form.get(u'confirmed'):
# Form submitted and confirmed. Actually delete the user account
# Log out user and delete cookies etc.
# TODO: Should we be using MG.auth.views.py:logout for this?
request.session.delete()
# Delete user account and all related media files etc....
request.user.delete()
# We should send a message that the user has been deleted
# successfully. But we just deleted the session, so we
# can't...
return redirect(request, 'index')
else: # Did not check the confirmation box...
messages.add_message(
request, messages.WARNING,
_('You need to confirm the deletion of your account.'))
# No POST submission or not confirmed, just show page
return render_to_response(
request,
'mediagoblin/edit/delete_account.html',
{'user': user})
开发者ID:incorpusyehtee,项目名称:mediagoblin,代码行数:28,代码来源:views.py
示例10: media_post_comment
def media_post_comment(request, media):
"""
recieves POST from a MediaEntry() comment form, saves the comment.
"""
assert request.method == 'POST'
comment = request.db.MediaComment()
comment.media_entry = media.id
comment.author = request.user.id
comment.content = unicode(request.form['comment_content'])
if not comment.content.strip():
messages.add_message(
request,
messages.ERROR,
_("Oops, your comment was empty."))
else:
comment.save()
messages.add_message(
request, messages.SUCCESS,
_('Your comment has been posted!'))
media_uploader = media.get_uploader
#don't send email if you comment on your own post
if (comment.author != media_uploader and
media_uploader.wants_comment_notification):
send_comment_email(media_uploader, comment, media, request)
return redirect(request, location=media.url_for_self(request.urlgen))
开发者ID:orblivion,项目名称:mediagoblin-quickstart-openshift,代码行数:30,代码来源:views.py
示例11: change_pass
def change_pass(request):
form = auth_forms.ChangePassForm(request.form)
user = request.user
if request.method == 'POST' and form.validate():
if not tools.bcrypt_check_password(
form.old_password.data, user.pw_hash):
form.old_password.errors.append(
_('Wrong password'))
return render_to_response(
request,
'mediagoblin/plugins/recaptcha/change_pass.html',
{'form': form,
'user': user})
# Password matches
user.pw_hash = tools.bcrypt_gen_password_hash(
form.new_password.data)
user.save()
messages.add_message(
request, messages.SUCCESS,
_('Your password was changed successfully'))
return redirect(request, 'mediagoblin.edit.account')
return render_to_response(
request,
'mediagoblin/plugins/recaptcha/change_pass.html',
{'form': form,
'user': user})
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:33,代码来源:views.py
示例12: edit_account
def edit_account(request):
user = request.user
form = forms.EditAccountForm(
request.form,
wants_comment_notification=user.wants_comment_notification,
license_preference=user.license_preference,
)
if request.method == "POST":
form_validated = form.validate()
if form_validated and form.wants_comment_notification.validate(form):
user.wants_comment_notification = form.wants_comment_notification.data
if form_validated and form.new_password.data or form.old_password.data:
password_matches = auth_lib.bcrypt_check_password(form.old_password.data, user.pw_hash)
if password_matches:
# the entire form validates and the password matches
user.pw_hash = auth_lib.bcrypt_gen_password_hash(form.new_password.data)
else:
form.old_password.errors.append(_("Wrong password"))
if form_validated and form.license_preference.validate(form):
user.license_preference = form.license_preference.data
if form_validated and not form.errors:
user.save()
messages.add_message(request, messages.SUCCESS, _("Account settings saved"))
return redirect(request, "mediagoblin.user_pages.user_home", user=user.username)
return render_to_response(request, "mediagoblin/edit/edit_account.html", {"user": user, "form": form})
开发者ID:praveen97uma,项目名称:goblin,代码行数:31,代码来源:views.py
示例13: verify_email
def verify_email(request):
"""
Email verification view
validates GET parameters against database and unlocks the user account, if
you are lucky :)
"""
# If we don't have userid and token parameters, we can't do anything; 404
if not 'userid' in request.GET or not 'token' in request.GET:
return render_404(request)
user = request.db.User.find_one(
{'_id': ObjectId(unicode(request.GET['userid']))})
if user and user.verification_key == unicode(request.GET['token']):
user.status = u'active'
user.email_verified = True
user.verification_key = None
user.save()
messages.add_message(
request,
messages.SUCCESS,
_("Your email address has been verified. "
"You may now login, edit your profile, and submit images!"))
else:
messages.add_message(
request,
messages.ERROR,
_('The verification key or user id is incorrect'))
return redirect(
request, 'mediagoblin.user_pages.user_home',
user=user.username)
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:35,代码来源:views.py
示例14: edit_profile
def edit_profile(request, url_user=None):
# admins may edit any user profile
if request.user.username != url_user.username:
if not request.user.is_admin:
raise Forbidden(_("You can only edit your own profile."))
# No need to warn again if admin just submitted an edited profile
if request.method != "POST":
messages.add_message(
request, messages.WARNING, _("You are editing a user's profile. Proceed with caution.")
)
user = url_user
form = forms.EditProfileForm(request.form, url=user.url, bio=user.bio)
if request.method == "POST" and form.validate():
user.url = unicode(form.url.data)
user.bio = unicode(form.bio.data)
user.save()
messages.add_message(request, messages.SUCCESS, _("Profile changes saved"))
return redirect(request, "mediagoblin.user_pages.user_home", user=user.username)
return render_to_response(request, "mediagoblin/edit/edit_profile.html", {"user": user, "form": form})
开发者ID:praveen97uma,项目名称:goblin,代码行数:26,代码来源:views.py
示例15: register_client
def register_client(request):
'''
Register an OAuth client
'''
form = ClientRegistrationForm(request.form)
if request.method == 'POST' and form.validate():
client = OAuthClient()
client.name = six.text_type(form.name.data)
client.description = six.text_type(form.description.data)
client.type = six.text_type(form.type.data)
client.owner_id = request.user.id
client.redirect_uri = six.text_type(form.redirect_uri.data)
client.save()
add_message(request, SUCCESS, _('The client {0} has been registered!')\
.format(
client.name))
return redirect(request, 'mediagoblin.plugins.oauth.list_clients')
return render_to_response(
request,
'oauth/client/register.html',
{'form': form})
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:26,代码来源:views.py
示例16: add
def add(request):
if request.method == 'GET':
return redirect(request, 'mediagoblin.plugins.persona.edit')
email = _get_response(request)
if email:
query = PersonaUserEmails.query.filter_by(
persona_email=email
).first()
user_exists = query.user if query else None
if user_exists:
messages.add_message(
request,
messages.WARNING,
_('Sorry, an account is already registered with that Persona'
' email address.'))
return redirect(request, 'mediagoblin.plugins.persona.edit')
else:
# Save the Persona Email to the user
new_entry = PersonaUserEmails()
new_entry.persona_email = email
new_entry.user_id = request.user.id
new_entry.save()
messages.add_message(
request,
messages.SUCCESS,
_('Your Persona email address was saved successfully.'))
return redirect(request, 'mediagoblin.edit.account')
开发者ID:spaetz,项目名称:mediagoblin_blog,代码行数:33,代码来源:views.py
示例17: silence_comments
def silence_comments(request, media):
silence_comment_subscription(request.user, media)
messages.add_message(
request, messages.SUCCESS, _("You will not receive notifications for comments on" " %s.") % media.title
)
return redirect(request, location=media.url_for_self(request.urlgen))
开发者ID:vasilenkomike,项目名称:mediagoblin,代码行数:8,代码来源:views.py
示例18: wrapper
def wrapper(request, *args, **kwargs):
if not mgg.app.auth:
messages.add_message(
request,
messages.WARNING,
_('Sorry, authentication is disabled on this instance.'))
return redirect(request, 'index')
return controller(request, *args, **kwargs)
开发者ID:phaer,项目名称:mediagoblin,代码行数:9,代码来源:decorators.py
示例19: register
def register(request):
# if request.method == 'GET':
# return redirect(
# request,
# 'mediagoblin.plugins.recaptcha.register')
register_form = auth_forms.RegistrationForm(request.form)
config = pluginapi.get_config('mediagoblin.plugins.recaptcha')
recaptcha_protocol = ''
if config['RECAPTCHA_USE_SSL']:
recaptcha_protocol = 'https'
else:
recaptcha_protocol = 'http'
_log.debug("Connecting to reCAPTCHA service via %r", recaptcha_protocol)
if register_form.validate():
recaptcha_challenge = request.form['recaptcha_challenge_field']
recaptcha_response = request.form['recaptcha_response_field']
_log.debug("response field is: %r", recaptcha_response)
_log.debug("challenge field is: %r", recaptcha_challenge)
response = captcha.submit(
recaptcha_challenge,
recaptcha_response,
config.get('RECAPTCHA_PRIVATE_KEY'),
request.remote_addr,
)
goblin = response.is_valid
if response.error_code:
_log.warning("reCAPTCHA error: %r", response.error_code)
if goblin:
user = register_user(request, register_form)
if user:
# redirect the user to their homepage... there will be a
# message waiting for them to verify their email
return redirect(
request, 'mediagoblin.user_pages.user_home',
user=user.username)
else:
messages.add_message(
request,
messages.WARNING,
_('Sorry, captcha was incorrect. Please try again.'))
return render_to_response(
request,
'mediagoblin/plugins/recaptcha/register.html',
{'register_form': register_form,
'post_url': request.urlgen('mediagoblin.plugins.recaptcha.register'),
'recaptcha_public_key': config.get('RECAPTCHA_PUBLIC_KEY'),
'recaptcha_protocol' : recaptcha_protocol})
开发者ID:goblinrefuge,项目名称:goblinrefuge-mediagoblin,代码行数:55,代码来源:views.py
示例20: email_debug_message
def email_debug_message(request):
"""
If the server is running in email debug mode (which is
the current default), give a debug message to the user
so that they have an idea where to find their email.
"""
if mg_globals.app_config['email_debug_mode']:
# DEBUG message, no need to translate
messages.add_message(request, messages.DEBUG,
u"This instance is running in email debug mode. "
u"The email will be on the console of the server process.")
开发者ID:3rdwiki,项目名称:mediagoblin,代码行数:11,代码来源:views.py
注:本文中的mediagoblin.messages.add_message函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论