Exemple #1
0
def freeze_user_tag(request, tag, user_id):
    Tag.del_recommend_user_tag(
        user_id = user_id,
        tag = tag,
    ) 
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
     
Exemple #2
0
def user_tag_entity(request, user_id, tag_hash, template="tag/tag_detail.html"):
    # _start_at = datetime.datetime.now()
    # _request_user_id = request.user.id if request.user.is_authenticated() else None
    if request.user.is_authenticated():
        _request_user_id = request.user.id
        _request_user_like_entity_set = Entity.like_set_of_user(_request_user_id)
    else:
        _request_user_id = None
        _request_user_like_entity_set = list()

    _user_context = User(user_id).read()
    _tag_text = Tag.get_tag_text_from_hash(tag_hash)
    
    _page_num = request.GET.get('p', 1)
    
    _entity_id_list = Tag.find_user_tag_entity(user_id, _tag_text)
    _paginator = Paginator(_page_num, 24, len(_entity_id_list))
    
    _entities = list()
    for _entity_id in _entity_id_list[_paginator.offset : _paginator.offset + _paginator.count_in_one_page]:
        try:
            _entity_context = Entity(_entity_id).read()
            _entity_context['is_user_already_like'] = True if _entity_id in _request_user_like_entity_set else False
            _entities.append(_entity_context)
            # _entities.append(Entity(_entity_id).read())
        except Exception, e:
            log.error(e.message)
Exemple #3
0
    def __init__(self, channel: Channel):
        self.ID = bitarray(MESSAGE_SIZE)
        self.IDS = bitarray(MESSAGE_SIZE)
        self.K1 = bitarray(MESSAGE_SIZE)
        self.K2 = bitarray(MESSAGE_SIZE)
        self.K3 = bitarray(MESSAGE_SIZE)
        self.K4 = bitarray(MESSAGE_SIZE)
        self.n1 = None
        self.n2 = None

        Tag.__init__(self, 'emap', channel)
Exemple #4
0
def tag_suggest(request):
    _prefix = request.GET.get("prefix", None)
    _rslt = []
    if _prefix != None and len(_prefix) > 0:
        _tag_prefix_index = Tag.read_tag_prefix_index()
        if _tag_prefix_index.has_key(_prefix):
            _rslt = _tag_prefix_index[_prefix][0:5]
    else:
        _user_latest_tag_list = Tag.read_user_latest_tag_list(request.user.id)
        if _user_latest_tag_list != None or len(_user_latest_tag_list) > 0:
            _rslt = _user_latest_tag_list[0:5]
    
    return JSONResponse(data=_rslt)
Exemple #5
0
def user_tag_list(request):
    _page_num = int(request.GET.get("p", "1"))
    _type = request.GET.get("type", "all")
    _user_id = request.GET.get("user", None)
    if _user_id != None:
        _user_id = int(_user_id)
    _tag = request.GET.get("tag", None)

    _recommend_user_tag_list = Tag.get_recommend_user_tag_list(with_entity_count = False)
    
    if _type == 'recommend':
        _user_tag_list = []
        for _user_tag in _recommend_user_tag_list:
            _user_tag_list.append({
                'user_id' : _user_tag[0], 
                'tag_text' : _user_tag[1], 
                'entity_count' : Tag.get_user_tag_entity_count(_user_tag[0], _user_tag[1])
            })
    else:
        _user_tag_list = Tag.find_user_tag(user_id = _user_id, tag = _tag)
    _paginator = Paginator(_page_num, 30, len(_user_tag_list), {"type" : _type})

    _context_list = []
    for _data in _user_tag_list[_paginator.offset : _paginator.offset + _paginator.count_in_one_page]:
        try:
            _user = User(_data['user_id'])
            _user_context = _user.read()
            if [_user_context['user_id'], _data['tag_text']] in _recommend_user_tag_list:
                _status = 1
            else:
                _status = 0
            _context_list.append({
                'tag' : _data['tag_text'],
                'user' : _user_context, 
                'entity_count' : _data['entity_count'],
                'status' : _status
            })
        except Exception, e:
            pass
