Exemplo n.º 1
0
def category_list(request):
    _group_id = request.GET.get("gid", None)
    if _group_id != None:
        _group_id = int(_group_id)
    _status = request.GET.get("status", None)
    if _status != None:
        _status = int(_status)

    _all_count = len(Category.find(group_id=_group_id))
    _normal_count = len(Category.find(group_id=_group_id, status=1))
    _freeze_count = _all_count - _normal_count

    _category_groups = Category.allgroups()
    _categories = Category.find(group_id=_group_id,
                                status=_status,
                                order_by='-status')

    for _category in _categories:
        _category["group_title"] = Category_Group(
            _category["group_id"]).read()["title"]

    return render_to_response('category/list.html', {
        'active_division': 'category',
        'category_groups': _category_groups,
        'categories': _categories,
        'selected_group_id': _group_id,
        'status': _status,
        'all_count': _all_count,
        'normal_count': _normal_count,
        'freeze_count': _freeze_count
    },
                              context_instance=RequestContext(request))
Exemplo n.º 2
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')
Exemplo n.º 3
0
def search_entity(request):
    if request.method == 'POST':
        _query = request.POST.get("query", None)
    elif request.method == 'GET':
        _query = request.GET.get("q", None)

    _category_groups = Category.allgroups()
    #    _entity_id_list = Entity.find(like_word = _query)
    _entity_context_list = []
    _category_title_dict = Category.get_category_title_dict()
    #    for _entity_id in _entity_id_list:
    #        _entity = Entity(_entity_id)
    #        _entity_context = _entity.read()
    #        _entity_context['category_title'] = _category_title_dict[_entity_context['category_id']]
    #        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']
    #        else:
    #            _entity_context['buy_link'] = ''
    #            _entity_context['taobao_title'] = ''
    #        _entity_context_list.append(_entity_context)

    _category_context_list = Category.find(like_word=_query)

    return render_to_response(
        'entity/search.html',
        {
            'active_division': 'entity',
            'query': _query,
            'category_groups': _category_groups,
            #'entity_context_list' : _entity_context_list,
            'entity_context_list': [],
            'category_context_list': _category_context_list,
        },
        context_instance=RequestContext(request))
Exemplo n.º 4
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))
Exemplo n.º 5
0
def edit_jd_entity(request, entity_id):
    if request.method == "GET":
        _code = request.GET.get("code", None)
        if _code == "1":
            _message = "京东商品已被创建至本entity"
        else:
            _message = None
        _entity_context = Entity(entity_id).read()
        _item_context_list = []
        for _item_id in JDItem.find(entity_id=entity_id):
            _item_context = JDItem(_item_id).read()
            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'] = 4  #jd的佣金是根据品类来区分的
            _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()

        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)
        _reset_created_time = request.POST.get("reset_created_time", "off")
        if _reset_created_time == "on":
            _reset_created_time = True
        else:
            _reset_created_time = False

        _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,
                       reset_created_time=_reset_created_time)

        _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'])
Exemplo n.º 6
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'])
Exemplo n.º 7
0
         '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))
 else:
     _categories = Category.find(group_id=int(_group_id))
     _category_groups = Category.allgroups()
     if len(_categories) == 0:
         _normal_entity_count = 0
         _freeze_entity_count = 0
         return render_to_response('entity/list.html', {
             'active_division': 'entity',
             'category_context': None,
             'category_groups': _category_groups,
             'categories': _categories,
             'category_group_id': int(_group_id),
             'normal_entity_count': _normal_entity_count,
             'freeze_entity_count': _freeze_entity_count,
             'entity_context_list': [],
         },
                                   context_instance=RequestContext(request))