Esempio n. 1
0
def log_visit_item(request, item_id):
    if request.user.is_authenticated():
        _request_user_id = request.user.id
    else:
        _request_user_id = None 
    if request.method == 'POST':
        _entry = request.POST.get("entry", "web")
        _item_id = request.POST.get("item_id", None) 
        _item_context = Item(item_id).read()
        _entity_id = _item_context['entity_id'] if _item_context.has_key('entity_id') else -1 
        # WebLogTask.delay(
        #     duration=0,
        #     entry='web',
        #     page='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_id,
        #         'entity_id' : _entity_id,
        #     },
        # )
        return HttpResponse('1')
Esempio n. 2
0
def _get_ustation_entity(entity_id, update_ustation=False):
    _entity = Entity(entity_id)
    _entity_context = _entity.read()

    if _entity_context.has_key('item_id_list') and len(
            _entity_context['item_id_list']):
        _item = Item(_entity_context['item_id_list'][0])
        _item_context = _item.read()

        _entity_context['buy_link'] = _item_context['buy_link']
        _entity_context['taobao_title'] = _item_context['title']
        _entity_context['taobao_id'] = _item_context['taobao_id']
        _entity_context['taobao_shop_nick'] = _item_context['shop_nick']

        if _item_context.has_key('shop_nick') and (
                not _item_context.has_key('ustation')
                or _item_context['ustation'] != 1):
            _shop_context = TaobaoShop(_item_context['shop_nick']).read()
            if _shop_context != None:
                _entity_context['commission_rate'] = _shop_context[
                    'extended_info']['commission_rate']
                if _shop_context['extended_info']['orientational']:
                    _entity_context['commission_type'] = 'orientational'
                else:
                    _entity_context['commission_type'] = 'general'
                if _entity_context['commission_rate'] > 0:
                    if update_ustation:
                        if not _item_context.has_key(
                                'ustation'
                        ) or _item_context['ustation'] == None:
                            _item.update(ustation=0)
                    return _entity_context
    return None
Esempio n. 3
0
def wechat_entity_detail(request, entity_id, template='wap/detail.html'):
    _start_at = datetime.datetime.now()
    if request.user.is_authenticated():
        _request_user_id = request.user.id
    else:
        _request_user_id = None 
    
    _entity_id = int(entity_id) 
    _entity_context = Entity(_entity_id).read()
    
    _is_soldout = True
    _taobao_id = None
    for _item_id in Item.find(entity_id=_entity_id):
        _item_context = Item(_item_id).read()
        _taobao_id = _item_context['taobao_id']
        if not _item_context['soldout']:
            _is_soldout = False
            break
    
    _note_list = []
    for _note_id in Note.find(entity_id=_entity_id, reverse=True):
        _note = Note(_note_id)
        _note_context = _note.read()
        if _note_context['weight'] >= 0:
            _creator_context = User(_note_context['creator_id']).read()
            _note_list.append({
                'note_context' : _note_context,
                'creator_context' : _creator_context,
            })
    
    _liker_list = []
    for _liker in Entity(_entity_id).liker_list(offset=0, count=20):
        _liker_list.append(User(_liker[0]).read())
    
    # _duration = datetime.datetime.now() - _start_at
    # WebLogTask.delay(
    #     duration=_duration.seconds * 1000000 + _duration.microseconds,
    #     entry='wechat',
    #     page='ENTITY',
    #     request=request.REQUEST,
    #     ip=get_client_ip(request),
    #     log_time=datetime.datetime.now(),
    #     request_user_id=_request_user_id,
    #     appendix={
    #         'entity_id' : int(_entity_id),
    #     },
    # )
    return render_to_response(
        template,
        {
            'entity_context' : _entity_context,
            'note_list' : _note_list,
            'liker_list' : _liker_list,
            'buy_link' : _item_context['buy_link'],
        },
        context_instance=RequestContext(request)
    )
