def __visit_jd_item(request, item_id): _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) _item_context = JDItem(item_id).read() buy_link = get_jd_url(_item_context['jd_id'], is_mobile=True) _duration = datetime.datetime.now() - _start_at _entity_id = _item_context['entity_id'] if _item_context.has_key( 'entity_id') else -1 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': 'jd', 'jd_id': _item_context['jd_id'], 'entity_id': _entity_id, 'tbk': False, }) return HttpResponseRedirect(decorate_jd_url(buy_link))
def new_jd_item(request): _cand_url = request.POST.get("url", None) _jd_id = parse_jd_id_from_url(_cand_url) _item = JDItem.get_item_by_jd_id(_jd_id) if _item == None: _jd_item_info = load_jd_item_info(_jd_id) _users = _get_special_names(request.user.id) return render_to_response('entity/create_jd.html', { 'active_division': 'entity', 'jd_id': _jd_id, 'category': _jd_item_info['category'], 'jd_title': _jd_item_info['title'], 'shop_nick': _jd_item_info['nick'], 'shop_link': _jd_item_info['shop_link'], 'price': _jd_item_info['price'], 'thumb_images': _jd_item_info['thumb_images'], 'brand': _jd_item_info['brand'], 'title': _jd_item_info['title'], 'users': _users, 'selected_category_id': "" }, context_instance=RequestContext(request)) elif _item.get_entity_id() == -1: pass else: return HttpResponseRedirect( reverse('management_edit_jd_entity', kwargs={'entity_id': _item.get_entity_id()}) + '?code=1')
def jd_info(request, _cand_url): _jd_id = parse_jd_id_from_url(_cand_url) _item = JDItem.get_item_by_jd_id(_jd_id) _rslt = {} if _item == None: _jd_item_info = load_jd_item_info(_jd_id) _chief_image_url = _jd_item_info['thumb_images'][0] #TODO:进行京东类目转换 #TODO :先用一个cid暂时使用着先 cid = '1512' _selected_category_id = Category.get_category_by_jd_cid(cid) _data = { 'user_context' : User(request.user.id).read(), 'cand_url' : _cand_url, 'jd_id' : _jd_id, 'jd_title' : _jd_item_info['title'], 'shop_nick' : _jd_item_info['nick'], 'shop_link' : _jd_item_info['shop_link'], 'brand' : _jd_item_info['brand'], 'price' : _jd_item_info['price'], 'chief_image_url' : _chief_image_url, 'thumb_images' :[x.replace("/n1/", "/n5/") for x in _jd_item_info['thumb_images']], 'cid' : cid, '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))
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_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'])
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
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) )
def read(self): _context = super(MobileItem, self).read() if _context == None: #TODO 这里必须特别注意,权宜之计,Item修改后要对这里进行修改 _context = JDItem(self.item_id).read() return _context