当前位置: 首页>>代码示例>>Python>>正文


Python Gift.put方法代码示例

本文整理汇总了Python中apps.gift.models.Gift.put方法的典型用法代码示例。如果您正苦于以下问题:Python Gift.put方法的具体用法?Python Gift.put怎么用?Python Gift.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apps.gift.models.Gift的用法示例。


在下文中一共展示了Gift.put方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sync_new_task

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import put [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})
开发者ID:gmist,项目名称:f-toy,代码行数:60,代码来源:views.py

示例2: sync_gift_task

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import put [as 别名]
def sync_gift_task(request, task_id):
    gift_id = memcache.get(task_id)
    memcache.delete(task_id)
    if gift_id:
        try:
            result = urlfetch.fetch(
                'http://www.3dhero.ru/api/v2/product.json?id=%s' % gift_id
            )
            if result.status_code == 200:
                result = simplejson.loads(result.content)
                if result['success']:
                    model = result['result']
                    if model['id_1c']:
                        category = Category.all().filter('name =', u'Развивающие Игры').get()
                        if category:
                            group = Group.all().filter('category =', category).filter('name =', u'Фигурки Героев').get()
                        else:
                            group = None
                        gift = Gift(
                                name = model.get('name', ''),
                                id_1c = model['id_1c'],
                                catalogue_id = model.get('catalogue_id', ''),
                                barcode = model.get('barcode', ''),
                                brand = model.get('brand', ''),
                                country = model.get('country', ''),
                                material = model.get('material', ''),
                                gift_size = model.get('size', ''),
                                weight = model.get('weight',''),
                                box_size = model.get('box_size', ''),
                                master_box = model.get('box_amount', ''),
                                real_price = model.get('price_trade', 0.0),
                                price = model.get('price_retail', 0.0),
                                leftovers = model.get('leftovers', 0),
                                remote_leftovers = model.get('leftovers_on_way', 0),
                                to_sync = True
                            )
                        if category and group:
                            gift.category = category
                            gift.group = group
                        gift.put()
                        images = model.get('images', [])
                        if images:
                            for img in images:
                                def txn():
                                    task_id = str(uuid.uuid4())
                                    data = {'gift_id': gift.key().id(), 'img_url': img}
                                    memcache.add(task_id, data, TASK_LIVE_TIMEOUT)
                                    taskqueue.add(
                                        url=url_for('sync/add_image_task', task_id=task_id),
                                        transactional=True
                                    )
                                db.run_in_transaction(txn)
        except:
            pass
    return render_to_response('empty.html')
开发者ID:gmist,项目名称:five-studio,代码行数:57,代码来源:views.py

示例3: update_process

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import put [as 别名]
def update_process(file):
    from apps.gift.models import Gift

    csv_file = open_csv(file)
    i = 0
    for line in csv_file:
        if not i:
        # skip first line (header)
            i = 1
            continue

        catalogue_uid = unicode.strip(line[3].decode('utf8'))
        if not catalogue_uid:
            continue

        status = unicode.strip(line[0].decode('utf-8'))
        if status:
            status = int(status)
        else:
            status = None
        if status is None or status > 70:
            gift = get_gift_by_catalogue_uid(catalogue_uid)
            if gift:
                gift.delete()
            continue

        barcode = unicode.strip(line[5].decode('utf8'))
        name_origin = unicode.strip(line[6].decode('utf8'))
        name = unicode.strip(line[7].decode('utf8'))
        subcategory = unicode.strip(line[8].decode('utf8'))
        group = unicode.strip(line[9].decode('utf8'))
        category = unicode.strip(line[10].decode('utf8'))
        receipt_date = unicode.strip(line[14].decode('utf8'))
        try:
            if receipt_date:
                receipt_date = datetime.date(
                    datetime.strptime(receipt_date, '%m/%d/%Y'))
        except:
            receipt_date = None
        brand = unicode.strip(line[15].decode('utf8'))
        master_box = unicode.strip(line[16].decode('utf8'))
        rating = unicode.strip(line[17].decode('utf8'))
        if rating:
            rating = int(rating)
        else:
            rating = None
        box_size = unicode.strip(line[18].decode('utf8'))

        price = str.strip(line[21])
        if price:
            price = price.replace(' ', '').replace(',', '').replace('.', ' ')
            price = float(price)
        else:
            price = 0.0

        real_price = str.strip(line[25])
        if real_price:
            real_price = real_price.replace(' ', '').\
            replace(',', '').replace('.', ' ')
            real_price = float(real_price)
        else:
            real_price = 0.0

        gift = get_gift_by_catalogue_uid(catalogue_uid)
        if not gift:
            print 'Gift not found by catalogue uid ( %s ). \
            Create it!' % catalogue_uid
            gift = Gift()
            gift.put()

        update_data(
            obj_key=gift.key(),
            status=status,
            catalogue_uid=catalogue_uid,
            name=name,
            name_origin=name_origin,
            brand=brand,
            category=category,
            subcategory=subcategory,
            group=group,
            price=price,
            barcode=barcode,
            box_size=box_size,
            master_box=master_box,
            rating=rating,
            receipt_date=receipt_date,
            real_price=real_price)
        print '%s. %s, %s, %s'\
        % (i, catalogue_uid.encode('utf8'), name.encode('utf8'), price)

        i += 1
开发者ID:gmist,项目名称:five-studio,代码行数:93,代码来源:importer.py