Esempio n. 4
0
def _available_ustation_list():

    _t_top = datetime.datetime.now()
    _t_bottom = datetime.datetime.now() - datetime.timedelta(hours=48)

    _entity_context_list = []
    _entity_id_set = set()
    for _item_info in Item.find_ustation():
        _entity_context = _get_ustation_entity(_item_info['entity_id'])
        if _entity_context != None:
            _entity_context_list.append(_entity_context)
            _entity_id_set.add(_item_info['entity_id'])

    for _selection in NoteSelection.objects.filter(
            post_time__lt=_t_top,
            post_time__gt=_t_bottom).order_by('-post_time'):
        try:
            if not _selection.entity_id in _entity_id_set:
                _entity_context = _get_ustation_entity(_selection.entity_id,
                                                       True)
                if _entity_context != None:
                    _entity_context_list.append(_entity_context)
                    _entity_id_set.add(_selection.entity_id)
        except Exception, e:
            pass
Esempio n. 5
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
Esempio n. 6
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
Esempio n. 7
0
def user_tag_entity_list(request, user_id, tag):
    _page_num = int(request.GET.get("p", "1"))
    _entity_id_list = Tag.find_user_tag_entity(user_id, tag)
    _paginator = Paginator(_page_num, 30, len(_entity_id_list))
    _category_title_dict = Category.get_category_title_dict()
    _user_context = User(user_id).read()
    
    _entity_context_list = []
    for _entity_id in _entity_id_list[_paginator.offset : _paginator.offset + _paginator.count_in_one_page]:
        try:
            _entity = Entity(_entity_id)
            _entity_context = _entity.read()
            _entity_context['category_title'] = _category_title_dict[_entity_context['category_id']]
            _entity_context['commission_rate'] = -1 
            _entity_context['commission_type'] = 'unknown' 
            if _entity_context.has_key('item_id_list') and len(_entity_context['item_id_list']):
                _item_context = Item(_entity_context['item_id_list'][0]).read()
                _entity_context['buy_link'] = _item_context['buy_link'] 
                _entity_context['taobao_title'] = _item_context['title'] 
                _entity_context['taobao_id'] = _item_context['taobao_id'] 
                _entity_context['taobao_shop_nick'] = _item_context['shop_nick'] 
                
                if _item_context.has_key('shop_nick'):
                    _shop_context = TaobaoShop(_item_context['shop_nick']).read()
                    if _shop_context != None:
                        if _shop_context['extended_info']['commission'] == True:
                            _entity_context['commission_rate'] = _shop_context['extended_info']['commission_rate']
                            if _shop_context['extended_info']['orientational']:
                                _entity_context['commission_type'] = 'orientational'
                            else:
                                _entity_context['commission_type'] = 'general'
            else:
                _entity_context['buy_link'] = ''
                _entity_context['taobao_title'] = ''
                _entity_context['taobao_id'] = ''
            _entity_context['is_selected'] = False
            if _entity_context.has_key('note_id_list') and len(_entity_context['note_id_list']):
                for _note_id in _entity_context['note_id_list']:
                    _note_context = Note(_note_id).read()
                    if _note_context['is_selected']:
                        _entity_context['is_selected'] = True
                        break
            _entity_context_list.append(_entity_context)
        except Exception, e:
            pass
Esempio n. 8
0
 def __get_context(self):
     context = {}
     entity = Entity(self.activity_obj.entity_id)
     item = Item(self.activity_obj.item_id)
     context['activity_id'] = self.activity_obj.id
     context['entity_context'] = entity.read()
     context['item_context'] = item.read()
     context['shop_nick'] = self.activity_obj.shop_nick
     context['taobao_id'] = self.activity_obj.taobao_id
     context['sale_price'] = self.activity_obj.sale_price
     context['total_volume'] = self.activity_obj.total_volume
     context['sales_volume'] = self.activity_obj.sales_volume
     context['start_time'] = self.activity_obj.start_time
     context['end_time'] = self.activity_obj.end_time
     context['seller_remarks'] = self.activity_obj.seller_remarks
     context['editor_remarks'] = self.activity_obj.editor_remarks
     context['created_time'] = self.activity_obj.created_time
     context['updated_time'] = self.activity_obj.updated_time
     context['status'] = self.activity_obj.status
     return context
