本文整理汇总了Python中nereid.flash函数的典型用法代码示例。如果您正苦于以下问题:Python flash函数的具体用法?Python flash怎么用?Python flash使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: revenue_opportunity
def revenue_opportunity(self):
"""
Set the Conversion Probability and estimated revenue amount
"""
NereidUser = Pool().get('nereid.user')
nereid_user = NereidUser.search(
[('employee', '=', self.employee.id)], limit=1
)
if nereid_user:
employee = nereid_user[0]
else:
employee = None
if request.method == 'POST':
self.write([self], {
'probability': request.form['probability'],
'amount': Decimal(request.form.get('amount'))
})
flash('Lead has been updated.')
return redirect(
url_for('sale.opportunity.admin_lead', active_id=self.id)
+ "#tab-revenue"
)
return render_template(
'crm/admin-lead.jinja', lead=self, employee=employee,
)
示例2: get_linkedin_oauth_client
def get_linkedin_oauth_client(
self, scope='r_basicprofile,r_emailaddress',
token='linkedin_oauth_token'
):
"""Returns a instance of WebCollect
:param scope: Scope of information to be fetched from linkedin
:param token: Token for authentication
"""
if not all([self.linkedin_api_key, self.linkedin_api_secret]):
current_app.logger.error("LinkedIn api settings are missing")
flash(_("LinkedIn login is not available at the moment"))
return None
oauth = OAuth()
linkedin = oauth.remote_app(
'linkedin',
base_url='https://api.linkedin.com',
request_token_url='/uas/oauth/requestToken',
access_token_url='/uas/oauth/accessToken',
authorize_url='/uas/oauth/authenticate',
consumer_key=self.linkedin_api_key,
consumer_secret=self.linkedin_api_secret,
request_token_params={'scope': scope}
)
linkedin.tokengetter_func = lambda *a: session.get(token)
return linkedin
示例3: set_language
def set_language(self):
"""Sets the language in the session of the user. Also try to guess the
currency of the user, if not use the default currency of the website
Accepted Methods: GET, POST
Accepts XHR: Yes
The language has to be provided in the GET arguments of POST form. It
is more convenient to pass the language code than the id of the
language because it makes it more readable in URLs
"""
raise DeprecationWarning("Set language is deprecated")
lang_obj = Pool().get('ir.lang')
language = request.values.get('language')
exists = lang_obj.search([('code', '=', language)], limit=1)
if exists:
flash(_('Your language preference have been saved.'))
else:
flash(_('Sorry! we do not speak your language yet!'))
# redirect to the next url if given else take to home page
redirect_to = request.values.get('next')
if redirect_to:
redirect_to.replace(session['language'], language)
return redirect(
request.values.get('next', url_for('nereid.website.home'))
)
示例4: delete_from_cart
def delete_from_cart(cls, line):
"""
Delete a line from the cart. The required argument in POST is:
line_id : ID of the line
Response: 'OK' if X-HTTPRequest else redirect to shopping cart
"""
SaleLine = Pool().get('sale.line')
cart = cls.open_cart()
if not cart.sale:
abort(404)
try:
sale_line, = SaleLine.search([
('id', '=', line),
('sale', '=', cart.sale.id),
])
except ValueError:
message = 'Looks like the item is already deleted.'
else:
SaleLine.delete([sale_line])
message = 'The order item has been successfully removed.'
flash(_(message))
if request.is_xhr:
return jsonify(message=message)
return redirect(url_for('nereid.cart.view_cart'))
示例5: edit_post
def edit_post(self):
"""
Edit an existing post
"""
if self.nereid_user != request.nereid_user:
abort(404)
# Search for a post with same uri
post_form = BlogPostForm(request.form, obj=self)
with Transaction().set_context(blog_id=self.id):
if request.method == 'POST' and post_form.validate():
self.title = post_form.title.data
self.content = post_form.content.data
self.allow_guest_comments = post_form.allow_guest_comments.data
self.save()
flash('Your post has been updated.')
if request.is_xhr:
return jsonify(success=True, item=self.serialize())
return redirect(url_for(
'blog.post.render', user_id=self.nereid_user.id,
uri=self.uri
))
if request.is_xhr:
return jsonify(
success=request.method != 'POST', # False for POST, else True
errors=post_form.errors or None,
)
return render_template(
'blog_post_edit.jinja', form=post_form, post=self
)
示例6: get_facebook_oauth_client
def get_facebook_oauth_client(self, site=None):
"""Returns a instance of WebCollect
:param site: Browserecord of the website, If not specified, it will be
guessed from the request context
"""
if site is None:
site = request.nereid_website
if not all([site.facebook_app_id, site.facebook_app_secret]):
current_app.logger.error("Facebook api settings are missing")
flash(_("Facebook login is not available at the moment"))
return None
oauth = OAuth()
facebook = oauth.remote_app('facebook',
base_url='https://graph.facebook.com/',
request_token_url=None,
access_token_url='/oauth/access_token',
authorize_url='https://www.facebook.com/dialog/oauth',
consumer_key=site.facebook_app_id,
consumer_secret=site.facebook_app_secret,
request_token_params={'scope': 'email'}
)
facebook.tokengetter_func = lambda *a: session.get(
'facebook_oauth_token'
)
return facebook
示例7: change_password
def change_password(cls):
"""
Changes the password
.. tip::
On changing the password, the user is logged out and the login page
is thrown at the user
"""
form = ChangePasswordForm(request.form)
if request.method == 'POST' and form.validate():
if request.nereid_user.match_password(form.old_password.data):
cls.write(
[request.nereid_user],
{'password': form.password.data}
)
flash(
_('Your password has been successfully changed! '
'Please login again')
)
logout_user()
return redirect(url_for('nereid.website.login'))
else:
flash(_("The current password you entered is invalid"))
return render_template(
'change-password.jinja', change_password_form=form
)
示例8: github_authorized_login
def github_authorized_login(cls):
"""
Authorized handler to which github will redirect the user to
after the login attempt is made.
"""
github = request.nereid_website.get_github_oauth_client()
if github is None:
return redirect(
request.referrer or url_for('nereid.website.login')
)
try:
# The response is an oauth2 response with code. But Github API
# requires the
if 'oauth_verifier' in request.args:
data = github.handle_oauth1_response()
elif 'code' in request.args:
data = github.handle_oauth2_response()
else:
data = github.handle_unknown_response()
github.free_request_token()
except Exception, exc:
current_app.logger.error("Github login failed %s" % exc)
flash(_("We cannot talk to github at this time. Please try again"))
return redirect(
request.referrer or url_for('nereid.website.login')
)
示例9: remove_tag
def remove_tag(cls, task_id, tag_id):
"""
Assigns the provided to this task
:param task_id: ID of task
:param tag_id: ID of tag
"""
Activity = Pool().get("nereid.activity")
task = cls.get_task(task_id)
cls.write([task], {"tags": [("unlink", [tag_id])]})
Activity.create(
[
{
"actor": request.nereid_user.id,
"object_": "project.work, %d" % task.id,
"verb": "removed_tag_from_task",
"target": "project.work, %d" % task.parent.id,
"project": task.parent.id,
}
]
)
if request.method == "POST":
flash("Tag removed from task %s" % task.rec_name)
return redirect(request.referrer)
flash("Tag cannot be removed")
return redirect(request.referrer)
示例10: create_task
def create_task(self, project_id):
"""Create a new task for the specified project
POST will create a new task
"""
project = self.get_project(project_id)
# Check if user is among the participants
self.can_write(project, request.nereid_user)
if request.method == 'POST':
task_id = self.create({
'parent': project_id,
'name': request.form['name'],
'type': 'task',
'comment': request.form.get('description', False),
})
flash("Task successfully added to project %s" % project.name)
return redirect(
url_for('project.work.render_task',
project_id=project_id, task_id=task_id
)
)
flash("Could not create task. Try again.")
return redirect(request.referrer)
示例11: assign_task
def assign_task(self, task_id):
"""Assign task to a user
:param task_id: Id of Task
"""
nereid_user_obj = Pool().get('nereid.user')
task = self.get_task(task_id)
new_assignee = nereid_user_obj.browse(int(request.form['user']))
if self.can_write(task.parent, new_assignee):
self.write(task.id, {
'assigned_to': new_assignee.id
})
if request.is_xhr:
return jsonify({
'success': True,
})
flash("Task assigned to %s" % new_assignee.name)
return redirect(request.referrer)
flash("Only employees can be assigned to tasks.")
return redirect(request.referrer)
示例12: add
def add(cls):
"""
Adds a contact mechanism to the party's contact mechanisms
"""
form = cls.get_form()
if form.validate_on_submit():
cls.create(
[
{
"party": request.nereid_user.party.id,
"type": form.type.data,
"value": form.value.data,
"comment": form.comment.data,
}
]
)
if request.is_xhr:
return jsonify({"success": True})
return redirect(request.referrer)
if request.is_xhr:
return jsonify({"success": False})
else:
for field, messages in form.errors:
flash("<br>".join(messages), "Field %s" % field)
return redirect(request.referrer)
示例13: remove_tag
def remove_tag(cls, task_id, tag_id):
"""
Assigns the provided to this task
:param task_id: ID of task
:param tag_id: ID of tag
"""
Activity = Pool().get('nereid.activity')
task = cls.get_task(task_id)
cls.write(
[task], {'tags': [('remove', [tag_id])]}
)
Activity.create([{
'actor': request.nereid_user.id,
'object_': 'project.work, %d' % task.id,
'verb': 'removed_tag_from_task',
'target': 'project.work, %d' % task.parent.id,
'project': task.parent.id,
}])
if request.method == 'POST':
flash('Tag removed from task %s' % task.rec_name)
return redirect(request.referrer)
flash("Tag cannot be removed")
return redirect(request.referrer)
示例14: get_linkedin_oauth_client
def get_linkedin_oauth_client(self, site=None,
scope='r_basicprofile,r_emailaddress',
token='linkedin_oauth_token'):
"""Returns a instance of WebCollect
:param site: Browserecord of the website, If not specified, it will be
guessed from the request context
"""
if site is None:
site = request.nereid_website
if not all([site.linkedin_api_key, site.linkedin_api_secret]):
current_app.logger.error("LinkedIn api settings are missing")
flash(_("LinkedIn login is not available at the moment"))
return None
oauth = OAuth()
linkedin = oauth.remote_app('linkedin',
base_url='https://api.linkedin.com',
request_token_url='/uas/oauth/requestToken',
access_token_url='/uas/oauth/accessToken',
authorize_url='/uas/oauth/authenticate',
consumer_key=site.linkedin_api_key,
consumer_secret=site.linkedin_api_secret,
request_token_params={'scope': scope}
)
linkedin.tokengetter_func = lambda *a: session.get(token)
return linkedin
示例15: new_password
def new_password(self):
"""Create a new password
.. tip::
Unlike change password this does not demand the old password.
And hence this method will check in the session for a parameter
called allow_new_password which has to be True. This acts as a
security against attempts to POST to this method and changing
password.
The allow_new_password flag is popped on successful saving
This is intended to be used when a user requests for a password reset.
"""
form = NewPasswordForm(request.form)
if request.method == "POST" and form.validate():
if not session.get("allow_new_password", False):
current_app.logger.debug("New password not allowed in session")
abort(403)
self.write(request.nereid_user.id, {"password": form.password.data})
session.pop("allow_new_password")
flash(_("Your password has been successfully changed! " "Please login again"))
session.pop("user")
return redirect(url_for("nereid.website.login"))
return render_template("new-password.jinja", password_form=form)