Exemple #1
0
def delete_entity_note(request, note_id):
    if request.method == "POST":
        _session = request.POST.get('session', None)
        _entity_id = MobileNote(note_id).get_entity_id()
        DeleteEntityNoteTask.delay(_entity_id, note_id)

        return SuccessJsonResponse({'delete_already': 1})
Exemple #2
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)
Exemple #3
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)
Exemple #4
0
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)
Exemple #5
0
def search_user(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

        _query_string = request.GET.get('q')
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))
        _user_id_list = MobileUser.search(query_string=_query_string,
                                          offset=_offset,
                                          count=_count)
        _rslt = []
        for _user_id in _user_id_list:
            _rslt.append(MobileUser(_user_id).read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='SEARCH_USER',
            request=request.REQUEST,
            ip=get_client_ip(request),
            log_time=datetime.datetime.now(),
            request_user_id=_request_user_id,
            appendix={
                'query': _query_string,
                'result_users': _user_id_list
            },
        )
        return SuccessJsonResponse(_rslt)
Exemple #6
0
def apns_token(request):
    if request.method == "POST":
        _session = request.POST.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _dev_token = request.POST.get('dev_token', None)
        _dev_name = request.POST.get('dev_name', None)
        _dev_model = request.POST.get('dev_model', None)
        _sys_ver = request.POST.get('sys_ver', None)
        _app_name = request.POST.get('app_name', None)
        _app_ver = request.POST.get('app_ver', None)
        _push_badge = request.POST.get('push_badge', False)
        _push_alert = request.POST.get('push_alert', False)
        _push_sound = request.POST.get('push_sound', False)
        _development = request.POST.get('development', False)

        if _dev_token != None:
            _apns = Apns(_dev_token)
            _apns.create(user_id=_request_user_id,
                         dev_name=_dev_name,
                         dev_models=_dev_model,
                         sys_ver=_sys_ver,
                         app_ver=_app_ver,
                         push_badge=_push_badge,
                         push_alert=_push_alert,
                         push_sound=_push_sound,
                         development=_development)

        return SuccessJsonResponse({'success': '1'})
Exemple #7
0
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)
Exemple #8
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)
Exemple #9
0
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)
Exemple #10
0
def user_tag_list(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
        _user_context = MobileUser(user_id).read()
        _tag_list = Tag.user_tag_stat(user_id)
        _rslt = {'user': _user_context, 'tags': _tag_list}

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_TAG',
            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_tags': map(lambda x: x['tag'], _tag_list)
            },
        )
        return SuccessJsonResponse(_rslt)
Exemple #11
0
def login(request):
    if request.method == "POST":
        _email = request.POST.get('email', None)
        _password = request.POST.get('password', None)
        _api_key = request.POST.get('api_key', None)

        try:
            _user = MobileUser.login(email=_email, password=_password)
            _session = Session_Key.objects.generate_session(
                user_id=_user.user_id,
                username=_user.get_username(),
                email=_email,
                api_key=_api_key)

            _data = {
                'user': _user.read(_user.user_id),
                'session': _session.session_key
            }
            return SuccessJsonResponse(_data)
        except MobileUser.LoginEmailDoesNotExist, e:
            return ErrorJsonResponse(data={
                'type': 'email',
                'message': str(e),
            },
                                     status=400)
        except MobileUser.LoginPasswordIncorrect, e:
            return ErrorJsonResponse(data={
                'type': 'password',
                'message': str(e),
            },
                                     status=400)
Exemple #12
0
def login_by_taobao(request):
    if request.method == "POST":
        _taobao_id = request.POST.get('taobao_id', None)
        _taobao_token = request.POST.get('taobao_token', None)
        _api_key = request.POST.get('api_key', None)

        try:
            _user = MobileUser.login_by_taobao(taobao_id=_taobao_id,
                                               taobao_token=_taobao_token)
            _session = Session_Key.objects.generate_session(
                user_id=_user.user_id,
                username=_user.get_username(),
                email=_user.get_email(),
                api_key=_api_key)

            _data = {
                'user': _user.read(_user.user_id),
                'session': _session.session_key
            }
            return SuccessJsonResponse(_data)
        except MobileUser.LoginTaobaoIdDoesNotExist, e:
            return ErrorJsonResponse(data={
                'type': 'taobao_id',
                'message': str(e),
            },
                                     status=400)
Exemple #13
0
def update_user(request):
    if request.method == "POST":
        _session = request.POST.get('session', None)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None

        _user = MobileUser(_request_user_id)

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

        _nickname = request.POST.get('nickname', None)
        _email = request.POST.get('email', None)
        _username = request.POST.get('username', None)
        _password = request.POST.get('password', None)
        if _email != None or _username != None or _password != None:
            _user.reset_account(username=_username,
                                password=_password,
                                email=_email)

        if _nickname != None:
            _user.set_profile(nickname=_nickname)

        return SuccessJsonResponse(_user.read())
Exemple #14
0
def user_following(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
        _offset = int(request.GET.get('offset', '0'))
        _count = int(request.GET.get('count', '30'))

        _rslt = []
        _following_user_id_list = MobileUser(
            user_id).read_following_user_id_list()
        for _following_user_id in _following_user_id_list[_offset:_offset +
                                                          _count]:
            _rslt.append(MobileUser(_following_user_id).read(_request_user_id))

        _duration = datetime.datetime.now() - _start_at
        MobileLogTask.delay(
            duration=_duration.seconds * 1000000 + _duration.microseconds,
            view='USER_FOLLOWING',
            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_users':
                _following_user_id_list[_offset:_offset + _count]
            },
        )
        return SuccessJsonResponse(_rslt)
