Пример #1
0
 def test_room_allocation(self):
     r1 = Room(room_name="Demo Room 1")
     r2 = Room(room_name="Demo Room 2")
     s1 = Student(first_name="billy")
     s2 = Student(first_name="bella")
     s3 = Student(first_name="mikes")
     s1.room = r1
     s2.room = r1
     s3.room = r2
     self.assertTrue(s1 in r1.students)
     self.assertTrue(s2 in r1.students)
     self.assertTrue(s3 in r2.students)
Пример #2
0
 def room_init(row):
     room = Room()
     num = Room.query.filter_by(name=row['Nom']).count()
     if num > 0:
         Room.query.delete()
     room.name = row['Nom']
     room.max_number = row['Espace total']
     room.description = row['Description']
     return room
Пример #3
0
 def post(self):
     """
     Create the room
     """
     data = room_parser.parse_args()
     if 'song' not in request.files:
         return {
             "status": "error",
             'message': 'You have to upload at least one song'
         }, 400
     if Room.find_by_name(data['name']):
         return {
             "status": "error",
             'message': 'Room {} already exists'.format(data['name'])
         }, 400
     current_user = User.find_by_username(get_jwt_identity())
     song = request.files["song"]
     if song.filename == "":
         return {"status": "error", 'message': "Please select a file"}, 400
     elif not (song and allowed_file(song.filename)):
         return {
             "status": "error",
             'message': "Files must be in mp3 format."
         }, 400
     else:
         link = None
         try:
             room = Room(name=data['name'])
             db.session.add(room)
             song_name = secure_filename(song.filename)
             link = upload_file_to_s3(song, config.S3_BUCKET)
             db.session.flush()
             db.session.execute(joins.insert().values(
                 user_id=current_user.id, room_id=room.id))
             new_song = Song(name=song_name, link=link, room_id=room.id)
             room.current_song_id = new_song.id
             room.current_song = new_song
             room.owner_id = current_user.id
             db.session.add(new_song)
         except Exception as e:
             if link is not None:
                 s3.delete_object(Bucket=config.S3_BUCKET,
                                  Key=link[len(config.S3_LOCATION):])
             db.session.rollback()
             print(repr(e))
             return {
                 "status":
                 "error",
                 'message':
                 "Something wrong happen while creating room. Please try again."
             }, 400
         db.session.commit()
         result = room_schema.dump(room)
         return {"status": "success", "data": result}, 201
Пример #4
0
 def post(self):
     data = request.get_json()
     r = Room(name=data['name'])
     users = data['users']
     for username in users:
         u = User.query.filter_by(username=username).first()
         v = u.viewed.copy()
         v[r.name] = 0
         u.viewed = v
         print(u.viewed)
         u.rooms.append(r)
     db.session.add(r)
     db.session.commit()
     return succes(id=r.id, name=r.name)