def wechat_entity_detail(request, entity_id, template='wap/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 = int(entity_id) _entity_context = Entity(_entity_id).read() _is_soldout = True _taobao_id = None for _item_id in Item.find(entity_id=_entity_id): _item_context = Item(_item_id).read() _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='wechat', # 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'], }, context_instance=RequestContext(request) )
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 read_full_context(self, request_user_id=None): _context = {} _context['entity'] = self._read(request_user_id) _context['entity']['item_list'] = [] for _item_id in Item.find(entity_id=self.entity_id)[0:1]: _context['entity']['item_list'].append(MobileItem(_item_id).read()) del _context['entity']['item_id_list'] _context['note_list'] = [] for _note_id in _context['entity']['note_id_list']: _note_context = MobileNote(_note_id).read(request_user_id) if _note_context['weight'] >= 0: _context['note_list'].append(_note_context) del _context['entity']['note_id_list'] _context['like_user_list'] = [] for _like_user in self.liker_list(0, 10): _user_id = _like_user[0] _context['like_user_list'].append( MobileUser(_user_id).read(request_user_id)) return _context
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 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 sync_taobao_item(request): _offset = int(request.GET.get('offset', '0')) _count = int(request.GET.get('count', '100')) _taobao_id_list = Item.find(offset=_offset, count=_count, full_info=True) return SuccessJsonResponse(_taobao_id_list)