Пример #1
0
def get_guoku_plus_item_context(taobao_url, shop_nick, user_id):
    if not is_taobao_url(taobao_url):
        raise NotTaobaoUrl()
    taobao_id = parse_taobao_id_from_url(taobao_url)
    if not taobao_id:
        raise InvalidUrl()

    item_inst = Item.get_item_by_taobao_id(taobao_id)
    if not item_inst:
        taobao_item_info = TaobaoExtractor.fetch_item(taobao_id)
        print taobao_item_info
        _category_id = Category.get_category_by_taobao_cid(
            taobao_item_info['cid'])
        _chief_image = None
        _detail_image_urls = []
        imgs_len = len(taobao_item_info['imgs'])
        if imgs_len > 0:
            _chief_image = taobao_item_info['imgs'][0]
            for i in range(1, imgs_len):
                _detail_image_urls.append(taobao_item_info['imgs'][i])
        _title = HTMLParser.HTMLParser().unescape(taobao_item_info['desc'])
        Entity.create_by_taobao_item(creator_id=user_id,
                                     category_id=_category_id,
                                     chief_image_url=_chief_image,
                                     taobao_item_info={
                                         'taobao_id':
                                         taobao_id,
                                         'cid':
                                         taobao_item_info['cid'],
                                         'title':
                                         _title,
                                         'shop_nick':
                                         unicode(taobao_item_info['nick'],
                                                 'utf-8'),
                                         'price':
                                         taobao_item_info['price'],
                                         'soldout':
                                         False,
                                     },
                                     brand="",
                                     title=_title,
                                     detail_image_urls=_detail_image_urls)
        item_inst = Item.get_item_by_taobao_id(taobao_id)
    item_context = item_inst.read()
    if item_context['shop_nick'] != shop_nick:
        raise NotSellerOwnProduct()
    return item_context
Пример #2
0
 def item_exist(self, taobao_item_id):
     item = Item.get_item_by_taobao_id(taobao_item_id)
     if not item:
         return False
     item_context = item.read()
     if item_context['shop_nick'] == self.nick:
         return True
     return False
Пример #3
0
def new_entity(request):
    if request.method == 'GET':
        return render_to_response('entity/new.html',
                                  {'active_division': 'entity'},
                                  context_instance=RequestContext(request))
    else:
        _cand_url = request.POST.get("url", None)
        _hostname = urlparse(_cand_url).hostname
        if re.search(r"\b(jd|360buy)\.com$", _hostname) != None:
            return new_jd_item(request)
        if re.search(r"\b(tmall|taobao)\.com$", _hostname) != None:
            _taobao_id = parse_taobao_id_from_url(_cand_url)

            _item = Item.get_item_by_taobao_id(_taobao_id)
            if _item == None:
                _taobao_item_info = load_taobao_item_info(_taobao_id)
                _brand = ''
                _title = ''
                _selected_category_id = Category.get_category_by_taobao_cid(
                    _taobao_item_info['cid'])

                _users = _get_special_names(request.user.id)

                return render_to_response(
                    'entity/create.html', {
                        'active_division': 'entity',
                        'taobao_id': _taobao_id,
                        'cid': _taobao_item_info['cid'],
                        'taobao_title': _taobao_item_info['title'],
                        'shop_nick': _taobao_item_info['nick'],
                        'shop_link': _taobao_item_info['shop_link'],
                        'price': _taobao_item_info['price'],
                        'thumb_images': _taobao_item_info["thumb_images"],
                        'selected_category_id': _selected_category_id,
                        'category_list': Category.find(),
                        'brand': _brand,
                        'title': _title,
                        'users': _users
                    },
                    context_instance=RequestContext(request))
            elif _item.get_entity_id() == -1:
                #TODO: bind an exist item to entity
                pass
            else:
                return HttpResponseRedirect(
                    reverse('management_edit_entity',
                            kwargs={"entity_id": _item.get_entity_id()}) +
                    '?code=1')
