本文整理汇总了Python中apps.gift.models.Gift.subcategory方法的典型用法代码示例。如果您正苦于以下问题:Python Gift.subcategory方法的具体用法?Python Gift.subcategory怎么用?Python Gift.subcategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.gift.models.Gift
的用法示例。
在下文中一共展示了Gift.subcategory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync_new_task
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import subcategory [as 别名]
def sync_new_task(request, uid):
logging.info("Create new gift from 5studio.ru with uid: %s" % uid)
url = 'http://www.5studio.ru/api/v1/get/gift.json?&uid=%s' % uid
result = urlfetch.fetch(url)
if result.status_code == 200:
j = simplejson.loads(result.content)
if len(j):
name = j.get('name', '').replace('\\"', '"')
name_origin = j.get('name_origin', '').replace('\\"', '"')
barcode = j.get('barcode', '')
description = j.get('description', '').replace('\\"', '"')
price = j.get('price', 0.0)
leftovers = j.get('leftovers', 0)
gift = Gift.all().filter('uid_5studio =', uid).fetch(1)
if gift:
gift = gift[0]
is_new = False
else:
is_new = True
gift = Gift(
uid_5studio=uid,
name=name,
name_origin=name_origin,
barcode=barcode,
description=description,
price=price,
leftovers=leftovers)
brand = j.get('brand', '').replace('\\"', '"')
if brand:
brand_obs = Brand.all().filter('brand =', brand)
if not brand_obs.count():
brand = Brand(brand=brand)
brand.put()
else:
brand = brand_obs.get()
gift.brand = brand
gift.category = get_category(j)
gift.subcategory = get_subcategory(j, gift.category)
gift.put()
if is_new or not gift.thumbs:
thumbs_url = j.get('thumbs_url', [])
for url in thumbs_url:
gift_uid = gift.key().id()
memcache.add('sync/add_image/%s' % gift_uid,
'http://%s' % url, 7200)
def txn():
taskqueue.add(url=url_for(
'sync/sync_add_image',
uid=gift.key().id()),
transactional=True)
db.run_in_transaction(txn)
return render_json_response({'api_msg': 'Ok', 'api_success': True})