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)
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)
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)
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})
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)
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)
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)
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)
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)