コード例 #1
0
def handle_shop_verification(request):
    shop_nick = request.POST.get("shop_nick", None)
    editor_remarks = request.POST.get("editor_remarks", None)
    action = request.POST.get("action", None)
    shop_inst = TaobaoShop(shop_nick)
    shop_inst.handle_shop_verification(action)
    return HttpResponseRedirect(reverse("management_shop_verification_list"))
コード例 #2
0
 def run(self, nick, shop_link):
     if not TaobaoShop.nick_exist(nick):
         _shop_info = TaobaoExtractor.fetch_shop(shop_link)
         _shop = TaobaoShop.create(nick=nick,
                                   shop_id=_shop_info['shop_id'],
                                   title=_shop_info['title'],
                                   shop_type=_shop_info['type'],
                                   seller_id=_shop_info['seller_id'],
                                   pic_path=_shop_info['pic'])
コード例 #3
0
def bind_taobao_shop(request):
    user_id = request.user.id
    user_inst = User(user_id)
    request_user_context = user_inst.read()
    if request.method == "GET":
        taobao_nick = request_user_context.get("taobao_nick", None)
        taobao_shop = None
        if taobao_nick and TaobaoShop.nick_exist(taobao_nick):
            taobao_shop = TaobaoShop(taobao_nick).read()
        return render_to_response(
            "bind_taobao_shop.html",
            { 
                "user_context" : request_user_context, 
                "taobao_shop" : taobao_shop
            },
            context_instance=RequestContext(request)
        )
    elif request.method == "POST":
        if not request_user_context.get("taobao_nick"):
            messages.info(request, u"尚未绑定淘宝帐号") 
            return HttpResponseRedirect(reverse('seller_bind_taobao_shop'))
        item_url = request.POST.get('item_url', None)
        if not item_url:
            message.info(request, u"请输入商品地址")
            return HttpResponseRedirect(reverse('seller_bind_taobao_shop'))
      
        if is_taobao_url(item_url):
            taobao_id = parse_taobao_id_from_url(item_url)
            taobao_item_info = TaobaoExtractor.fetch_item(taobao_id)
            nick = taobao_item_info['nick'].decode("utf-8")
            user_taobao_nick = request_user_context.get('taobao_nick')
            if user_taobao_nick == nick:
                user_inst.create_seller_info(nick)
                if not TaobaoShop.nick_exist(nick):
                    shop_info = TaobaoExtractor.fetch_shop(taobao_item_info['shop_link'])
                    TaobaoShop.create(
                        shop_info['nick'],
                        shop_info['shop_id'],
                        shop_info['title'],
                        shop_info['type'],
                        shop_info['seller_id'],
                        shop_info['pic']
                    ) 
                return HttpResponseRedirect(reverse('seller_bind_taobao_shop'))
            else:
                messages.info(request, u"错误的商品地址,请输入淘宝商品地址")
                return HttpResponseRedirect(reverse('seller_bind_taobao_shop'))
        else:
            return HttpResponseRedirect(reverse('seller_bind_taobao_shop'))
コード例 #4
0
def add_shop(request):
    _shop_link = request.POST.get("shop_link", None)
    if _shop_link:
        _shop_info = TaobaoExtractor.fetch_shop(_shop_link)

        if not TaobaoShop.nick_exist(_shop_info['nick']):
            TaobaoShop.create(nick=_shop_info['nick'],
                              shop_id=_shop_info['shop_id'],
                              seller_id=_shop_info['seller_id'],
                              title=_shop_info['title'],
                              shop_type=_shop_info['type'],
                              pic_path=_shop_info['pic'])
        else:
            messages.info(request, "该店铺已经存在")
        return HttpResponseRedirect(reverse("management_shop_list"))
