本文整理汇总了Python中nereid.helpers.url_for函数的典型用法代码示例。如果您正苦于以下问题:Python url_for函数的具体用法?Python url_for怎么用?Python url_for使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url_for函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: add_to_cart
def add_to_cart(cls):
"""
Adds the given item to the cart if it exists or to a new cart
The form is expected to have the following data is post
quantity : decimal
product : integer ID
action : set (default), add
Response:
'OK' if X-HTTPRequest
Redirect to shopping cart if normal request
"""
form = AddtoCartForm(request.form)
if request.method == "POST" and form.validate():
cart = cls.open_cart(create_order=True)
action = request.values.get("action", "set")
if form.quantity.data <= 0:
flash(_("Be sensible! You can only add real quantities to cart"))
return redirect(url_for("nereid.cart.view_cart"))
cls._add_or_update(cart.sale.id, form.product.data, form.quantity.data, action)
if action == "add":
flash(_("The product has been added to your cart"), "info")
else:
flash(_("Your cart has been updated with the product"), "info")
if request.is_xhr:
return jsonify(message="OK")
return redirect(url_for("nereid.cart.view_cart"))
开发者ID:shalabhaggarwal,项目名称:nereid-cart-b2c,代码行数:30,代码来源:cart.py
示例2: get_absolute_url
def get_absolute_url(self, **kwargs):
"""
Return the URL of the current product.
This method works only under a nereid request context
"""
return url_for('product.product.render', uri=self.uri, **kwargs)
开发者ID:gautampanday,项目名称:nereid-catalog,代码行数:7,代码来源:product.py
示例3: clear_cart
def clear_cart(cls):
"""
Clears the current cart and redirects to shopping cart page
"""
cart = cls.open_cart()
cart._clear_cart()
flash(_("Your shopping cart has been cleared"))
return redirect(url_for("nereid.cart.view_cart"))
开发者ID:shalabhaggarwal,项目名称:nereid-cart-b2c,代码行数:8,代码来源:cart.py
示例4: get_url
def get_url(self, name):
"""Return the url if within an active request context or return
False values
"""
if _request_ctx_stack.top is None:
return None
return url_for("nereid.static.file.send_static_file", folder=self.folder.name, name=self.name)
开发者ID:COLABORATI,项目名称:nereid,代码行数:8,代码来源:static_file.py
示例5: add_to_wishlist
def add_to_wishlist(self):
"""Add the product to wishlist
"""
user = request.nereid_user
product = request.args.get('product', type=int)
self.write(product, {'wishlist': [('add', [user.id])]})
flash(_("The product has been added to wishlist"))
if request.is_xhr:
return 'OK'
return redirect(url_for('nereid.user.render_wishlist'))
开发者ID:shalabhaggarwal,项目名称:nereid-catalog,代码行数:10,代码来源:product.py
示例6: render
def render(self):
with NamedTemporaryFile(suffix=".xml") as buffer:
buffer.write('<?xml version="1.0" encoding="UTF-8"?>\n')
buffer.write('<sitemapindex ')
buffer.write(
'xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'
)
for page in xrange(1, self.page_count + 1):
loc = '<sitemap><loc>%s</loc></sitemap>\n'
method = '%s.sitemap' % self.model._name
buffer.write(loc % url_for(method, page=page, _external=True))
buffer.write('</sitemapindex>')
return send_file(buffer.name, cache_timeout=self.cache_timeout)
开发者ID:shalabhaggarwal,项目名称:nereid,代码行数:13,代码来源:sitemap.py
示例7: get_url
def get_url(self, name):
"""Return the url if within an active request context or return
False values
"""
if _request_ctx_stack.top is None:
return None
if self.type == 'local':
return url_for(
'nereid.static.file.send_static_file',
folder=self.folder.folder_name, name=self.name
)
elif self.type == 'remote':
return self.remote_path
开发者ID:Abhisar,项目名称:nereid,代码行数:14,代码来源:static_file.py
示例8: add_to_wishlist
def add_to_wishlist(cls):
"""
Add the product to wishlist
.. versionchanged::2.6.0.1
Only POST method can now be used to add products to wishlist.
"""
cls.write(
[cls(request.form.get('product', type=int))],
{'wishlist': [('add', [request.nereid_user.id])]}
)
if request.is_xhr:
return 'OK'
flash(_("The product has been added to wishlist"))
return redirect(url_for('nereid.user.render_wishlist'))
开发者ID:simmianand,项目名称:nereid-catalog,代码行数:16,代码来源:product.py
示例9: get_url
def get_url(self, ids, name):
"""Return the url if within an active request context or return
False values
"""
res = {}.fromkeys(ids, False)
if _request_ctx_stack.top is None:
return res
for f in self.browse(ids):
if f.type == 'local':
res[f.id] = url_for(
'nereid.static.file.send_static_file',
folder=f.folder.folder_name, name=f.name
)
elif f.type == 'remote':
res[f.id] = f.remote_path
return res
开发者ID:shalabhaggarwal,项目名称:nereid,代码行数:17,代码来源:static_file.py
示例10: _menu_item_to_dict
def _menu_item_to_dict(self, menu_item):
"""
:param menu_item: Active record of the menu item
"""
if hasattr(menu_item, 'reference') and getattr(menu_item, 'reference'):
model, id = getattr(menu_item, 'reference').split(',')
if int(id):
reference, = Pool().get(model).browse([int(id)])
uri = url_for('%s.render' % reference._name, uri=reference.uri)
else:
uri = getattr(menu_item, self.uri_field.name)
else:
uri = getattr(menu_item, self.uri_field.name)
return {
'name' : getattr(menu_item, self.title_field.name),
'uri' : uri,
}
开发者ID:shalabhaggarwal,项目名称:nereid-cms,代码行数:17,代码来源:cms.py
示例11: 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")
sale_line = SaleLine(line)
assert sale_line.sale.id == cls.open_cart().sale.id
SaleLine.delete([sale_line])
flash(_("The order item has been successfully removed"))
if request.is_xhr:
return jsonify(message="OK")
return redirect(url_for("nereid.cart.view_cart"))
开发者ID:shalabhaggarwal,项目名称:nereid-cart-b2c,代码行数:19,代码来源:cart.py
示例12: get_absolute_url
def get_absolute_url(self, **kwargs):
return url_for(
'nereid.cms.article.render', uri=self.uri, **kwargs
)
开发者ID:priyankarani,项目名称:nereid-cms,代码行数:4,代码来源:cms.py
示例13: get_absolute_url
def get_absolute_url(self, product, **kwargs):
return url_for(
'product.product.render', uri=product.uri, **kwargs)
开发者ID:shalabhaggarwal,项目名称:nereid-catalog,代码行数:3,代码来源:product.py
注:本文中的nereid.helpers.url_for函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论