Пример #4
0
def load_item_info(request):
    if request.method == 'POST':
        _cand_url = request.POST.get("cand_url", None)
        _hostname = urlparse(_cand_url).hostname

        if re.search(r"\b(jd|360buy)\.com$", _hostname) != None:
            return jd_info(request, _cand_url)

        if re.search(r"\b(tmall|taobao)\.com$", _hostname) is not None:
            _taobao_id = parse_taobao_id_from_url(_cand_url)
            _item = Item.get_item_by_taobao_id(_taobao_id)

            if _item is None:
                _taobao_item_info = load_taobao_item_info(_taobao_id)
                _chief_image_url = _taobao_item_info["thumb_images"][0]
                _selected_category_id = Category.get_category_by_taobao_cid(_taobao_item_info['cid'])
                _data = {
                    'user_context' : User(request.user.id).read(), 
                    'cand_url' : _cand_url,
                    'taobao_id': _taobao_id,
                    'cid': _taobao_item_info['cid'],
                    'taobao_title': _taobao_item_info['title'],
                    'shop_nick': _taobao_item_info['shop_nick'],
                    'shop_link': _taobao_item_info['shop_link'],
                    'price': _taobao_item_info['price'],
                    'chief_image_url' : _chief_image_url,
                    'thumb_images': _taobao_item_info["thumb_images"],
                    'selected_category_id': _selected_category_id,
                }
                _rslt = {
                    'status' : 'SUCCESS',
                    'data' : _data
                }
            elif _item.get_entity_id() == -1:
                _rslt = {
                    'status' : 'OTHER'
                }
            else:
                _entity_id = _item.get_entity_id()
                _entity_context = Entity(_entity_id).read()
                _rslt = {
                    'status' : 'EXIST',
                    'data' : {
                        'entity_hash' : _entity_context['entity_hash']
                    }
                }
            return HttpResponse(json.dumps(_rslt))
Пример #5
0
 def create(cls, taobao_id, sale_price, total_volume, seller_remarks, shop_nick):
     item_inst = Item.get_item_by_taobao_id(taobao_id)
     item_context = item_inst.read()
     time_now = datetime.datetime.now()
     start_time = time_now + datetime.timedelta(100000) #set start time as 100000 days later
     GuokuPlusModel.objects.create(
         entity_id = item_context['entity_id'],
         item_id = item_context['item_id'],
         taobao_id = taobao_id,
         sale_price = sale_price,
         total_volume = total_volume,
         sales_volume = 0,
         seller_remarks = seller_remarks,
         shop_nick = shop_nick,
         status = ACTIVITY_WAITING,
         start_time = start_time,
         created_time = time_now,
         updated_time = time_now)   
Пример #6
0
def load_taobao_item_for_entity(request, entity_id):
    if request.method == 'POST':
        _taobao_id = request.POST.get("taobao_id", None)

        _item = Item.get_item_by_taobao_id(_taobao_id)
        if _item == None:
            _taobao_item_info = load_taobao_item_info(_taobao_id)
            return render_to_response(
                'entity/new_taobao_item_info.html', {
                    'active_division': 'entity',
                    'entity_id': entity_id,
                    'taobao_id': _taobao_id,
                    'cid': _taobao_item_info['cid'],
                    'taobao_title': _taobao_item_info['title'],
                    'shop_nick': _taobao_item_info['shop_nick'],
                    'price': _taobao_item_info['price'],
                    'thumb_images': _taobao_item_info["thumb_images"],
                    'soldout': 0,
                },
                context_instance=RequestContext(request))
        elif _item.get_entity_id() == -1:
            _item_context = _item.read()

            if not _item_context.has_key('images'):
                _item_context['images'] = None
            return render_to_response('entity/exist_taobao_item_info.html', {
                'active_division': 'entity',
                'entity_id': entity_id,
                'taobao_id': _taobao_id,
                'item_id': _item_id,
                'cid': _item_context['cid'],
                'taobao_title': _item_context['title'],
                'shop_nick': _item_context['shop_nick'],
                'price': _item_context['price'],
                'images': _item_context['images'],
                'soldout': 0,
            },
                                      context_instance=RequestContext(request))
        else:
            return HttpResponseRedirect(
                reverse('management_edit_entity',
                        kwargs={"entity_id": _entity_id}) + '?code=1')
Пример #7
0
def read_taobao_item_state(request):
    _taobao_url = request.GET.get("url", None)
    _item = None
    if _taobao_url is not None:
        _taobao_id = parse_taobao_id_from_url(_taobao_url)
        _item = Item.get_item_by_taobao_id(_taobao_id)

    _result = {}

    if _item is None:
        _result['status'] = 0
    elif _item.get_entity_id() == -1:
        _result['status'] = -1
    else:
        _result['status'] = 1
        _entity_id = _item.get_entity_id()
        _entity = Entity(_entity_id).read()
        _result['entity'] = _entity

    return HttpResponse(json.dumps(_result, cls=DjangoJSONEncoder))
