def put(self): try: user_id = self.get_argument('user_id') room_id = self.get_argument('room_id') name = self.get_argument('name') tag_ids = self.get_argument('tag_ids', []) intro = self.get_argument('intro', '') limit_user_number = self.get_argument('limit_user_number', LIMIT_USER_NUMBER) status = self.get_argument('status', ROOM_PUBLIC) avatar_url = self.get_argument('avatar', '') except MissingArgumentError: return self.error(MISSING_PARAMS) if filter.check_sensitive(name) or filter.check_sensitive( intro) or filter_name.check_sensitive(name): return self.error(SENSITIVE_WORD_EXISTS) try: tag_ids = json.loads(tag_ids) except ValueError: tag_ids = [] try: avatar = json.loads(avatar_url)[0] except: avatar = avatar_url o = urlparse(avatar) img_path = o.path if img_path.startswith('/'): avatar = re.sub(r'/', '', img_path, 1) else: avatar = img_path room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) if RoomTag.get_tag_ids_by_room(room_id) != tag_ids: RoomTag.update_tags(room_id, tag_ids) try: room.update(name=name, intro=intro, limit_user_number=limit_user_number, status=status, avatar=avatar) update_open_search_room.delay(room_id, name, intro, tag_ids) except Exception, e: logger.error(u'更新房间失败。error:[%s]', e) return self.error(SYSTEM_ERROR)
def post(self): try: user_id = self.get_argument('user_id') room_id = self.get_argument('room_id') name = self.get_argument('name') deadline = self.get_argument('deadline') options = self.get_argument('options') options = json.loads(options) except (MissingArgumentError, TypeError): return self.error(MISSING_PARAMS) if filter.check_sensitive(name): return self.error(SENSITIVE_WORD_EXISTS) for op in options: if filter.check_sensitive(op): return self.error(SENSITIVE_WORD_EXISTS) if len(op) > 24: return self.error(OPTION_TEXT_TOO_LONG) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) room_user = RoomUser.get_by_room_and_user(room_id, user_id) if not user.super_user: if not room_user: return self.error(ACCESS_NOT_ALLOWED) if int(room_user.status) == ROOM_USER_SILENT: return self.error(USER_IN_ROOM_SILENT_LIST) try: vote = Vote.add(user_id, room_id, name, deadline, options, room_user.status) except Exception as e: logger.error(u'添加投票失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR) handle_daily_create_content.delay(user_id, vote.id) return self.render({ 'status': 0, 'data': vote.jsonify(), })
def post(self): try: user_id = self.get_argument('user_id') room_id = self.get_argument('room_id') intro = self.get_argument('intro') except MissingArgumentError: return self.error(MISSING_PARAMS) if filter.check_sensitive(intro): return self.error(SENSITIVE_WORD_EXISTS) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) if int(room.creator_id) != int(user_id): return self.error(ACCESS_NOT_ALLOWED) try: if intro != room.intro: room.update(intro=intro) return self.render({ 'status': 0, 'data': { 'intro': intro, } }) except Exception as e: logger.error(u'修改房间介绍失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR)
def post(self): try: user_id = self.get_argument('user_id') name = self.get_argument('name') except MissingArgumentError: return self.error(MISSING_PARAMS) if filter.check_sensitive(name) or filter_name.check_sensitive(name): return self.error(SENSITIVE_WORD_EXISTS) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) try: if name != user.name: if user.exists_user_name(name): return self.error(USER_NAME_EXISTS) else: user.update(name=name) if UserChatStatus.is_flower_identity(user_id): rong_client.user_refresh(user_id, name=name) return self.render({ 'status': 0, 'data': { 'name': name, } }) except Exception as e: logger.error(u'修改用户名失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR)
def post(self): try: user_id = self.get_argument('user_id') reply_user_id = self.get_argument('reply_user_id', None) room_id = self.get_argument('room_id') content_id = self.get_argument('content_id') text = self.get_argument('text') except MissingArgumentError: return self.error(MISSING_PARAMS) if filter.check_sensitive(text): return self.error(SENSITIVE_WORD_EXISTS) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) # if reply_user_id: # reply_user = User.get(reply_user_id) # if not reply_user: # return self.error(USER_NOT_FOUND) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) if not user.has_room_access(room_id): return self.error(ACCESS_NOT_ALLOWED) if not user.has_room_speak_access(room_id): return self.error(USER_IN_ROOM_SILENT_LIST) content = Content.get(content_id) if not content: return self.error(CONTENT_NOT_FOUND) try: comment = Comment.add(user_id, reply_user_id, content_id, text) if not reply_user_id: if int(user_id) != int(content.creator_id): notify_content_comment.delay(user, content, comment) handle_daily_comment.delay(user_id, comment.id) else: reply_user = User.get(reply_user_id) if not reply_user: return self.error(USER_NOT_FOUND) if int(user.id) != int(reply_user_id): notify_comment_reply.delay(user, reply_user, content, comment) handle_daily_comment.delay(user_id, comment.id) return self.render({ 'status': 0, 'data': comment.jsonify(), }) except Exception as e: logger.error(u'发表评论失败。User:[%s], Content:[%s], Error:[%s]' % (user_id, content_id, e)) return self.error(SYSTEM_ERROR)
def post(self): user_id = self.get_argument('user_id') text = self.get_argument('text', '') room_id = self.get_argument('room_id') video = self.get_argument('video', '') images = self.get_argument('images', '[]') if not room_id: return self.error(MISSING_PARAMS) if filter.check_sensitive(text): return self.error(SENSITIVE_WORD_EXISTS) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) room_user = RoomUser.get_by_room_and_user(room_id, user_id) if not user.super_user: if not room_user: return self.error(ACCESS_NOT_ALLOWED) if int(room_user.status) == ROOM_USER_SILENT: return self.error(USER_IN_ROOM_SILENT_LIST) try: posts = Posts.add(user_id, room_id, text, images, video, room_user.status) except Exception as e: logger.error(u'添加帖子内容失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR) handle_daily_create_content.delay(user_id, posts.id) return self.render({'status': 0, 'data': posts.jsonify()})
def post(self, *args): try: user_id = self.get_argument('user_id') name = self.get_argument('name') tag_ids = self.get_argument('tag_ids', '[]') intro = self.get_argument('intro', '') limit_user_number = self.get_argument('limit_user_number', LIMIT_USER_NUMBER) status = self.get_argument('status', ROOM_PUBLIC) avatar_url = self.get_argument('avatar', '') question_info = self.get_argument('question_info', None) create_time = datetime.now() except MissingArgumentError: return self.error(MISSING_PARAMS) if filter.check_sensitive(name) or filter.check_sensitive( intro) or filter_name.check_sensitive(name): return self.error(SENSITIVE_WORD_EXISTS) try: tag_ids = json.loads(tag_ids) except ValueError: tag_ids = [] if not name: return self.error(ROOM_NAME_COULD_NOT_NONE) if Room.exist_room(name): return self.error(ROOM_NAME_EXISTS) try: avatar = json.loads(avatar_url)[0] except: avatar = avatar_url if question_info: question_info = json.loads(question_info) try: room_id = Room.add(user_id, name, intro, tag_ids, avatar, limit_user_number, create_time, status, question_info) add_open_search_room.delay(room_id, name, intro, create_time, tag_ids) except Exception, e: logger.error(u'创建房间失败。error:[%s]', e) return self.error(ROOM_CREATE_ERROR)
def post(self, *args, **kwargs): try: tag_name = self.get_argument('tag_name') # source = self.get_argument('source', USER_CREATED) except MissingArgumentError: return self.error(MISSING_PARAMS) if filter.check_sensitive(tag_name) or filter_name.check_sensitive( tag_name): return self.error(SENSITIVE_WORD_EXISTS) tag = Tag.get_by_name(tag_name) if not tag: tag_id = Tag.add(tag_name, USER_CREATED) tag = Tag.get(tag_id) data = {'status': 0, 'data': tag.jsonify()} return self.render(data)
def post(self): try: user_id = self.get_argument('user_id') room_id = self.get_argument('room_id') name = self.get_argument('name') except MissingArgumentError: return self.error(MISSING_PARAMS) if filter.check_sensitive(name): return self.error(SENSITIVE_WORD_EXISTS) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) if int(room.creator_id) != int(user_id): return self.error(ACCESS_NOT_ALLOWED) try: if name != room.name: if room.exist_room(name): return self.error(ROOM_NAME_EXISTS) else: room.update(name=name) return self.render({ 'status': 0, 'data': { 'name': name, } }) except Exception as e: logger.error(u'修改房间名失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR)
def post(self): try: user_id = self.get_argument('user_id') name = self.get_argument('name') tag_ids = self.get_argument('tag_ids', '[]') avatar_url = self.get_argument('avatar', '') except MissingArgumentError: return self.error(MISSING_PARAMS) if filter.check_sensitive(name) or filter_name.check_sensitive(name): return self.error(SENSITIVE_WORD_EXISTS) try: tag_ids = json.loads(tag_ids) except ValueError: tag_ids = [] user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) if user.exists_user_name(name): return self.error(USER_NAME_EXISTS) try: avatar = json.loads(avatar_url)[0] except: avatar = avatar_url try: user.add_user_info(avatar, name, tag_ids) user = User.get(user_id) return self.render({ 'status': 0, 'data': user.jsonify(), }) except Exception as e: logger.error(u'添加完善用户信息失败。Error:[%s]' % e) return self.error(SYSTEM_ERROR)
def post(self): try: user_id = int(self.get_argument('user_id')) room_id = int(self.get_argument('room_id')) content_id = self.get_argument('content_id') text = self.get_argument('text') start_time = self.get_argument('start_time', None) except MissingArgumentError: return self.error(MISSING_PARAMS) now = datetime.now() if filter.check_sensitive(text): return self.error(SENSITIVE_WORD_EXISTS) user = User.get(user_id) if not user: return self.error(USER_NOT_FOUND) room = Room.get(room_id) if not room: return self.error(ROOM_NOT_FOUND) content = Content.get(content_id) if not content: return self.error(CONTENT_NOT_FOUND) if int(room.creator_id) != user_id or int(content.room_id) != room_id: return self.error(ACCESS_NOT_ALLOWED) push_count = RoomPush.get_push_count_by_room_and_date(room_id, now) if push_count and push_count >= 1: return self.error(ROOM_PUSH_OVER_LIMIT) push_room_content.delay(room, content, text, start_time) return self.render({ 'status': 0, })