Exemple #15
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)
Exemple #16
0
def logout(request):
    _req_uri = request.get_full_path()
    if request.method == "POST":
        _session = request.POST.get('session', None)
        _session_obj = Session_Key.objects.get(session_key=_session)
        _session_obj.delete()

        return SuccessJsonResponse({'success': '1'})
Exemple #17
0
def user_info(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
        _rslt = MobileUser(_request_user_id).read()
        return SuccessJsonResponse(_rslt)
Exemple #18
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)
Exemple #19
0
def forget_password(request):
    if request.method == "POST":
        _email = request.POST.get('email', None)
        _user_id = MobileUser.get_user_id_by_email(_email)
        if _user_id == None:
            return ErrorJsonResponse(data={
                'type': 'email',
                'message': 'email does not exist',
            },
                                     status=400)
        RetrievePasswordTask.delay(_user_id)

        return SuccessJsonResponse({'success': '1'})
Exemple #20
0
def like_entity(request, entity_id, target_status):
    if request.method == "POST":
        _session = request.POST.get('session', None)

        _request_user_id = Session_Key.objects.get_user_id(_session)
        _rslt = {'entity_id': int(entity_id)}
        if target_status == '1':
            LikeEntityTask.delay(entity_id, _request_user_id)
            _rslt['like_already'] = 1
        else:
            UnlikeEntityTask.delay(entity_id, _request_user_id)
            _rslt['like_already'] = 0
        return SuccessJsonResponse(_rslt)
Exemple #21
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)
Exemple #22
0
def check_sina_user(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
        _sina_id_list = request.GET.getlist('sid[]')
        _sina_user_list = MobileUser.check_sina_id(_sina_id_list)
        _rslt = []
        for _sina_user in _sina_user_list[0:100]:
            _user_id = _sina_user['user_id']
            _rslt.append(MobileUser(_user_id).read(_request_user_id))

        return SuccessJsonResponse(_rslt)
Exemple #23
0
def poke_entity_note(request, note_id, target_status):
    if request.method == "POST":
        _session = request.POST.get('session', None)
        
        _request_user_id = Session_Key.objects.get_user_id(_session)
        _rslt = { 
            'note_id' : int(note_id) 
        }
        if target_status == '1':
            PokeEntityNoteTask.delay(note_id, _request_user_id)
            _rslt['poke_already'] = 1
        else:
            DepokeEntityNoteTask.delay(note_id, _request_user_id)
            _rslt['poke_already'] = 0
        return SuccessJsonResponse(_rslt)
Exemple #24
0
def update_entity_note(request, note_id):
    if request.method == "POST":
        _session = request.POST.get('session', None)
        # log.info(request.POST)
        if _session != None:
            _request_user_id = Session_Key.objects.get_user_id(_session)
        else:
            _request_user_id = None
        _note_text = request.POST.get('note', None)
        _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()
        
        ## There's no authorize confirmation yet ##
        
        _note = MobileNote(note_id)
        note_context = _note.read()

        # log.info(note_context)
        if note_context['creator']['user_id'] == _request_user_id:
            # _note.create()
            _note.update(
                note_text = _note_text,
                image_data = _image_data
            )
        else:
            _note = MobileNote.create(
                entity_id = note_context['entity_id'],
                creator_id = _request_user_id,
                note_text = _note_text,
                image_data = _image_data
            )
            # _note.create(
            #     entity_id = note_context['entity_id'],
            #     creator_id = _request_user_id,
            #     note_text = _note_text,
            #     image_data = _image_data,
            # )
        _rslt = _note.read(_request_user_id)
        log.info(_rslt)
        return SuccessJsonResponse(_rslt)
Exemple #25
0
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)
Exemple #26
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)
Exemple #27
0
def comment_entity_note(request, note_id):
    if request.method == "POST":
        _session = request.POST.get('session', None)
        _comment_text = request.POST.get('comment', None)
        _reply_to_comment_id = request.POST.get('reply_to_comment', None)
        _reply_to_user_id = request.POST.get('reply_to_user', None)
        
        _request_user_id = Session_Key.objects.get_user_id(_session)
        
        _note = MobileNote(note_id)
        _comment_id = _note.add_comment(
            comment_text = _comment_text, 
            creator_id = _request_user_id, 
            reply_to_comment_id = _reply_to_comment_id,
            reply_to_user_id = _reply_to_user_id,
        )
        _context = _note.read_comment(_comment_id, _request_user_id)
        return SuccessJsonResponse(_context)
Exemple #28
0
def report_entity(request, entity_id):
    if request.method == "POST":
        _session = request.POST.get('session', None)
        if _session != None:
            _reporter_id = Session_Key.objects.get_user_id(_session)
        else:
            _reporter_id = -1

        _comment = request.POST.get('comment', '')
        _report = EntityReport(
            reporter_id=_reporter_id,
            comment=_comment,
            entity_id=int(entity_id),
            created_time=datetime.datetime.now(),
            updated_time=datetime.datetime.now(),
        )
        _report.save()
        return SuccessJsonResponse({"status": 1})
Exemple #29
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)
Exemple #30
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)