コード例 #5
0
ファイル: ustation.py プロジェクト: guoku/Raspberry
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
コード例 #6
0
def edit_shop(request):
    _nick = request.POST.get("nick", None)
    if _nick:
        _priority = int(request.POST.get('priority', '10'))
        _cycle = int(request.POST.get('cycle', '720'))
        _shop_type = request.POST.get('shoptype', 'taobao.com')
        _orientational = request.POST.get('orientational', 'false')
        if _orientational == "false":
            _orientational = False
        else:
            _orientational = True
        _commission_rate = float(request.POST.get("commission_rate", "-1"))
        _original = request.POST.get('original', 'false')
        if _original == "false":
            _original = False
        else:
            _original = True
        _gifts = request.POST.getlist("gifts")
        _commission = request.POST.get('commission', 'false')
        if _commission == "false":
            _commission = False
        else:
            _commission = True
        _single_tail = request.POST.get('single_tail', 'false')
        if _single_tail == "false":
            _single_tail = False
        else:
            _single_tail = True

        _main_products = request.POST.get('main_products', "")
        shop = TaobaoShop(_nick)
        shop.update(priority=_priority,
                    cycle=_cycle,
                    shop_type=_shop_type,
                    orientational=_orientational,
                    commission=_commission,
                    commission_rate=_commission_rate,
                    original=_original,
                    gifts=_gifts,
                    main_products=_main_products,
                    single_tail=_single_tail)
        return HttpResponseRedirect(
            reverse("management_shop_detail") + "?nick=" + _nick)
    else:
        return Http404()
コード例 #7
0
 def seller_only_decorator(request, *args, **kwargs):
     user_inst = User(request.user.id)
     user_context = user_inst.read()
     shop_nick = user_context.get("shop_nick", None)
     if shop_nick:
         shop_inst = TaobaoShop(shop_nick)
         kwargs['user_context'] = user_context
         kwargs['shop_inst'] = shop_inst
         return func(request, *args, **kwargs)
     else:
         return HttpResponseRedirect(reverse("seller_bind_taobao_shop"))
コード例 #8
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()
コード例 #9
0
ファイル: tag.py プロジェクト: guoku/Raspberry
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
コード例 #10
0
def shop_verification_list(request):
    _num_every_page = 30
    _para = {}
    _p = int(request.GET.get("p", "1"))
    _status = request.GET.get("status", None)
    if _status:
        _para['status'] = _status
    _results, _total = TaobaoShop.read_shop_verification_list(
        status=_status,
        offset=(_p - 1) * _num_every_page,
        count=_num_every_page)
    _paginator = Paginator(_p, _num_every_page, _total, _para)
    return render_to_response('shop/verification_list.html', {
        'status_filter': _status,
        'results': _results,
        'paginator': _paginator,
    },
                              context_instance=RequestContext(request))
コード例 #11
0
ファイル: ustation.py プロジェクト: guoku/Raspberry
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
コード例 #12
0
def shop_list(request):
    _para = {}
    _p = int(request.GET.get("p", 1))
    _nick = request.GET.get("nick", None)
    if _nick:
        _para['nick'] = unicode(_nick)

    _sort_by = request.GET.get("sort_by", "-created_time")
    if _sort_by:
        _sort_on = _sort_by
        _para['sort_by'] = _sort_by
        _order = request.GET.get("order", "asc")
        _para['order'] = _order
        if _sort_by == "priority":
            _sort_on = "crawler_info.priority"
        elif _sort_by == "commission_rate":
            _sort_on = "extended_info.commission_rate"
        else:
            _sort_on = _sort_by
        if _order == "desc":
            _sort_on = "-" + _sort_on
    else:
        _sort_on = "-created_time"
        _sort_by = "created_time"
        _order = "desc"

    _gifts = request.GET.getlist("gifts")
    if _gifts:
        _para['gifts'] = _gifts
    _offset = NUM_EVERY_PAGE * (_p - 1)
    _shops, _count = TaobaoShop.find(_nick, _offset, NUM_EVERY_PAGE, _sort_on,
                                     _gifts)
    _paginator = Paginator(_p, NUM_EVERY_PAGE, _count, _para)

    return render_to_response('shop/list.html', {
        'shops': _shops,
        'sort_by': _sort_by,
        'order': _order,
        'gifts': _gifts,
        'all_gifts': ALL_GIFTS,
        'paginator': _paginator
    },
                              context_instance=RequestContext(request))
コード例 #13
0
ファイル: entity.py プロジェクト: guoku/Raspberry
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))
コード例 #14
0
ファイル: entity.py プロジェクト: guoku/Raspberry
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'])