Esempio n. 9
0
def sync_entity_without_title(request):
    _offset = int(request.GET.get('offset', '0'))
    _count = int(request.GET.get('count', '100'))

    _category_title_dict = Category.get_category_title_dict()
    _rslt = []
    for _entity_obj in EntityModel.objects.filter(
            Q(title__isnull=True) | Q(title=''))[_offset:_offset + _count]:
        try:
            _title = _category_title_dict[_entity_obj.neo_category_id]
            _context = {
                'entity_id': _entity_obj.id,
                'category_title': _title,
                'item_titles': []
            }
            for _item_id in Item.find(entity_id=_entity_obj.id):
                _context['item_titles'].append(Item(_item_id).read()['title'])
            _rslt.append(_context)
        except Exception, e:
            print e
Esempio n. 10
0
def update_item(request, item_id):
    if request.method == 'POST':
        _price = request.POST.get("price", None)
        _soldout = request.POST.get("soldout", None)
        if _soldout != None:
            if _soldout == '1':
                _soldout = True
            else:
                _soldout = False
        _weight = request.POST.get("weight", None)
        Item(item_id).update(price=_price, soldout=_soldout, weight=_weight)
        return HttpResponseRedirect(request.META['HTTP_REFERER'])
Esempio n. 11
0
def commodities(request, user_context, shop_inst):
    item_list = Item.find_taobao_item(shop_nick=user_context['shop_nick'],
                                      full_info=True)
    for i in range(len(item_list)):
        item = Item(item_list[i]['item_id'])
        item_context = item.read()
        item_list[i]['item'] = item_context
        item_list[i]['entity'] = Entity(item_context['entity_id']).read()
    verification_form = ShopVerificationForm()
    shop_context = shop_inst.read()
    if not shop_context['shop_verified']:
        shop_verification = shop_inst.read_shop_verification()
    else:
        shop_verification = None
    return render_to_response("commodities.html", {
        "item_list": item_list,
        "user_context": user_context,
        "verification_form": verification_form,
        "shop_verification": shop_verification
    },
                              context_instance=RequestContext(request))
Esempio n. 12
0
def shop_detail(request):
    _nick = request.GET.get("nick", None)
    if _nick:
        shop = TaobaoShop(_nick)
        shop_context = shop.read()
        item_list = Item.find_taobao_item(shop_nick=shop_context['shop_nick'],
                                          full_info=True)
        items = []
        for item in item_list:
            inst = Item(item['item_id'])
            item_context = inst.read()
            entity = Entity(item['entity_id'])
            item_context['image'] = entity.read()['chief_image']
            items.append(item_context)
        return render_to_response("shop/detail.html", {
            "shop": shop_context,
            "items": items,
            "gifts": ALL_GIFTS,
            "priorities": range(11),
            "taobao_shop_types": SHOP_TYPES
        },
                                  context_instance=RequestContext(request))
    else:
        return Http404()
Esempio n. 13
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')
Esempio n. 14
0
 def parse_detail(self, response):
     try:
         house_obj = response.extra
         desc = response.xpath('//p[@data-el="houseComment"]/@data-desc')
         info = response.xpath(
             '//h3[@id="info"]/following-sibling::ul[1]//li[position()>1]/text()'
         )
         house_obj['desc'] = desc[0] if desc else ''
         house_obj['info'] = ''.join(info)
         longitude = self.longitude_pat.findall(response.text)
         latitude = self.latitude_pat.findall(response.text)
         house_obj['longitude'] = float(longitude[0]) if longitude else ''
         house_obj['latitude'] = float(latitude[0]) if latitude else ''
         yield Item(house_obj)
     except Exception:
         self.logger.error(response.url + "-->" + format_exc())
