def comment(token, travel_id, content): user = userservice.get_user(token) tc = TravelComment() #游记的拥有者 travel_name = '' related_user_name = '' try: travel = Travel.objects.get(pk=travel_id) travel_name = travel.title related_user_name = travel.user.nickname except ObjectDoesNotExist: return {RSP_CODE : RC_NO_SUCH_TRAVEL} else: if travel.user == user: return {RSP_CODE : RC_FUCK_SELF} tc.travel_id = travel_id tc.commenter = user tc.content = content tc.save() APPKEY = '986aa2521dcb7f92092a8848' MASTER_SECRET = 'b6ddbc1f0933845e4fa50c9b' jpush_client = JPushClient(MASTER_SECRET) welcome_message = "您的游记" #welcome_message += travel_name welcome_message += "有一条新评论,点击查看" sendno = int(time.time()) jpush_client.send_notification_by_alias(related_user_name, APPKEY, sendno, 'travo', welcome_message, content, 'android',{'travel_id':travel_id}) return {RSP_CODE : RC_SUCESS}
def friend_travels(token, friend_id): user = userservice.get_user(token) friend = userservice.get_user_by_id(friend_id) result = {RSP_CODE : RC_SUCESS} result['travels'] = list(Travel.objects.filter(user=friend, is_public=True, is_deleted=False)) return result '''
def sync_state(token): user = userservice.get_user(token) result = {RSP_CODE : RC_SUCESS} result['travel'] = Travel.user_lm_time(user) result['note'] = Note.user_lm_time(user) result['user_info'] = UserInfo.user_lm_time(user) #result['location'] = Location.objects.filter(user=user).latest('lm_time') return result
def get_favorite_web(token): user = userservice.get_user(token) fts = FavoriteTravel.objects.filter(user=user).order_by('time').reverse() travels = [] for ft in fts: travels.append(ft.travel) result = {RSP_CODE : RC_SUCESS} result['travels'] = travels return result
def get_favorit(token, first_idx=1, max_qty=20): user = userservice.get_user(token) fts = FavoriteTravel.objects.filter(user=user).order_by('time').reverse()[first_idx - 1:max_qty] travels = [] for ft in fts: travels.append(ft.travel) result = {RSP_CODE : RC_SUCESS} result['travels'] = travels return result
def sync(token, begin_time): user = userservice.get_user(token) result = {RSP_CODE : RC_SUCESS} if begin_time is None: #sync all note result['notes'] = list(Note.objects.filter(user = user)) else: begin_time = utils.strpdatetime(begin_time) result['notes'] = list(Note.objects.filter(user=user,lm_time__gt=begin_time)) return result
def sync(token, begin_time): user = userservice.get_user(token) result = {RSP_CODE : RC_SUCESS} if begin_time is None: #sync all travel result['travels'] = list(Travel.objects.filter(user = user)) else: begin_time = utils.strpdatetime(begin_time) result['travels'] = list(Travel.objects.filter(user=user,lm_time__gt=begin_time)) return result
def search(token, order=SO_DEFAULT, first_idx=1, max_qty=20): first_idx = int(first_idx) user = None if token is not None: user = userservice.get_user(token) return { SO_DEFAULT : _search_default, SO_READ_TIMES: _search_read_times, SO_VOTE_QTY : _search_vote_qty, SO_NEWEST : _search_newest, }[order](first_idx - 1, max_qty, user)
def upload(token, travels, covers={}): user = userservice.get_user(token) rsps = [] for t in travels: if t.get('id') is None or t.get('id') == 0: rsps.append(_new(user, t, covers.get(t.get('cover')))) else: rsps.append(_update(user, t, covers.get(t.get('cover')))) result = {RSP_CODE : RC_SUCESS} result['rsps'] = rsps result['lm_time'] = utils.datetimepstr(datetime.now()) return result
def upload(token, notes, images={}): user = userservice.get_user(token) rsps = [] for n in notes: if n.get('id') is None or n.get('id') == 0: rsps.append(_new(user, n, images.get(n.get('image')))) else: rsps.append(_update(user, n, images.get(n.get('image')))) result = {RSP_CODE: RC_SUCESS} result['rsps'] = rsps result['lm_time'] = utils.datetimepstr(datetime.now()) return result
def upload(token, notes, images={}): user = userservice.get_user(token) rsps = [] for n in notes: if n.get('id') is None or n.get('id') == 0: rsps.append(_new(user, n, images.get(n.get('image')))) else: rsps.append(_update(user, n, images.get(n.get('image')))) result = {RSP_CODE : RC_SUCESS} result['rsps'] = rsps result['lm_time'] = utils.datetimepstr(datetime.now()) return result
def get_travel(token,recent = False): user = userservice.get_user(token) user_id = user.id result = {RSP_CODE : RC_SUCESS} try: travel_list = Travel.objects.filter(user=user_id).order_by('-create_time') if recent == False: result['travel_list'] = travel_list return result else: result['travel_list'] = travel_list[:recent] return result except ObjectDoesNotExist: return {RSP_CODE : RC_NO_SUCH_TRAVEL}
def read(token, travel_id): user = userservice.get_user(token) try: travel = Travel.objects.get(pk=travel_id, is_public=True) except: return {RSP_CODE : RC_NO_SUCH_TRAVEL} else: if travel.user != user: #can not read self's travel trl = TravelReadLog() trl.reader = user trl.travel_id = travel_id trl.save() else: return {RSP_CODE : RC_FUCK_SELF} return {RSP_CODE : RC_SUCESS}
def vote(token, travel_id): user = userservice.get_user(token) try: travel = Travel.objects.get(pk=travel_id) except ObjectDoesNotExist: return {RSP_CODE : RC_NO_SUCH_TRAVEL} else: if travel.user != user: tv = TravelVote() tv.voter = user tv.travel = travel try: tv.save() except: return {RSP_CODE : RC_DUP_ACTION} else: return {RSP_CODE : RC_FUCK_SELF} return {RSP_CODE : RC_SUCESS}
def get_cover(travel_id, token): travel = None result = {RSP_CODE : RC_SUCESS} try: travel = Travel.objects.get(pk=travel_id) except ObjectDoesNotExist: return {RSP_CODE : RC_NO_SUCH_TRAVEL} if travel.cover_path is None: return {RSP_CODE : RC_NO_COVER} if travel.is_public is False: user = userservice.get_user() if travel.user != user: return {RSP_CODE : RC_PERMISSION_DENIED} else: result['cover'] = utils.get_cover(travel.cover_path) else: result['cover'] = utils.get_cover(travel.cover_path) return result
def favorit(token, travel_id): user = userservice.get_user(token) try: travel = Travel.objects.get(pk=travel_id, is_public=True, is_deleted=False) except: return {RSP_CODE : RC_NO_SUCH_TRAVEL} else: if travel.user != user: #can not favorit self's travel ft = FavoriteTravel() ft.user = user ft.travel_id = travel_id try: ft.save() except IntegrityError: return {RSP_CODE : RC_DUP_ACTION} else: return {RSP_CODE : RC_FUCK_SELF} return {RSP_CODE : RC_SUCESS}
def get_all_in_travel(travel_id, token=None): try: travel = Travel.objects.get(pk=travel_id) except: return {RSP_CODE : RC_NO_SUCH_TRAVEL} else: if not travel.is_public: return {RSP_CODE : RC_PERMISSION_DENIED} if token is not None: #some read this travel user = userservice.get_user(token) if travel.user != user: #can not read self's travel trl = TravelReadLog() trl.reader = user trl.travel_id = travel_id trl.save() result = {RSP_CODE : RC_SUCESS} result['notes'] = list(Note.objects.filter(travel_id=travel_id, is_deleted=False)) return result
def get_all_in_travel(travel_id, token=None): try: travel = Travel.objects.get(pk=travel_id) except: return {RSP_CODE: RC_NO_SUCH_TRAVEL} else: if not travel.is_public: return {RSP_CODE: RC_PERMISSION_DENIED} if token is not None: #some read this travel user = userservice.get_user(token) if travel.user != user: #can not read self's travel trl = TravelReadLog() trl.reader = user trl.travel_id = travel_id trl.save() result = {RSP_CODE: RC_SUCESS} result['notes'] = list( Note.objects.filter(travel_id=travel_id, is_deleted=False)) return result