Пример #8
0
def old_visit_item(request):
    _start_at = datetime.datetime.now()

    if request.method == "GET":
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _ttid = request.GET.get("ttid", None)
        _sid = request.GET.get("sid", None)
        _entry = request.GET.get("entry", "mobile")
        _outer_code = request.GET.get("outer_code", None)
        _sche = request.GET.get("sche", None)

        _taobao_id = request.GET.get("item_id", None)
        _item = Item.get_item_by_taobao_id(_taobao_id)
        _item_context = _item.read()

        if _taobao_id == '38232357603':
            _duration = datetime.datetime.now() - _start_at
            MobileLogTask.delay(entry="jd_bilang",
                                duration=_duration.seconds * 1000000 +
                                _duration.microseconds,
                                view='CLICK',
                                request=request.REQUEST,
                                ip=get_client_ip(request),
                                log_time=datetime.datetime.now(),
                                request_user_id=_request_user_id,
                                appendix={})
            return HttpResponseRedirect("http://item.jd.com/1076756.html")

        _taobaoke_info = taobaoke_mobile_item_convert(
            _item_context['taobao_id'])
        _entity_id = _item_context['entity_id'] if _item_context.has_key(
            'entity_id') else -1
        _duration = datetime.datetime.now() - _start_at

        if _taobaoke_info and _taobaoke_info.has_key('click_url'):
            MobileLogTask.delay(entry=_entry,
                                duration=_duration.seconds * 1000000 +
                                _duration.microseconds,
                                view='CLICK',
                                request=request.REQUEST,
                                ip=get_client_ip(request),
                                log_time=datetime.datetime.now(),
                                request_user_id=_request_user_id,
                                appendix={
                                    'site': 'taobao',
                                    'taobao_id': _item_context['taobao_id'],
                                    'item_id': _item_context['item_id'],
                                    'entity_id': _entity_id,
                                    'tbk': True,
                                })
            return HttpResponseRedirect(
                decorate_taobao_url(_taobaoke_info['click_url'], _ttid, _sid,
                                    _outer_code, _sche))

        MobileLogTask.delay(entry=_entry,
                            duration=_duration.seconds * 1000000 +
                            _duration.microseconds,
                            view='CLICK',
                            request=request.REQUEST,
                            ip=get_client_ip(request),
                            log_time=datetime.datetime.now(),
                            request_user_id=_request_user_id,
                            appendix={
                                'site': 'taobao',
                                'taobao_id': _item_context['taobao_id'],
                                'item_id': _item_context['item_id'],
                                'entity_id': _entity_id,
                                'tbk': False,
                            })
        return HttpResponseRedirect(
            decorate_taobao_url(
                get_taobao_url(_item_context['taobao_id'], True), _ttid, _sid,
                _outer_code, _sche))
Пример #9
0
def create_entity_from_offline(request):
    if request.method == 'POST':
        _taobao_id = request.POST.get("taobao_id", None)
        _cid = request.POST.get("cid", None)
        _taobao_shop_nick = request.POST.get("taobao_shop_nick", None)
        _taobao_title = request.POST.get("taobao_title", None)
        _taobao_price = request.POST.get("taobao_price", None)
        _taobao_soldout = request.POST.get("taobao_soldout", '0')
        if _taobao_soldout == '0':
            _taobao_soldout = False
        else:
            _taobao_soldout = True
        _rank_score = int(request.POST.get("item_score", '0'))
        _chief_image_url = request.POST.get("chief_image_url", None)
        _chief_image_url = re.sub('_\d+x\d+\.jpg|_b.jpg', '', _chief_image_url)
        _brand = request.POST.get("brand", "")
        _title = request.POST.get("title", "")
        _intro = request.POST.get("intro", "")
        _category_id = Category.get_category_by_taobao_cid(_cid)
        _origin_detail_image_urls = request.POST.getlist("image_url")
        _detail_image_urls = []
        for _url in _origin_detail_image_urls:
            _detail_image_urls.append(re.sub('_\d+x\d+\.jpg|_b.jpg', '', _url))

        if _chief_image_url in _detail_image_urls:
            _detail_image_urls.remove(_chief_image_url)

        _item = Item.get_item_by_taobao_id(_taobao_id)
        if _item == None:
            _entity = Entity.create_by_taobao_item(
                creator_id=request.user.id,
                category_id=_category_id,
                chief_image_url=_chief_image_url,
                taobao_item_info={
                    'taobao_id': _taobao_id,
                    'cid': _cid,
                    'title': _taobao_title,
                    'shop_nick': _taobao_shop_nick,
                    'price': _taobao_price,
                    'soldout': _taobao_soldout,
                },
                brand=_brand,
                title=_title,
                intro=_intro,
                detail_image_urls=_detail_image_urls,
                weight=-1,
                rank_score=_rank_score)
            _rslt = {
                'entity_id': _entity.entity_id,
                'item_id': _entity.read()['item_id_list'][0],
                'status': 'success'
            }
            return SuccessJsonResponse(_rslt)
        else:
            _item.update(cid=_cid,
                         title=_taobao_title,
                         shop_nick=_taobao_shop_nick,
                         price=_taobao_price,
                         soldout=_taobao_soldout)
            _rslt = {
                'message': 'item_exist',
                'item_id': _item.item_id,
                'status': 'updated'
            }
            return SuccessJsonResponse(_rslt)