Esempio n. 15
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))
Esempio n. 16
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)   
Esempio n. 17
0
def sync_ustation(request):
    _entity_context_list = _available_ustation_list()
    _rslt = []
    for _entity_context in _entity_context_list:
        try:
            _note_id = Note.find(entity_id=_entity_context['entity_id'],
                                 selection=1)[0]
            _note_context = Note(_note_id).read()
            _item_context = Item(_entity_context['item_id_list'][0]).read()
            _shop_nick = _item_context['shop_nick']
            _rslt.append({
                'item_id': _entity_context['taobao_id'],
                'cid': _entity_context['old_root_category_id'],
                'note': _note_context['content'],
                'is_global': TaobaoShop.is_global_shop(_shop_nick)
            })
        except Exception, e:
            pass
Esempio n. 18
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')
Esempio n. 19
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))
Esempio n. 20
0
    def read_full_context(self, request_user_id=None):
        _context = {}
        _context['entity'] = self._read(request_user_id)

        _context['entity']['item_list'] = []
        for _item_id in Item.find(entity_id=self.entity_id)[0:1]:
            _context['entity']['item_list'].append(MobileItem(_item_id).read())
        del _context['entity']['item_id_list']

        _context['note_list'] = []
        for _note_id in _context['entity']['note_id_list']:
            _note_context = MobileNote(_note_id).read(request_user_id)
            if _note_context['weight'] >= 0:
                _context['note_list'].append(_note_context)
        del _context['entity']['note_id_list']

        _context['like_user_list'] = []
        for _like_user in self.liker_list(0, 10):
            _user_id = _like_user[0]
            _context['like_user_list'].append(
                MobileUser(_user_id).read(request_user_id))
        return _context
Esempio n. 21
0
def sync_selection(request):
    _offset = int(request.GET.get('offset', '0'))
    _count = int(request.GET.get('count', '100'))
    _rslt = []
    for _doc in NoteSelection.objects.all().order_by(
            '-post_time')[_offset:_offset + _count]:
        _entity_id = _doc.entity_id
        _entity_context = Entity(_entity_id).read()
        _taobao_id_list = []
        for _item_id in _entity_context['item_id_list']:
            _item_context = Item(_item_id).read()
            _taobao_id_list.append({
                'taobao_id': _item_context['taobao_id'],
                'shop_nick': _item_context['shop_nick'],
            })
        _rslt.append({
            'entity_id': _entity_id,
            'note_id': _doc.note_id,
            'post_time': time.mktime(_doc.post_time.timetuple()),
            'taobao_item_list': _taobao_id_list
        })

    return SuccessJsonResponse(_rslt)
Esempio n. 22
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)
Esempio n. 23
0
 def __init__(self, item_id):
     Item.__init__(self, item_id)
Esempio n. 24
0
def tencent_entity_detail(request, entity_hash, template='tencent/detail.html'):
    _start_at = datetime.datetime.now()
    if request.user.is_authenticated():
        _request_user_id = request.user.id
    else:
        _request_user_id = None 
    
    
    _entity_id = Entity.get_entity_id_by_hash(entity_hash)
    _entity_context = Entity(_entity_id).read()
    
    _is_soldout = True
    _taobao_id = None
    _jd_id = None
    _is_jd = False
    for _item_id in Item.find(entity_id=_entity_id):
        _item_context = Item(_item_id).read()
        if _item_context == None:
            _item_context = JDItem(_item_id).read()
            _jd_id = _item_context['jd_id']
            _is_jd = True
        else:
            _taobao_id = _item_context['taobao_id']
        if not _item_context['soldout']:
            _is_soldout = False
            break
    
    _note_list = []
    for _note_id in Note.find(entity_id=_entity_id, reverse=True):
        _note = Note(_note_id)
        _note_context = _note.read()
        if _note_context['weight'] >= 0:
            _creator_context = User(_note_context['creator_id']).read()
            _note_list.append({
                'note_context' : _note_context,
                'creator_context' : _creator_context,
            })
    
    _liker_list = []
    for _liker in Entity(_entity_id).liker_list(offset=0, count=20):
        _liker_list.append(User(_liker[0]).read())
    
    _duration = datetime.datetime.now() - _start_at
    WebLogTask.delay(
        duration=_duration.seconds * 1000000 + _duration.microseconds,
        entry='tencent',
        page='ENTITY', 
        request=request.REQUEST, 
        ip=get_client_ip(request), 
        log_time=datetime.datetime.now(),
        request_user_id=_request_user_id,
        appendix={ 
            'entity_id' : int(_entity_id),
        },
    )

    return render_to_response(
        template,
        {
            'entity_context' : _entity_context,
            'note_list' : _note_list,
            'liker_list' : _liker_list,
            'buy_link' : _item_context['buy_link'],
            'is_jd' : _is_jd,
        },
        context_instance=RequestContext(request)
    )
