예제 #1
0
def guess_entity(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
        _category_id = request.GET.get('cid', None)
        _count = int(request.GET.get('count', '5'))
        if _category_id != None:
            _category_id = int(_category_id)
        _rslt = []
        _entity_id_list = []
        for _entity_id in MobileEntity.roll(category_id=_category_id,
                                            count=_count):
            _rslt.append(MobileEntity(_entity_id).read(_request_user_id))
            _entity_id_list.append(_entity_id)

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='GUESS_ENTITY',
            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_entities': _entity_id_list
            },
        )

        return SuccessJsonResponse(_rslt)
예제 #2
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)
예제 #3
0
파일: user.py 프로젝트: guoku/Raspberry
def user_detail(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

        _rslt = {}
        _rslt['user'] = MobileUser(user_id).read(_request_user_id)
        _last_note_id = MobileNote.get_user_last_note(user_id)
        if _last_note_id != None:
            _rslt['last_note'] = MobileNote(_last_note_id).read(
                _request_user_id)
        _last_like_entity_id = MobileEntity.get_user_last_like(user_id)
        if _last_like_entity_id != None:
            _rslt['last_like'] = MobileEntity(_last_like_entity_id).read(
                _request_user_id)

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER',
            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),
            },
        )
        return SuccessJsonResponse(_rslt)
예제 #4
0
def add_note_for_entity(request, entity_id):
    if request.method == "POST":
        _session = request.POST.get('session', None)
        _note_text = request.POST.get('note', None)
        _score = int(request.POST.get('score', '0'))

        _image_file = request.FILES.get('image', None)
        if _image_file == None:
            _image_data = None
        else:
            if hasattr(_image_file, 'chunks'):
                _image_data = ''.join(chunk for chunk in _image_file.chunks())
            else:
                _image_data = _image_file.read()

        _request_user_id = Session_Key.objects.get_user_id(_session)
        _entity = MobileEntity(entity_id)
        try:
            _note = _entity.add_note(
                creator_id=_request_user_id,
                note_text=_note_text,
                score=_score,
                image_data=_image_data,
            )
        except MobileNote.UserAddNoteForEntityAlready, e:
            return ErrorJsonResponse(data={
                'type': 'user_add_note_for_entity_already',
                'message': str(e)
            },
                                     status=400)

        _context = _note.read(request_user_id=_request_user_id)
        return SuccessJsonResponse(_context)
예제 #5
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)
예제 #6
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)
예제 #7
0
def entity_note_detail(request, note_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
        
        _rslt = {}
        _rslt = MobileNote(note_id).read_note_full_context(_request_user_id)
        if _rslt['note'].has_key('entity_id'):
            _rslt['entity'] = MobileEntity(_rslt['note']['entity_id']).read(_request_user_id)
        
        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration = _duration.seconds * 1000000 + _duration.microseconds, 
            view = 'NOTE', 
            request = request.REQUEST, 
            ip = get_client_ip(request), 
            log_time = datetime.datetime.now(),
            request_user_id = _request_user_id,
            appendix = { 
                'note_id' : int(note_id), 
            },
        )
        return SuccessJsonResponse(_rslt)
예제 #8
0
파일: user.py 프로젝트: guoku/Raspberry
def user_tag_entity(request, user_id, tag):
    _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

        _user_context = MobileUser(user_id).read(_request_user_id)
        _entity_id_list = Tag.find_user_tag_entity(user_id, tag)
        _rslt = {'user': _user_context, 'entity_list': []}
        for _entity_id in _entity_id_list:
            _rslt['entity_list'].append(
                MobileEntity(_entity_id).read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_TAG_ENTITY',
            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),
                'tag': tag
            },
        )
        return SuccessJsonResponse(_rslt)
예제 #9
0
파일: user.py 프로젝트: guoku/Raspberry
def recommend_user_tag(request):
    if request.method == "GET":
        _offset = int(request.GET.get('offset', '10'))
        _count = int(request.GET.get('count', '10'))
        _session = request.GET.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _rslt = []
        _recommend_user_tag_list = Tag.get_recommend_user_tag_list()
        for _tag_data in _recommend_user_tag_list[_offset:_offset + _count]:
            _data = {
                'tag_name': _tag_data[1],
                'entity_count': _tag_data[2],
                'user': MobileUser(_tag_data[0]).read(_request_user_id),
                'entity_list': []
            }
            for _entity_id in Tag.find_user_tag_entity(_tag_data[0],
                                                       _tag_data[1])[0:3]:
                _data['entity_list'].append(
                    MobileEntity(_entity_id).read(_request_user_id))
            _rslt.append(_data)
        return SuccessJsonResponse(_rslt)
예제 #10
0
파일: user.py 프로젝트: guoku/Raspberry
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)
예제 #11
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)
예제 #12
0
파일: user.py 프로젝트: guoku/Raspberry
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)
예제 #13
0
파일: user.py 프로젝트: guoku/Raspberry
def user_like(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'))

        _list = []
        _last_like_time = None
        _entity_id_list = []
        for _item in MobileUser(user_id).find_like_entity(timestamp=_timestamp,
                                                          offset=_offset,
                                                          count=_count,
                                                          with_timestamp=True):
            _list.append(MobileEntity(_item[0]).read(_request_user_id))
            _entity_id_list.append(_item[0])
            _last_like_time = _item[1]

        if _last_like_time == None:
            _timestamp = 0.0
        else:
            _timestamp = time.mktime(_last_like_time.timetuple())
        _rslt = {'timestamp': _timestamp, 'entity_list': _list}

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_LIKE',
            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_entities': _entity_id_list
            },
        )
        return SuccessJsonResponse(_rslt)
예제 #14
0
파일: category.py 프로젝트: guoku/Raspberry
def category_stat(request, category_id):
    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

        _rslt = {
            'entity_count':
            MobileEntity.count(category_id=category_id, status='normal'),
            'entity_note_count':
            MobileNote.count(category_id=category_id),
        }
        if _request_user_id != None:
            _rslt['like_count'] = MobileUser(
                _request_user_id).entity_like_count(
                    neo_category_id=category_id)
        else:
            _rslt['like_count'] = 0

        return SuccessJsonResponse(_rslt)
예제 #15
0
def entity_detail(request, entity_id):
    _start_at = datetime.datetime.now()
    print 'detail'
    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

        _rslt = MobileEntity(entity_id).read_full_context(_request_user_id)

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='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 SuccessJsonResponse(_rslt)