Example #1
0
def search_entity_note(request):
    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

        _query_string = request.GET.get('q')
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        _note_id_list = MobileNote.search(
            query_string = _query_string
        )
        
        _rslt = []
        for _note_id in _note_id_list:
            _note_context = MobileNote(_note_id).read(_request_user_id)
            if _note_context.has_key('entity_id'):
                _entity = MobileEntity(_note_context['entity_id'])
                _rslt.append({
                    'entity' : _entity.read(_request_user_id),
                    'note' : _note_context,
                })
        
        return SuccessJsonResponse(_rslt)
Example #2
0
def entity_list(request):
    _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
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.datetime.fromtimestamp(float(_timestamp))

        _sort_by = request.GET.get('sort', 'novus_time')
        _reverse = request.GET.get('reverse', '0')
        if _reverse == '0':
            _reverse = False
        else:
            _reverse = True
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        _root_old_cat_id = request.GET.get('rcat', None)
        if _root_old_cat_id != None:
            _root_old_cat_id = int(_root_old_cat_id)

        _entity_id_list = MobileEntity.find(
            root_old_category_id=_root_old_cat_id,
            timestamp=_timestamp,
            offset=_offset,
            count=_count,
            sort_by=_sort_by,
            reverse=_reverse,
            status='novus')

        _rslt = []
        for _entity_id in _entity_id_list:
            try:
                _entity = MobileEntity(_entity_id)
                _entity_context = _entity.read(_request_user_id)
                _entity_context['updated_time'] = _entity_context['novus_time']
                _rslt.append(_entity_context)
            except Exception, e:
                pass

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='NOVUS',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={'result_entities': _entity_id_list},
        )

        return SuccessJsonResponse(_rslt)
Example #3
0
def search_entity(request):
    _start_at = datetime.datetime.now()
    if request.method == "GET":
        _session = request.GET.get('session', None)
        _type = request.GET.get('type', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _query_string = request.GET.get('q')
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))

        _entity_id_list = MobileEntity.search(query_string=_query_string, )
        _rslt = {
            'stat': {
                'all_count': len(_entity_id_list),
                'like_count': 0,
            },
            'entity_list': []
        }

        if _request_user_id != None:
            _like_set = MobileEntity.like_set_of_user(_request_user_id)
            _like_entity_id_list = _like_set.intersection(_entity_id_list)
            _rslt['stat']['like_count'] = len(_like_entity_id_list)
            if _type == 'like':
                _entity_id_list = list(_like_entity_id_list)

        for _entity_id in _entity_id_list[_offset:_offset + _count]:
            _entity = MobileEntity(_entity_id)
            _rslt['entity_list'].append(_entity.read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='SEARCH_ENTITY',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'query': _query_string,
                'result_entities': _entity_id_list[_offset:_offset + _count],
            },
        )

        return SuccessJsonResponse(_rslt)
Example #4
0
def user_entity_note(request, user_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
        _timestamp = request.GET.get('timestamp', None)
        if _timestamp != None:
            _timestamp = datetime.datetime.fromtimestamp(float(_timestamp))
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))

        _rslt = []
        _note_id_list = MobileNote.find(creator_set=[user_id],
                                        timestamp=_timestamp,
                                        offset=_offset,
                                        count=_count)
        for _note_id in _note_id_list:
            try:
                _note_context = MobileNote(_note_id).read(_request_user_id)
                if _note_context.has_key('entity_id'):
                    _entity = MobileEntity(_note_context['entity_id'])
                    _rslt.append({
                        'entity': _entity.read(_request_user_id),
                        'note': _note_context,
                    })
            except:
                pass

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_NOTE',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'user_id': int(user_id),
                'result_notes': _note_id_list
            },
        )
        return SuccessJsonResponse(_rslt)
Example #5
0
def category_entity_note(request, category_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
        _sort_by = request.GET.get('sort', 'poke')
        if _sort_by == '':
            _sort_by = 'poke'
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        
        _note_id_list = MobileNote.find(
            category_id = category_id,
            offset = _offset,
            count = _count,
            sort_by = _sort_by
        )
        _rslt = []
        for _note_id in _note_id_list:
            _note_context = MobileNote(_note_id).read(_request_user_id)
            if _note_context.has_key('entity_id'):
                _entity = MobileEntity(_note_context['entity_id'])
                _rslt.append({
                    'entity' : _entity.read(_request_user_id),
                    'note' : _note_context,
                })
            
        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration = _duration.seconds * 1000000 + _duration.microseconds, 
            view = 'CATEGORY_NOTE_LIST', 
            request = request.REQUEST, 
            ip = get_client_ip(request), 
            log_time = datetime.datetime.now(),
            request_user_id = _request_user_id,
            appendix = { 
                'neo_category_id' : int(category_id),
                'result_notes' : _note_id_list
            },
        )
        return SuccessJsonResponse(_rslt)
Example #6
0
def category_user_like(request, category_id, user_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

        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        _sort_by = request.GET.get('sort', 'new')
        _reverse = request.GET.get('reverse', '0')
        if _reverse == '0':
            _reverse = False
        else:
            _reverse = True

        _entity_id_list = MobileUser(user_id).find_like_entity(
            neo_category_id=category_id,
            offset=_offset,
            count=_count,
            sort_by=_sort_by,
            reverse=_reverse)
        _rslt = []
        for _entity_id in _entity_id_list:
            _entity = MobileEntity(_entity_id)
            _rslt.append(_entity.read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='CATEGORY_USER_LIKE',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'neo_category_id': int(category_id),
                'user_id': int(user_id),
                'result_entities': _entity_id_list
            },
        )
        return SuccessJsonResponse(_rslt)