Esempio n. 25
0
def entity_list(request):
    _group_id = request.GET.get("gid", None)
    if _group_id == None:
        _status = request.GET.get("status", "select")
        _para = {"status": _status}

        _page_num = int(request.GET.get("p", "1"))
        _category_id = request.GET.get("cid", None)
        if _category_id != None:
            _category_id = int(_category_id)
            _category_context = Category(_category_id).read()
            _category_group_id = _category_context['group_id']
            _categories = Category.find(group_id=_category_context['group_id'])
            for _category in _categories:
                _category['entity_count'] = Entity.count(
                    _category['category_id'])
            _para['cid'] = _category_id
        else:
            _category_context = None
            _category_group_id = None
            _categories = None

        _category_groups = Category.allgroups()
        _select_entity_count = Entity.count(category_id=_category_id,
                                            status='select')
        _novus_entity_count = Entity.count(category_id=_category_id,
                                           status='novus')
        _freeze_entity_count = Entity.count(category_id=_category_id,
                                            status='freeze')
        _recycle_entity_count = Entity.count(category_id=_category_id,
                                             status='recycle')

        _sort_by = request.GET.get("sort_by", "time")
        _reverse = request.GET.get("reverse", None)
        if _sort_by:
            _para["sort_by"] = _sort_by
            _para["reverse"] = _reverse
            if _reverse == '1':
                _reverse = True
            else:
                _reverse = False

        _entity_count = Entity.count(category_id=_category_id, status=_status)

        if _sort_by == 'random':
            _paginator = None
            _entity_id_list = Entity.random(status=_status, count=30)
        else:
            _paginator = Paginator(_page_num, 30, _entity_count, _para)

            _entity_id_list = Entity.find(category_id=_category_id,
                                          status=_status,
                                          offset=_paginator.offset,
                                          count=_paginator.count_in_one_page,
                                          sort_by=_sort_by,
                                          reverse=_reverse)

        _entity_context_list = []
        _category_title_dict = Category.get_category_title_dict()
        for _entity_id in _entity_id_list:
            try:
                _entity = Entity(_entity_id)
                _entity_context = _entity.read()
                _entity_context['category_title'] = _category_title_dict[
                    _entity_context['category_id']]
                _entity_context['commission_rate'] = -1
                _entity_context['commission_type'] = 'unknown'
                if _entity_context.has_key('item_id_list') and len(
                        _entity_context['item_id_list']):
                    _item_context = Item(
                        _entity_context['item_id_list'][0]).read()
                    if _item_context == None:
                        #jd items
                        _item_context = JDItem(
                            _entity_context['item_id_list'][0]).read()
                        _entity_context['buy_link'] = _item_context['buy_link']
                        _entity_context['jd_title'] = _item_context['title']
                        _entity_context['jd_id'] = _item_context['jd_id']
                        _entity_context['_jd_shop_nick'] = _item_context[
                            'shop_nick']
                        _entity_context['commission_rate'] = 4  #默认设为4
                        _entity_context['commission_type'] = 'general'
                    else:
                        _entity_context['buy_link'] = _item_context['buy_link']
                        _entity_context['taobao_title'] = _item_context[
                            'title']
                        _entity_context['taobao_id'] = _item_context[
                            'taobao_id']
                        _entity_context['taobao_shop_nick'] = _item_context[
                            'shop_nick']

                        if _item_context.has_key('shop_nick'):
                            _shop_context = TaobaoShop(
                                _item_context['shop_nick']).read()
                            if _shop_context != None:
                                if _shop_context['extended_info'][
                                        'commission'] == True:
                                    _entity_context[
                                        'commission_rate'] = _shop_context[
                                            'extended_info']['commission_rate']
                                    if _shop_context['extended_info'][
                                            'orientational']:
                                        _entity_context[
                                            'commission_type'] = 'orientational'
                                    else:
                                        _entity_context[
                                            'commission_type'] = 'general'
                else:
                    _entity_context['buy_link'] = ''
                    _entity_context['taobao_title'] = ''
                    _entity_context['taobao_id'] = ''
                _entity_context['is_selected'] = False
                if _entity_context.has_key('note_id_list') and len(
                        _entity_context['note_id_list']):
                    for _note_id in _entity_context['note_id_list']:
                        _note_context = Note(_note_id).read()
                        if _note_context['is_selected']:
                            _entity_context['is_selected'] = True
                            break
                _entity_context_list.append(_entity_context)
            except Exception, e:
                pass

        if _status == 'freeze':
            UpdateNovusStatImpression.delay(impression_type='list')

        return render_to_response('entity/list.html', {
            'active_division': 'entity',
            'status_filter': _status,
            'category_context': _category_context,
            'category_groups': _category_groups,
            'categories': _categories,
            'category_group_id': _category_group_id,
            'select_entity_count': _select_entity_count,
            'novus_entity_count': _novus_entity_count,
            'freeze_entity_count': _freeze_entity_count,
            'recycle_entity_count': _recycle_entity_count,
            'entity_context_list': _entity_context_list,
            'paginator': _paginator,
            'sort_by': _sort_by,
            'reverse': _reverse
        },
                                  context_instance=RequestContext(request))
