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
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
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))
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))