本文整理汇总了Python中nereid.ctx.has_request_context函数的典型用法代码示例。如果您正苦于以下问题:Python has_request_context函数的具体用法?Python has_request_context怎么用?Python has_request_context使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了has_request_context函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: default_price_list
def default_price_list():
"""Get the pricelist of active user. In the
event that the logged in user does not have a pricelist set against
the user, the shop's pricelist is chosen.
:param user: active record of the nereid user
"""
User = Pool().get('res.user')
user = User(Transaction().user)
shop_price_list = user.shop.price_list.id if user.shop else None
if not has_request_context():
# Not a nereid request
return shop_price_list
# If control reaches here, then this is a nereid request. Lets try
# and personalise the pricelist of the user logged in.
if current_user.is_anonymous():
# Sorry anonymous users, you get the shop price
return shop_price_list
if current_user.party.sale_price_list:
# There is a sale pricelist for the specific user's party.
return current_user.party.sale_price_list.id
return shop_price_list
示例2: confirm
def confirm(cls, sales):
"Send an email after sale is confirmed"
super(Sale, cls).confirm(sales)
if has_request_context():
for sale in sales:
sale.send_confirmation_email()
示例3: default_price_list
def default_price_list(user=None):
"""Get the pricelist of active user. In the
event that the logged in user does not have a pricelist set against
the user, the guest user's pricelist is chosen.
:param user: active record of the nereid user
"""
if not has_request_context():
# Not a nereid request
return None
if user is not None and user.party.sale_price_list:
# If a user was provided and the user has a pricelist, use
# that
return user.party.sale_price_list.id
if not current_user.is_anonymous() and \
current_user.party.sale_price_list:
# If the currently logged in user has a pricelist defined, use
# that
return current_user.party.sale_price_list.id
# Since there is no pricelist for the user, use the guest user's
# pricelist if one is defined.
guest_user = request.nereid_website.guest_user
if guest_user.party.sale_price_list:
return guest_user.party.sale_price_list.id
return None
示例4: confirm
def confirm(self, ids):
"Send an email after sale is confirmed"
super(Sale, self).confirm(ids)
if has_request_context():
for sale in self.browse(ids):
self.send_confirmation_email(sale)
示例5: validate_for_product_inventory
def validate_for_product_inventory(self):
"""
This method validates the sale line against the product's inventory
attributes. This method requires request context.
"""
if has_request_context() and not self.product.can_buy_from_eshop():
flash(_("This product is no longer available"))
abort(redirect(request.referrer))
示例6: default_active
def default_active():
"""
If the user gets created from the web the activation should happen
through the activation link. However, users created from tryton
interface are activated by default
"""
if has_request_context():
return False
return True
示例7: confirm
def confirm(cls, sales):
"Send an email after sale is confirmed"
super(Sale, cls).confirm(sales)
if has_request_context():
for sale in sales:
# Change party name to invoice address name for guest user
if current_user.is_anonymous():
sale.party.name = sale.invoice_address.name
sale.party.save()
示例8: _get_email_template_context
def _get_email_template_context(self):
"""
Update context
"""
context = super(Sale, self)._get_email_template_context()
if has_request_context() and not current_user.is_anonymous():
customer_name = current_user.display_name
else:
customer_name = self.party.name
context.update({
'url_for': lambda *args, **kargs: url_for(*args, **kargs),
'has_request_context': lambda *args, **kargs: has_request_context(
*args, **kargs),
'current_user': current_user,
'customer_name': customer_name,
'to_json': lambda *args, **kargs: json.dumps(*args, **kargs),
})
return context
示例9: create
def create(self, values):
if has_request_context():
values['created_by'] = request.nereid_user.id
if values['type'] == 'task':
values.setdefault('participants', [])
values['participants'].append(
('add', [request.nereid_user.id])
)
else:
# TODO: identify the nereid user through employee
pass
return super(Project, self).create(values)
示例10: default_employee
def default_employee():
User = Pool().get('res.user')
if 'employee' in Transaction().context:
return Transaction().context['employee']
user = User(Transaction().user)
if user.employee:
return user.employee.id
if has_request_context() and request.nereid_user.employee:
return request.nereid_user.employee.id
示例11: _get_receiver_email_address
def _get_receiver_email_address(self):
"""
Update reciever's email address(s)
"""
to_emails = set()
if self.party.email:
to_emails.add(self.party.email.lower())
if has_request_context() and not current_user.is_anonymous() and \
current_user.email:
to_emails.add(current_user.email.lower())
return list(to_emails)
示例12: create
def create(self, values):
"""
Update create to save uploaded by
:param values: A dictionary
"""
if has_request_context():
values['uploaded_by'] = request.nereid_user.id
#else:
# TODO: try to find the nereid user from the employee
# if an employee made the update
return super(IrAttachment, self).create(values)
示例13: create
def create(cls, vlist):
"""
Create a Task and add current user as participant of the project
:param vlist: List of dictionaries of values to create
"""
for values in vlist:
if has_request_context():
if values["type"] == "task":
values.setdefault("participants", []).append(("add", [request.nereid_user.id]))
else:
# TODO: identify the nereid user through employee
pass
return super(Task, cls).create(vlist)
示例14: create
def create(cls, vlist):
'''
Create a Task and add current user as participant of the project
:param vlist: List of dictionaries of values to create
'''
for values in vlist:
if has_request_context():
if values['type'] == 'task' and not current_user.is_anonymous():
values.setdefault('participants', []).append(
('add', [current_user.id])
)
else:
# TODO: identify the nereid user through employee
pass
return super(Task, cls).create(vlist)
示例15: serialize
def serialize(self, purpose=None):
rv = {
'create_date': self.create_date.isoformat(),
"objectType": self.__name__,
"id": self.id,
"updatedBy": self.uploaded_by.serialize('listing'),
"displayName": self.name,
"description": self.description,
}
if has_request_context():
rv['downloadUrl'] = url_for(
'project.work.download_file',
attachment_id=self.id,
task=Transaction().context.get('task'),
)
return rv