Exemple #6
0
def user_tags(request, user_id, template=TEMPLATE):
    _start_at = datetime.datetime.now()
    _query_user = User(user_id)
    _query_user_context = _query_user.read()
    if request.user.is_authenticated():
        _request_user_id = request.user.id
        _request_user_context = User(_request_user_id).read() 
        _relation = User.get_relation(_request_user_context['user_id'], _query_user_context['user_id']) 
    else:
        _request_user_id = None 
        _request_user_context = None
        _relation = None 

    _page_num = int(request.GET.get('p', '1'))
    _tag_stat_list = Tag.user_tag_stat(user_id)
    _total_count = len(_tag_stat_list)
    _paginator = Paginator(_page_num, 20, len(_tag_stat_list))

    _tag_list = []
    _log_tags = []
    for _tag_stat in _tag_stat_list[_paginator.offset : _paginator.offset + _paginator.count_in_one_page]:
        try:
            _tag_id = _tag_stat['tag_id']
            _tag_hash = _tag_stat['tag_hash']
            _tag = _tag_stat['tag']
            _entity_id_list = Tag.find_user_tag_entity(user_id, _tag)
            _entity_count = len(_entity_id_list)
            _entity_list = [Entity(x).read() for x in _entity_id_list[:4]]
    
            _tag_list.append({
                'tag' : _tag,
                'tag_id' : _tag_id,
                'tag_hash' : _tag_hash,
                'entity_list' : _entity_list,
                'entity_count' : _entity_count
            })
            _log_tags.append(_tag)
        except Exception, e:
            pass
