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')
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 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))
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'])
def visit_item(request, item_id): _start_at = datetime.datetime.now() if item_id == '533bd0caa2128a11428c912b': _session = request.GET.get('session', None) if _session != None: _request_user_id = Session_Key.objects.get_user_id(_session) else: _request_user_id = None _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") 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) _item_context = Item(item_id).read() if _item_context == None: return __visit_jd_item(request, item_id) _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_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'], 'entity_id': _entity_id, 'tbk': False, }) return HttpResponseRedirect( decorate_taobao_url( get_taobao_url(_item_context['taobao_id'], True), _ttid, _sid, _outer_code, _sche))