本文整理汇总了Python中models.Subscription.get_by_product_and_period方法的典型用法代码示例。如果您正苦于以下问题:Python Subscription.get_by_product_and_period方法的具体用法?Python Subscription.get_by_product_and_period怎么用?Python Subscription.get_by_product_and_period使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Subscription
的用法示例。
在下文中一共展示了Subscription.get_by_product_and_period方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Subscription [as 别名]
# 或者: from models.Subscription import get_by_product_and_period [as 别名]
def post(self):
# Get customer and create an invoice.
customer = Customer.get_by_key_name(self.get_current_username())
invoice = Invoice(customer=customer)
invoice.put()
# Now start processing subscription data.
subscription_data = self.session['subscription-data']
products = db.get([db.Key(key) for key in subscription_data.get('products')])
period = subscription_data.get('period')
subscription_period = SubscriptionPeriod.get_by_period(period)
units = [product for product in products if 'product_keys' not in product.properties()]
baskets = [product for product in products if 'product_keys' in product.properties()]
activation_credentials_list = []
orders = []
for unit in units:
subscription = Subscription.get_by_product_and_period(unit, period)
order = Order(customer=customer, invoice=invoice, subscription=subscription)
order.subscription_price = subscription.price
order.subscription_general_sales_tax = subscription.general_sales_tax
order.subscription_period_in_months = subscription.period_in_months
order.subscription_free_period_in_months = subscription_period.free_period_in_months
order.price = subscription.price + subscription.general_sales_tax
order.subscription_currency = subscription.currency
orders.append(order)
order.put()
unit_id = unit.key().id()
activation_credentials = ActivationCredentials()
activation_credentials.serial_number = self.get_argument('u_%d_serial_number' % unit_id)
activation_credentials.machine_id = self.get_argument('u_%d_machine_id' % unit_id)
activation_credentials.order = order
activation_credentials.product = unit
activation_credentials.customer = customer
logging.info(activation_credentials)
activation_credentials_list.append(activation_credentials)
for basket in baskets:
subscription = Subscription.get_by_product_and_period(basket, period)
order = Order(customer=customer, invoice=invoice, subscription=subscription)
order.subscription_price = subscription.price
order.subscription_general_sales_tax = subscription.general_sales_tax
order.subscription_period_in_months = subscription.period_in_months
order.subscription_free_period_in_months = subscription_period.free_period_in_months
order.price = subscription.price + subscription.general_sales_tax
order.subscription_currency = subscription.currency
orders.append(order)
order.put()
for unit in basket.products:
basket_id = basket.key().id()
unit_id = unit.key().id()
activation_credentials = ActivationCredentials()
activation_credentials.serial_number = self.get_argument('b_%d_u_%d_serial_number' % (basket_id, unit_id,))
activation_credentials.machine_id = self.get_argument('b_%d_u_%d_machine_id' % (basket_id, unit_id,))
activation_credentials.order = order
activation_credentials.product = unit
activation_credentials.customer = customer
logging.info(activation_credentials)
activation_credentials_list.append(activation_credentials)
db.put(activation_credentials_list)
invoice.total_price = sum([order.price for order in orders])
invoice.currency = orders[0].subscription_currency
invoice.put()
self.session['activation-invoice-key'] = str(invoice.key())
self.redirect('/activate/overview')