本文整理汇总了Python中nereid.abort函数的典型用法代码示例。如果您正苦于以下问题:Python abort函数的具体用法?Python abort怎么用?Python abort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了abort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_comment
def update_comment(self, task_id, comment_id):
"""
Update a specific comment.
"""
project_obj = Pool().get('project.work')
nereid_user_obj = Pool().get('nereid.user')
# allow modification only if the user is an admin or the author of
# this ticket
task = project_obj.browse(task_id)
comment = self.browse(comment_id)
assert task.type == "task"
assert comment.project.id == task.id
# Allow only admins and author of this comment to edit it
if nereid_user_obj.is_project_admin(request.nereid_user) or \
comment.updated_by == request.nereid_user:
self.write(comment_id, {'comment': request.form['comment']})
else:
abort(403)
if request.is_xhr:
comment_record = self.browse(comment_id)
html = render_template('comment.jinja', comment=comment_record)
return jsonify({
'success': True,
'html': html,
'state': project_obj.browse(task.id).state,
})
return redirect(request.referrer)
示例2: download_file
def download_file(self, attachment_id):
"""
Returns the file for download. The wonership of the task or the
project is checked automatically.
"""
attachment_obj = Pool().get('ir.attachment')
work = None
if request.args.get('project', None):
work = self.get_project(request.args.get('project', type=int))
if request.args.get('task', None):
work = self.get_task(request.args.get('task', type=int))
if not work:
# Neither task, nor the project is specified
raise abort(404)
attachment_ids = attachment_obj.search([
('id', '=', attachment_id),
('resource', '=', '%s,%d' % (self._name, work.id))
])
if not attachment_ids:
raise abort(404)
attachment = attachment_obj.browse(attachment_ids[0])
with tempfile.NamedTemporaryFile(delete=False) as f:
f.write(attachment.data)
return send_file(
f.name, attachment_filename=attachment.name, as_attachment=True
)
示例3: render
def render(self, post_id):
"Render the blog post"
post = self.browse(post_id)
if not post:
abort(404)
return render_template('blog_post.jinja', post=post)
示例4: render
def render(self, slug=None, page=1):
"""
Renders a page of products in the tree and all of its branches
:param slug: slug of the browse node to be shown
:param page: page of the products to be displayed
"""
Product = Pool().get('product.product')
try:
self.slug
except UserError:
abort(404)
if self.type_ != 'catalog':
# Display only catalog nodes
abort(403)
products = Pagination(Product, [
('displayed_on_eshop', '=', True),
('nodes.left', '>=', self.left),
('nodes.right', '<=', self.right),
('template.active', '=', True),
], page=page, per_page=self.products_per_page)
return render_template(
'catalog/node.html', products=products, node=self
)
示例5: render
def render(cls, uri, page=1):
"""
Renders the category
"""
Article = Pool().get('nereid.cms.article')
# Find in cache or load from DB
try:
category, = cls.search([('unique_name', '=', uri)])
except ValueError:
abort(404)
order = []
if category.sort_order == 'recent_first':
order.append(('write_date', 'DESC'))
elif category.sort_order == 'older_first':
order.append(('write_date', 'ASC'))
elif category.sort_order == 'sequence':
order.append(('sequence', 'ASC'))
articles = Pagination(
Article, [
('categories', '=', category.id),
('state', '=', 'published')
], page, category.articles_per_page, order=order
)
return render_template(
category.template, category=category, articles=articles)
示例6: 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
)
示例7: 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'))
示例8: render_comments
def render_comments(self):
"""
Render comments
GET: Return json of all the comments of this post.
POST: Create new comment for this post.
"""
if self.state != 'Published':
abort(404)
# Add re_captcha if the configuration has such an option and user
# is guest
if 're_captcha_public' in CONFIG.options and request.is_guest_user:
comment_form = GuestCommentForm(
request.form, captcha={'ip_address': request.remote_addr}
)
else:
comment_form = PostCommentForm(request.form)
if request.method == 'GET':
if self.nereid_user == request.nereid_user:
return jsonify(comments=[
comment.serialize() for comment in self.comments
])
return jsonify(comments=[
comment.serialize() for comment in self.comments
if not comment.is_spam
])
# If post does not allow guest comments,
# then dont allow guest user to comment
if not self.allow_guest_comments and request.is_guest_user:
flash('Guests are not allowed to write comments')
if request.is_xhr:
return jsonify(
success=False,
errors=['Guests are not allowed to write comments']
)
return redirect(url_for(
'blog.post.render', user_id=self.nereid_user.id, uri=self.uri
))
if request.method == 'POST' and comment_form.validate():
self.write([self], {
'comments': [('create', [{
'nereid_user': current_user.id
if not current_user.is_anonymous() else None,
'name': current_user.display_name
if not current_user.is_anonymous()
else comment_form.name.data,
'content': comment_form.content.data,
}])]
})
if request.is_xhr:
return jsonify(success=True) if comment_form.validate() \
else jsonify(success=False, errors=comment_form.errors)
return redirect(url_for(
'blog.post.render', user_id=self.nereid_user.id, uri=self.uri
))
示例9: stream_via_token
def stream_via_token(cls, token):
'''
Set token user to online and publish presence of this user to all
friends.
'''
NereidUser = Pool().get('nereid.user')
if hasattr(current_app, 'redis_client'):
redis_client = current_app.redis_client
else:
redis_client = Redis(
CONFIG.get('redis_host', 'localhost'),
int(CONFIG.get('redis_port', 6379))
)
key = 'chat:token:%s' % token
if not redis_client.exists(key):
abort(404)
nereid_user = NereidUser(int(redis_client.get(key)))
nereid_user.broadcast_presence()
return Response(
cls.generate_event_stream(
nereid_user.id,
Transaction().cursor.dbname
),
mimetype='text/event-stream'
)
示例10: start_session
def start_session(cls):
'''
POST: Start chat session with another user.
:args user: User Id of nereid user.
:return: JSON as
{
thread_id: uuid,
members: Serialized members list.
}
'''
NereidUser = Pool().get('nereid.user')
form = NewChatForm()
if not form.validate_on_submit():
return jsonify(errors=form.errors), 400
chat_with = NereidUser(form.user.data)
if not request.nereid_user.can_chat(chat_with):
abort(403, "You can only talk to friends")
chat = cls.get_or_create_room(
request.nereid_user.id, chat_with.id
)
return jsonify({
'thread_id': chat.thread,
'members': map(
lambda m: m.user.serialize(), chat.members
)
})
示例11: __init__
def __init__(self, product, *args, **kwargs):
super(GiftCardForm, self).__init__(*args, **kwargs)
Product = Pool().get('product.product')
if not isinstance(product, Product):
abort(400)
try:
self.gc_product, = Product.search([
('id', '=', product.id),
('is_gift_card', '=', True)
], limit=1)
except ValueError as e:
e.message = 'Expected Gift Card, Got %s' % (product.rec_name)
raise
self.fill_choices()
if self.gc_product.gift_card_delivery_mode in ['virtual', 'combined']:
self.recipient_email.validators = [
validators.DataRequired(), validators.Email()
]
else:
self.recipient_email.validators = [
validators.Optional(), validators.Email()
]
示例12: process
def process(cls, sale, payment_method_id):
"""Begins the payment processing.
Returns a response object if a redirect to third party website is
required, else processes the payment.
:param sale: Browse Record of the Sale
:param payment_method_id: ID of payment method
"""
Sale = Pool().get('sale.sale')
try_to_authorize = (
request.nereid_website.payment_mode == 'auth_if_available'
)
payment_method = cls(payment_method_id)
allowed_gateways = cls._get_available_gateways(
sale.invoice_address.country
)
if payment_method not in allowed_gateways:
current_app.logger.error("Payment method %s is not valid" %
payment_method.name)
abort(403)
payment_method_obj = Pool().get(payment_method.model.model)
Sale.write([sale], {'payment_method': payment_method.id})
if try_to_authorize and hasattr(payment_method_obj, 'authorize'):
return payment_method_obj.authorize(sale)
else:
return payment_method_obj.capture(sale)
示例13: get_available_gateways
def get_available_gateways(cls):
"""Return the JSONified list of payment gateways available
This is a XHR only method
If type is specified as address then an address lookup is done
"""
Address = Pool().get('party.address')
value = request.args.get('value', 0, type=int)
if request.values.get('type') == 'address':
# Address lookup only when logged in
if request.is_guest_user:
abort(403)
# If not validated as user's address this could lead to
# exploitation by ID
if value not in [a.id for a in
request.nereid_user.party.addresses]:
abort(403)
address = Address(value)
value = address.country.id
rv = [{
'id': g.id,
'name': g.name,
'image': g.get_image(),
} for g in cls._get_available_gateways(value)]
return jsonify(result=rv)
示例14: render
def render(self, confirmation=None):
"""Render given sale order
:param sale: ID of the sale Order
:param confirmation: If any value is provided for this field then this
page is considered the confirmation page. This
also passes a `True` if such an argument is proved
or a `False`
"""
NereidUser = Pool().get('nereid.user')
# This Ugly type hack is for a bug in previous versions where some
# parts of the code passed confirmation as a text
confirmation = False if confirmation is None else True
# Try to find if the user can be shown the order
access_code = request.values.get('access_code', None)
if current_user.is_anonymous():
if not access_code:
# No access code provided, user is not authorized to
# access order page
return NereidUser.unauthorized_handler()
if access_code != self.guest_access_code:
# Invalid access code
abort(403)
else:
if self.party.id != request.nereid_user.party.id:
# Order does not belong to the user
abort(403)
return render_template(
'sale.jinja', sale=self, confirmation=confirmation
)
示例15: render
def render(cls, user_id, uri):
"Render the blog post"
NereidUser = Pool().get('nereid.user')
if 're_captcha_public' in CONFIG.options and request.is_guest_user:
comment_form = GuestCommentForm(
captcha={'ip_address': request.remote_addr}
)
else:
comment_form = PostCommentForm()
user = NereidUser(user_id)
posts = cls.search([
('nereid_user', '=', user.id),
('uri', '=', uri),
])
if not posts:
abort(404)
# if only one post is found then it is rendered and
# if more than one are found then the first one is rendered
post = posts[0]
if not (post.state == 'Published' or
request.nereid_user == post.nereid_user):
abort(403)
if request.is_xhr:
return jsonify(post.serialize())
return render_template(
'blog_post.jinja', post=post, comment_form=comment_form,
poster=user
)