示例4: update_gifts

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import put [as 别名]
def update_gifts(task_id, create=False, except_fields=EXCEPT_FIELDS_UPDATE):
    set_obj = memcache.get(task_id)
    flag = False
    if set_obj:
        data = simplejson.loads(set_obj)
        memcache.delete(task_id)
        id_1c = data.get('id_1c', '')
        logging.info("API update 1c: %s" % id_1c)
        name = data.get('name', '')
        logging.info("API update name: %s" % name)
        if not id_1c and not name:
            if not create:
                return render_to_response('empty.html')
        if id_1c:
            gifts_obj = Gift.all().filter('id_1c =', id_1c)
            if not gifts_obj.count():
                gifts_obj = Gift.all().filter('name =', name)
        else:
            gifts_obj = Gift.all().filter('name =', name)
        if gifts_obj.count() and create:
            return render_to_response('empty.html')
        gift = None
        if gifts_obj.count() and not create:
            gift = gifts_obj[0]
        if not gifts_obj.count() and create:
            gift = Gift(name=name)
        if gift is None:
            return render_to_response('empty.html')

        # update category and groups
        category = data.get('subcategory', '-')
        group = data.get('group', '-')
        try:
            a = gift.category.name
            b = gift.group.name
        except Exception:
            gift.category = gift.group = None

        if category != '-' and group != '-':
            if not category or not group:
                if gift.category or gift.group:
                    gift.category = None
                    gift.group = None
                    flag = True
            else:
                category_obj = Category.all().filter('name =', category)
                if category_obj.count():
                    category_obj = category_obj[0]
                else:
                    category_obj = Category(name=category)
                    category_obj.put()
                if not gift.category or gift.category != category_obj:
                    gift.category = category_obj
                    flag = True

                group_obj = Group.all().filter(
                    'category =', category_obj).filter('name =', group)
                if group_obj.count():
                    group_obj = group_obj[0]
                else:
                    group_obj = Group(name=group, category=category_obj)
                    group_obj.put()
                if not gift.group or gift.group != group_obj:
                    gift.group = group_obj
                    flag = True

        # and other fields
        for key in data.keys():
            if key in except_fields:
                continue
            value = data.get(key, None)
            if value is None:
                continue
            if key == 'receipt_date':
                try:
                    new_date = datetime.date(
                        datetime.strptime(value, '%Y-%m-%d'))
                    if new_date == gift.receipt_date:
                        continue
                    gift.receipt_date = new_date
                    flag = True
                except ValueError:
                    if gift.receipt_date is not None:
                        gift.receipt_date = None
                        flag = True
                continue
            try:
                old_val = getattr(gift, key)
                if old_val == value:
                    continue
                setattr(gift, key, value)
                flag = True
            except AttributeError:
                pass
        if flag:
            gift.put()
            gift_views.get_gift(gift.uid, True)
    return render_to_response('empty.html')
开发者ID:gmist,项目名称:five-studio,代码行数:100,代码来源:views.py

示例5: import_data

# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import put [as 别名]
def import_data(in_file='quick_export.csv'):
    images_path = os.path.join(DEFAULT_PATH, 'images')
    reader = csv.reader(open(os.path.join(DEFAULT_PATH, in_file)))
    for i, line in enumerate(reader):
        if not i:
            continue
        uid = line[0]
        gift_imgs_path = os.path.join(images_path, uid)
        try:
            imgs_files = os.listdir(gift_imgs_path)
        except OSError:
            imgs_files = []
        name = line[2].decode('utf-8')
        category = line[3].decode('utf-8')
        subcategory = line[4].decode('utf-8')
        brand = line[5].decode('utf-8')

        if line[6]:
            price = float(line[6])
        else:
            price = 0.0

        size = line[9].decode('utf-8')
        if not size:
            size = u''
        desc = line[10].decode('utf-8')

        if line[11]:
            rating = float(line[11])
        else:
            rating = 3.0
            
        if imgs_files:
            imgs_files =\
            [open(os.path.join(gift_imgs_path, img), 'rb').read() \
             for img in imgs_files]

        if brand:
            brand_obj = Brand.all().filter('brand =', brand)
            if not brand_obj.count():
                brand_obj = Brand(brand=brand)
                brand_obj.put()
            else:
                brand_obj = brand_obj[0]
        else:
            brand_obj = None

        if category:
            category_obj = Category.all().filter('category =', category)
            if category_obj.count():
                category_obj = category_obj[0]
            else:
                category_obj = Category(category=category)
                category_obj.put()
        else:
            category_obj = None

        if category and subcategory:
            subcategory_obj = Subcategory.all().filter('subcategory =', subcategory).filter('on_category =', category_obj)
            if subcategory_obj.count():
                subcategory_obj = subcategory_obj[0]
            else:
                subcategory_obj = Subcategory(subcategory=subcategory, on_category=category_obj)
                subcategory_obj.put()
        else:
            subcategory_obj = None

        gift = Gift(name=name,
                    uid_5studio=uid,
                    brand=brand_obj,
                    category=category_obj,
                    subcategory=subcategory_obj,
                    description=desc,
                    rating=rating,
                    price=price,
                    size=size)
        gift.put()

        if gift.name:
            title = gift.name.replace('"', '"')
        else:
            title = ''
        content_type = 'image/jpeg'
        for thumb in imgs_files:
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            if not gift.thumbs.count():
                thumb_img.main_gift = gift
            thumb_img.gift = gift
            thumb_img.put()
开发者ID:gmist,项目名称:f-toy,代码行数:99,代码来源:import_data.py


注:本文中的apps.gift.models.Gift.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。