Exemple #7
0
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
Exemple #8
0
def web_message(request, template='account/message.html'):
    _start_at = datetime.now()
    if request.method == "GET":
        _request_user_id = request.user.id
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.fromtimestamp(float(_timestamp))
        else:
            _timestamp = datetime.now()
        _count = int(request.GET.get('count', 30))

        _recommend_tag_list = Tag.get_recommend_user_tag_list()

        _popular_list = popularity.read_popular_user_context()
        _popular_list_detail = []
        if _popular_list != None:
            for _popular_user in _popular_list["data"]:
                try:
                    _popu_context = {
                        "user_id":
                        _popular_user["user_id"],
                        "user_context":
                        User(_popular_user["user_id"]).read(),
                        "relation":
                        User.get_relation(_request_user_id,
                                          _popular_user["user_id"])
                    }
                    _popular_list_detail.append(_popu_context)
                except Exception, e:
                    print e
                    pass
        _rslt = []
        for _message in NeoMessage.objects.filter(
                user_id=_request_user_id,
                created_time__lt=_timestamp).order_by(
                    '-created_time')[0:_count]:
            try:
                if isinstance(_message, UserFollowMessage):
                    _context = {
                        'type':
                        'user_follow',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'follower':
                            User(_message.follower_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NotePokeMessage):
                    _context = {
                        'type':
                        'note_poke_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'poker':
                            User(_message.poker_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NoteCommentMessage):
                    _context = {
                        'type':
                        'note_comment_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'comment':
                            Note(_message.note_id).read_comment(
                                _message.comment_id),
                            'comment_user':
                            User(_message.comment_creator_id).read(
                                _request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NoteCommentReplyMessage):
                    _context = {
                        'type':
                        'note_comment_reply_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'comment':
                            Note(_message.note_id).read_comment(
                                _message.comment_id),
                            'replying_comment':
                            Note(_message.note_id).read_comment(
                                _message.replying_comment_id),
                            'replying_user':
                            User(_message.replying_user_id).read(
                                _request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, EntityLikeMessage):
                    _context = {
                        'type':
                        'entity_like_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'liker':
                            User(_message.liker_id).read(_request_user_id),
                            'entity':
                            Entity(_message.entity_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, EntityNoteMessage):
                    _context = {
                        'type':
                        'entity_note_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'entity':
                            Entity(_message.entity_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
                elif isinstance(_message, NoteSelectionMessage):
                    _context = {
                        'type':
                        'note_selection_message',
                        'created_time':
                        datetime.fromtimestamp(
                            time.mktime(_message.created_time.timetuple())),
                        'content': {
                            'note':
                            Note(_message.note_id).read(_request_user_id),
                            'entity':
                            Entity(_message.entity_id).read(_request_user_id)
                        }
                    }
                    _rslt.append(_context)
            except Exception, e:
                print e
                pass
Exemple #9
0
def transcend_user_tag(request, tag, user_id):
    Tag.add_recommend_user_tag(
        user_id = user_id,
        tag = tag,
    ) 
    return HttpResponseRedirect(request.META['HTTP_REFERER'])
Exemple #10
0
def search(request, template='search/search.html'):
    _start_at = datetime.datetime.now()
    if request.user.is_authenticated():
        _request_user_id = request.user.id
        _request_user_context = User(_request_user_id).read()
        _request_user_like_entity_set = Entity.like_set_of_user(
            request.user.id)
    else:
        _request_user_id = None
        _request_user_context = None
        _request_user_like_entity_set = []

    _query = request.GET.get('q', None)
    _group = request.GET.get('g', 'e')  # e->entity, u->user, t->tag
    _page = request.GET.get('p', 1)

    _entity_list = []
    _user_list = []
    _tag_list = []
    _log_appendix = {'query': _query}

    if _query == None or _query == '':
        _entity_id_list = []
        _user_id_list = []
        _tag_list = []
        _paginator = None
    else:
        _entity_id_list = Entity.search(query_string=_query, )
        _user_id_list = User.search(query_string=_query, )
        _tag_list = Tag.search(query_string=_query)

        if _group == 'u':
            _paginator = Paginator(_page, 8, len(_user_id_list), {
                'q': _query,
                'g': 'u'
            })
            for _u_id in _user_id_list[_paginator.offset:_paginator.offset +
                                       _paginator.count_in_one_page]:
                try:
                    _user = User(_u_id)
                    _user_context = _user.read()
                    if _request_user_context != None:
                        _user_context['relation'] = User.get_relation(
                            _request_user_context['user_id'], _u_id)
                    _user_context[
                        'latest_like_entity_id_list'] = _user.read_latest_like_entity_list(
                        )
                    _user_list.append(_user_context)
                except Exception, e:
                    pass
            _log_appendix['type'] = 'user'
            _log_appendix['result_users'] = _user_id_list[
                _paginator.offset:_paginator.offset +
                _paginator.count_in_one_page]
        elif _group == 't':
            _paginator = Paginator(_page, 24, len(_tag_list), {
                'q': _query,
                'g': 't'
            })
            _log_appendix['type'] = 'tag'
            _log_appendix['result_tags'] = []
            for _tag_context in _tag_list[_paginator.offset:_paginator.offset +
                                          _paginator.count_in_one_page]:
                try:
                    _tag_entity_id_list = Tag.find_tag_entity(
                        _tag_context['tag_hash'])
                    _tag_context['entity_count'] = len(_tag_entity_id_list)
                    _tag_context['entity_list'] = [
                        Entity(x).read() for x in _tag_entity_id_list[:4]
                    ]
                    _log_appendix['result_tags'].append(_tag_context['tag'])
                except Exception, e:
                    pass
Exemple #11
0
def tag_origin(request, tag):
    _tag_hash = Tag.get_tag_hash_from_text(tag) 
    return HttpResponsePermanentRedirect(reverse('web_tag_detail', kwargs = { "tag_hash" : _tag_hash }))
Exemple #12
0
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