Esempio n. 26
0
def edit_entity(request, entity_id):
    if request.method == 'GET':
        _code = request.GET.get("code", None)
        _source = request.GET.get("source", "taobao")
        if _source == "jd":
            return edit_jd_entity(request, entity_id)
        if _code == "1":
            _message = "淘宝商品已被创建至本entity"
        else:
            _message = None
        _entity_context = Entity(entity_id).read()
        _item_context_list = []
        for _item_id in Item.find(entity_id=entity_id):
            _item_context = Item(_item_id).read()
            if _item_context == None:
                return edit_jd_entity(request, entity_id)
            if (not _entity_context.has_key('title')
                    or _entity_context['title'] == "") and (
                        not _entity_context.has_key('recommend_title')):
                _entity_context['recommend_title'] = _item_context['title']
            _item_context['commission_type'] = 'unknown'
            _item_context['commission_rate'] = -1
            if _item_context.has_key('shop_nick'):
                _shop_context = TaobaoShop(_item_context['shop_nick']).read()
                if _shop_context != None:
                    if _shop_context['extended_info']['commission'] == True:
                        _item_context['commission_rate'] = _shop_context[
                            'extended_info']['commission_rate']
                        if _shop_context['extended_info']['orientational']:
                            _entity_context[
                                'commission_type'] = 'orientational'
                        else:
                            _entity_context['commission_type'] = 'general'
            _item_context_list.append(_item_context)

        _note_count = Note.count(entity_id=entity_id)

        _users = _get_special_names(request.user.id)
        _mark_list = Entity.Mark.all()

        if _entity_context['weight'] < 0:
            UpdateNovusStatImpression.delay(impression_type='edit')

        return render_to_response('entity/edit.html', {
            'active_division': 'entity',
            'entity_context': _entity_context,
            'category_list': Category.find(),
            'old_category_list': Old_Category.find(),
            'item_context_list': _item_context_list,
            'mark_list': _mark_list,
            'message': _message,
            'note_count': _note_count,
            'users': _users
        },
                                  context_instance=RequestContext(request))
    elif request.method == 'POST':
        _brand = request.POST.get("brand", None)
        _title = request.POST.get("title", None)
        _intro = request.POST.get("intro", None)
        _price = request.POST.get("price", None)
        _weight = int(request.POST.get("weight", '0'))
        _mark = int(request.POST.get("mark", '0'))
        _chief_image_id = request.POST.get("chief_image", None)
        if _price:
            _price = float(_price)
        _category_id = request.POST.get("category_id", None)
        if _category_id:
            _category_id = int(_category_id)
        _old_category_id = request.POST.get("old_category_id", None)
        if _old_category_id:
            _old_category_id = int(_old_category_id)
        _entity = Entity(entity_id)
        _entity.update(
            category_id=_category_id,
            old_category_id=_old_category_id,
            brand=_brand,
            title=_title,
            intro=_intro,
            price=_price,
            chief_image_id=_chief_image_id,
            weight=_weight,
            mark=_mark,
        )

        _note = request.POST.get("note", None)
        _user_id = request.POST.get("user_id", None)
        if _note != None and len(_note) > 0:
            _add_note_and_select_delay(_entity, _user_id, _note)

        return HttpResponseRedirect(request.META['HTTP_REFERER'])
