本文整理汇总了Python中store.database.add函数的典型用法代码示例。如果您正苦于以下问题:Python add函数的具体用法?Python add怎么用?Python add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: seven_days_in_shop_subscription
def seven_days_in_shop_subscription(step, days):
days = int(days)
subscription = database.Subscription.get_one()
subscription.date_activated = lib.get_utcnow()
subscription.trial_end_date = lib.get_utcnow() + datetime.timedelta(days=days)
database.add(subscription)
database.push()
开发者ID:danieltcv,项目名称:product_reviews,代码行数:7,代码来源:subscription.py
示例2: prepare_billing_activation_reminder_emails
def prepare_billing_activation_reminder_emails():
"""
:return:
"""
emails = []
now = get_utcnow()
six_days_from_now = now + datetime.timedelta(days=6)
subscriptions = database.Subscription.get_by(filters=[(database.Subscription.trial_end_date < six_days_from_now) |
(database.Subscription.trial_end_date >= now) &
(database.Subscription.active == False) &
(database.Subscription.deactivated_at != None) ])
email_factory = ReminderEmailFactory()
for subscription in subscriptions:
send_at = get_email_sending_timestamp_for_timezone(subscription.created_at)
days_left_in_trial = trial_days_left(subscription.trial_end_date)
content = days_email_reminders_mapping.get(days_left_in_trial)
if not content:
continue
if subscription.trial_end_email_sent:
continue
if days_left_in_trial == 0:
subscription.trial_end_email_sent = True
database.add(subscription)
email = email_factory.create(template=content.get('template'),
subject=content.get('subject'),
subscription=subscription,
send_at=send_at)
emails.append(email)
database.push()
return emails
开发者ID:danieltcv,项目名称:product_reviews,代码行数:33,代码来源:subscriptions.py
示例3: create
def create(cls, user_id, **kwargs):
user = get_or_create_anonymous_user(user_id)
created_at = get_utcnow()
database_instance = cls.local.create(user_id=user.id, created_at=created_at, **kwargs)
database.add(database_instance)
database.push()
return database_instance
开发者ID:danieltcv,项目名称:product_reviews,代码行数:7,代码来源:contact.py
示例4: create_review_opinew_on_shopify_emails
def create_review_opinew_on_shopify_emails():
emails = []
now = get_utcnow()
sixteen_days_ago = now - timedelta(days=16)
fifteen_days_ago = now - timedelta(days=15)
# get users which have subscriptions post trial and. email is 2 days after the trial finished and they decided to stay
subscriptions = database.Subscription.get_by(filters=[(database.Subscription.activated_at >= sixteen_days_ago) &
(database.Subscription.activated_at <= fifteen_days_ago) &
(database.Subscription.review_us_email_sent == False)])
unsubscribe_group = current_app.config.get("SENDGRID_UNSUBSCRIBE_GROUP_SHOP_OWNER_MESSAGES")
for subscription in subscriptions:
user = subscription.customer.user
ctx = {}
ctx['user_name'] = user.name
email_content = render_template("emails/review_us.html", **ctx)
email = Email(origin=Constants.EMAIL_DEFAULT_ORIGIN, destination=user.email,
subject=Constants.EMAIL_SUBJECT_REVIEW_US, content=email_content,
unsubscribe_group=unsubscribe_group)
emails.append(email)
subscription.review_us_email_sent = True
database.add(subscription)
database.push()
return emails
开发者ID:danieltcv,项目名称:product_reviews,代码行数:27,代码来源:shopify.py
示例5: create_message
def create_message(sender, receiver, body, timestamp=None):
"""
Create a message from user with id the first argument
to user with id the second argument
:param sender: id of user from which to send message
:param receiver: is of user to which to send message
:param body: the message body
:param timestamp: the time when the message is created; default is time of function call
:return: the created message object
"""
time = None
if timestamp:
time = timestamp
else:
time = lib.get_utcnow()
new_message = database.Message.create(
sender=sender,
receiver=receiver,
body=body,
timestamp=time
)
database.add(new_message)
database.push()
return new_message
开发者ID:danieltcv,项目名称:product_reviews,代码行数:25,代码来源:messages.py
示例6: import_orders
def import_orders(shopify_api, shop, is_reinstallation=False):
"""
Imports all orders from shopify store to our database
:param shopify_api:
:param shop
:param is_reinstallation: Is this a re-installation of the application
"""
shopify_orders_count = shopify_api.get_orders_count()
total_pages = shopify_orders_count / external_apis.shopify.SHOPIFY_MAX_ORDERS_PER_PAGE + 1
for page in range(1, total_pages + 1):
# Get shopify orders
shopify_orders = shopify_api.get_orders(page=page)
# Import shop orders
for shopify_order in shopify_orders:
# skip existing orders
platform_order_id = str(shopify_order.get('id', ''))
# deleted could be True when is_reinstallation is True
existing_order = database.Order.get_one_by(platform_order_id=platform_order_id,
deleted=is_reinstallation)
if existing_order and is_reinstallation:
existing_order.undelete()
order = adapt_shopify_order_to_database(shopify_order, existing_order=existing_order)
if order:
order.shop = shop
database.add(order)
开发者ID:danieltcv,项目名称:product_reviews,代码行数:26,代码来源:shopify.py
示例7: import_products
def import_products(shopify_api, shop, is_reinstallation=False):
"""
Imports all products from shopify store to our database
:param shopify_api:
:param shop
:param is_reinstallation: is this a reinstallation of the shop
"""
shopify_products_count = shopify_api.get_products_count()
total_pages = shopify_products_count / external_apis.shopify.SHOPIFY_MAX_PRODUCTS_PER_PAGE + 1
for page in range(1, total_pages + 1):
shopify_products = shopify_api.get_products(page=page)
# Import shop products
for shopify_product in shopify_products:
# skip existing product
platform_product_id = str(shopify_product.get('id', ''))
# deleted could be True when is_reinstallation is True
existing_product = database.Product.get_one_by(platform_product_id=platform_product_id,
deleted=is_reinstallation)
if existing_product and is_reinstallation:
existing_product.undelete()
product = adapt_shopify_product_to_database(shopify_product, existing_product=existing_product)
if product:
product.shop = shop
database.add(product)
database.push()
开发者ID:danieltcv,项目名称:product_reviews,代码行数:26,代码来源:shopify.py
示例8: create_review_requests_for_order
def create_review_requests_for_order(order_id):
order = database.Order.get_one_by(id=order_id)
verify_required_condition(order.shop is not None, "Order's shop is not specified")
verify_required_condition(order.shop.owner is not None, "Order's shop owner is not specified")
verify_required_condition(order.shop.owner.customer is not None, "Order's shop customer is not specified")
verify_required_condition(order.product_variants is not None, "Order products are not specified")
products_variants_sorted = sort_product_variants(order.product_variants)
subscription = order.shop.owner.customer.subscription
for i, product_variant in enumerate(products_variants_sorted):
if subscription.quota_left <= 0:
break
subscription.quota_left -= 1
rr = create_new_review_request(to_user_id=order.user_id,
for_product_variant_id=product_variant.id,
for_order_id=order.id)
rr.send_at = decide_time_of_review_request(number_of_item_in_order=i)
database.add(rr)
database.add(subscription)
database.push()
开发者ID:danieltcv,项目名称:product_reviews,代码行数:25,代码来源:order.py
示例9: one_subscription_in_db_quota_reset_today
def one_subscription_in_db_quota_reset_today(step):
days_ago = 30
default_plan = database.Plan.create(name=assets.PlatformConstants.SHOPIFY_DEFAULT_PLAN_NAME, amount=40,
trial_period_days=assets.PlatformConstants.SHOPIFY_BASIC_PLAN_TRIAL_DAYS,
quota=500)
activated_at = lib.get_utcnow() - datetime.timedelta(days=days_ago)
trial_end_date = activated_at + datetime.timedelta(days=assets.PlatformConstants.SHOPIFY_BASIC_PLAN_TRIAL_DAYS)
billing_on = lib.tzunaware_datetime_to_aware(
datetime.datetime.strptime("2015-03-14", "%Y-%m-%d")) #this is the get_utcnow value that we set in tests by freezetime
s1 = database.Subscription.create(active=True, activated_at=activated_at, trial_end_date=trial_end_date, plan=default_plan,
review_us_email_sent=True, quota_left=10, billing_on=billing_on)
world.local.subscription = s1
role = database.Role.get_one_by(name=assets.Roles.SHOP_OWNER_ROLE)
shop_owner_user = database.User.create(name="Jerzy",
email="[email protected]", password="azerty",
roles=[role], active=True)
shop = database.Shop.create()
shop_owner_user.shops = [shop]
customer = database.Customer.create(user=shop_owner_user)
s1.customer = customer
database.add(s1)
database.push()
开发者ID:danieltcv,项目名称:product_reviews,代码行数:28,代码来源:subscription.py
示例10: activate_subscription
def activate_subscription(subscription_id, external_subscription_id, billing_on):
subscription = database.Subscription.get_one_by(id=subscription_id)
subscription.external_subscription_id = external_subscription_id
subscription.active = True
subscription.activated_at = get_utcnow()
subscription.billing_on = billing_on
database.add(subscription)
database.push()
开发者ID:danieltcv,项目名称:product_reviews,代码行数:8,代码来源:subscriptions.py
示例11: product_already_exists_666
def product_already_exists_666(step):
product = database.Product.create(platform_product_id=NEW_ORDER_PRODUCT_2_ID)
product_variant_3 = database.ProductVariant.create(platform_variant_id=PRODUCT_VARIANT_3_ID)
product.variants.append(product_variant_3)
database.add(product)
database.push()
开发者ID:danieltcv,项目名称:product_reviews,代码行数:8,代码来源:shopify_webhooks.py
示例12: update_review_request
def update_review_request(review, review_request_id, review_request_token):
review_request = database.ReviewRequest.get_one_by(id=review_request_id)
verify_review_request(review_request, review_request_token)
review_request.completed = True
review.verified_review = True
review.user = review_request.to_user
review.product_variant_id = review_request.for_product_variant_id
database.add(review_request)
开发者ID:danieltcv,项目名称:product_reviews,代码行数:8,代码来源:review_requests.py
示例13: create_shop_shopify
def create_shop_shopify(shop_domain, request_dict, client_id, client_secret, server_url):
"""
Create a temporary user
:return: the freshly created shop
"""
# Initialize the API
shopify_api = external_apis.shopify.ShopifyAPI(shop_domain=shop_domain)
# verify the request arguments
shop_name = get_shop_name_by_domain(shop_domain)
nonce = request_dict.get('state').replace(' ', '+')
hmac_r = request_dict.get('hmac')
code = request_dict.get('code')
# verify the request arguments
verify_nonce(nonce, shop_name)
verify_hmac(request_dict, hmac_r, client_secret)
verify_shop_name(shop_domain)
# Get shop info from API
shop_access_token = shopify_api.get_access_token(client_id, client_secret, code)
shopify_api.reinit(access_token=shop_access_token)
old_user_new_shop = False
# Has this shop been uninstalled?
is_reinstallation = False
shop = database.Shop.get_one_by(domain=shop_domain, deleted=True)
shopify_shop = shopify_api.get_shop()
shop_owner = database.User.get_one_by(email=shopify_shop.get('email', ''))
if not shop_owner:
shop_owner = _create_minimal_shop_owner(shopify_shop)
else:
verify_one_shop_per_user(shop_owner, shop_domain, shop_access_token)
if not shop:
old_user_new_shop = True
if not shop_owner.has_role(assets.Roles.SHOP_OWNER_ROLE):
shop_owner_role = database.Role.get_one_by(name=assets.Roles.SHOP_OWNER_ROLE)
shop_owner.roles.append(shop_owner_role)
database.add(shop_owner)
if shop:
# renew the access token in any case
shop.access_token = shop_access_token
if shop.deleted:
shop.undelete()
is_reinstallation = True
else:
return shop
else:
shop = _create_minimal_shop(shop_owner, shop_name, shop_domain, shop_access_token)
shop_owner = shop.owner
database.add(shop)
create_notifications(shop)
database.push()
# Schedule a task to update the shop details
shopify_shop_setup.delay(shop_owner_user_id=shop_owner.id,
shop_domain=shop_domain,
server_url=server_url,
is_reinstallation=is_reinstallation,
old_user_new_shop=old_user_new_shop)
return shop
开发者ID:danieltcv,项目名称:product_reviews,代码行数:58,代码来源:shopify.py
示例14: find_user_by_id_or_email
def find_user_by_id_or_email(self, user_id, user_email):
user = database.User.get_one_by(id=user_id)
email_user = database.User.get_one_by(email=user_email)
if not email_user:
user.email = user_email
database.add(user)
else:
user = email_user
return user
开发者ID:danieltcv,项目名称:product_reviews,代码行数:9,代码来源:create_reviews.py
示例15: get_or_create_anonymous_user
def get_or_create_anonymous_user(user_id):
if user_id:
user = database.User.get_one_by(id=int(user_id))
if user:
return user
user = database.User.create()
database.add(user)
database.push()
return user
开发者ID:danieltcv,项目名称:product_reviews,代码行数:9,代码来源:users.py
示例16: create_event
def create_event(shop, type, meta, show_to_shop):
now = lib.get_utcnow()
event = database.Event.create(shop=shop,
timestamp=now,
type=type,
meta=meta,
show_to_shop=show_to_shop)
database.add(event)
database.push()
开发者ID:danieltcv,项目名称:product_reviews,代码行数:9,代码来源:events.py
示例17: create_notifications
def create_notifications(shop):
welcome_notification = database.ShopNotification.create(shop=shop,
title="Welcome to Opinew!",
body=assets.NotificationsMessages.SHOP_CREATED,
template='snippets/onboarding.html',
default_open=True,
category=assets.ErrorCategories.INFO,
timestamp=get_utcnow())
database.add(welcome_notification)
开发者ID:danieltcv,项目名称:product_reviews,代码行数:9,代码来源:shopify.py
示例18: there_is_a_review_created_by_someone_else
def there_is_a_review_created_by_someone_else(step):
now = lib.get_utcnow()
user = database.User.create()
review = database.Review.create(product_id=world.product_id, user_id=user.id,
body="review by someone else", star_rating=5,
created_ts=now, published=True)
database.add(review)
database.push()
world.previous_review_id = review.id
开发者ID:danieltcv,项目名称:product_reviews,代码行数:9,代码来源:product_plugin.py
示例19: cancel_review_requests
def cancel_review_requests(review):
existing_orders = database.Order.get_by_product_and_user_email(product=review.product,
user_email=review.user.email)
if existing_orders:
review.verified_review = True
for order in existing_orders:
for review_request in order.review_requests:
cancel_review_request(review_request)
database.add(review)
database.push()
开发者ID:danieltcv,项目名称:product_reviews,代码行数:10,代码来源:review_requests.py
示例20: one_old_subscription_in_db_zero_days_left
def one_old_subscription_in_db_zero_days_left(step):
default_plan = database.Plan.create(name=assets.PlatformConstants.SHOPIFY_DEFAULT_PLAN_NAME, amount=40,
trial_period_days=assets.PlatformConstants.SHOPIFY_BASIC_PLAN_TRIAL_DAYS)
activated_at = lib.get_utcnow() - datetime.timedelta(days=34)
trial_end_date = lib.get_utcnow() - datetime.timedelta(days=5)
s1 = database.Subscription.create(trial_end_date=trial_end_date, activated_at=activated_at, plan=default_plan)
database.add(s1)
database.push()
开发者ID:danieltcv,项目名称:product_reviews,代码行数:11,代码来源:subscription.py
注:本文中的store.database.add函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论