def get(self): try: user_id = self.get_argument('user_id') room_id = self.get_argument('room_id') start = int(self.get_argument('start', 0)) count = int(self.get_argument('count', 10)) except MissingArgumentError: return self.error(MISSING_PARAMS) user = User.get(user_id) # if not user.has_room_access(room_id): # return self.error(ACCESS_NOT_ALLOWED) room_users = RoomUser.get_ordered_room_users_by_room( room_id, start, count) data = [] for room_user in room_users: user_id = room_user.user_id user = User.get(user_id) status = room_user.status data.append({ 'id': user.id, 'name': user.user_name, 'avatar': user.avatar_url, 'status': status, 'join_time': room_user.join_time.strftime('%Y-%m-%d %H:%M:%S'), }) return self.render({ 'status': 0, 'data': data, })
def jsonify(self, user=None): from starmachine.model.room_user import RoomUser last_content_updated = self.last_content_updated if isinstance(last_content_updated, basestring): if last_content_updated == 'None': last_content_updated = '' else: if last_content_updated: last_content_updated = last_content_updated.strftime( '%Y-%m-%d %H:%M:%S') else: last_content_updated = '' data = { 'id': self.id, 'creator': { 'id': self.creator.id, 'name': self.creator.user_name, 'avatar': self.creator.avatar_url }, 'name': self.name, 'intro': self.intro, 'avatar_url': self.avatar_url, 'limit_user_number': int(self.limit_user_number), 'status': self.status, 'user_amount': self.user_amount, 'balance': self.star_fund, 'create_time': self.create_time if isinstance(self.create_time, basestring) else self.create_time.strftime('%Y-%m-%d %H:%M:%S'), 'tags': [tag.jsonify() for tag in self.tags if tag], 'last_content_updated': last_content_updated, 'admin_users': RoomUser.get_admin_users_by_room(self.id), } room_users = RoomUser.get_ordered_room_users_by_room(self.id) room_users_data = [] for room_user in room_users: user_obj = User.get(room_user.user_id) room_users_data.append({ 'id': user_obj.id, 'name': user_obj.user_name, 'avatar': user_obj.avatar_url, 'status': user_obj.status, }) data.update({ 'users': room_users_data, }) if int(self.status) == ROOM_PRIVATE_NEED_VERIFY: question_info = RoomQuestion.get_question_by_room(self.id) if question_info: data.update({'question_info': question_info.jsonify()}) if user: from starmachine.model.room_user import RoomUser, RoomBlackUser data.update({ 'owner': bool(int(self.creator_id) == int(user.id)), 'joined': bool(RoomUser.room_exists_user(self.id, user.id)), 'is_black': bool(RoomBlackUser.is_room_black_user(self.id, user.id)), }) return data