Esempio n. 27
0
def entity_detail(request, entity_hash, template='main/detail.html'):
    _user_agent = request.META['HTTP_USER_AGENT']
    if _user_agent == None:
        log.error("[selection] Remote Host [%s] access selection without user agent" % (request.META['REMOTE_ADDR']))
        raise Http404
    
    _agent = request.GET.get('agent', 'default')
    if _agent == 'default' :
        if 'iPhone' in _user_agent :
            _agent = 'iphone'
        if 'Android' in _user_agent :
            _agent = 'android'
    if _agent == 'iphone' or _agent == 'android' :
        return HttpResponseRedirect(reverse('wap_detail', kwargs = { "entity_hash" : entity_hash })) 
    
    _start_at = datetime.datetime.now()
    if request.user.is_authenticated():
        _request_user_id = request.user.id
        _is_staff = request.user.is_staff
        _request_user_context = User(request.user.id).read() 
        _request_user_like_entity_set = Entity.like_set_of_user(request.user.id)
        _request_user_poke_note_set = Note.poke_set_of_user(request.user.id)
    else:
        _request_user_id = None 
        _is_staff = False 
        _request_user_context = None
        _request_user_like_entity_set = []
        _request_user_poke_note_set = []

    _entity_id = Entity.get_entity_id_by_hash(entity_hash)
    if _entity_id is None:
        raise Http404
    _entity_context = Entity(_entity_id).read()
    # log.info(_entity_context)
    _liker_list = Entity(_entity_id).liker_list(offset=0, count=20)
    _is_user_already_like = True if _entity_id in _request_user_like_entity_set else False
    _tag_list = Tag.entity_tag_stat(_entity_id)
    
    
    _is_soldout = True
    _taobao_id = None
    _jd_id = None
    _activity_id = None
    for _item_id in Item.find(entity_id=_entity_id):
        _item_context = Item(_item_id).read()
        if _item_context == None:
            _item_context = JDItem(_item_id).read()
            _jd_id = _item_context['jd_id']
            if not _item_context['soldout']:
                _is_soldout = False
        else:
            _taobao_id = _item_context['taobao_id']
            if not _item_context['soldout']:
                _is_soldout = False
                break
    if _taobao_id != None:
        try:
            _guokuplus = GuokuPlusActivity.find_by_taobao_id(_taobao_id)
            if _guokuplus != None and _guokuplus.is_active():
                _activity_id = _guokuplus.read()['activity_id']
        except Exception, e:
            pass
Esempio n. 28
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))
Esempio n. 29
0
def clean_ustation(request):
    for _item_info in Item.find_ustation():
        _item = Item(_item_info['item_id'])
        _item.update(ustation=1)

    return HttpResponseRedirect(reverse('management_ustation_list'))
Esempio n. 30
0
def sync_taobao_item(request):
    _offset = int(request.GET.get('offset', '0'))
    _count = int(request.GET.get('count', '100'))

    _taobao_id_list = Item.find(offset=_offset, count=_count, full_info=True)
    return SuccessJsonResponse(_taobao_id_list)