Ejemplo n.º 1
0
def add_6_albumns():
    cover_images = [
        'https://i2.wp.com/bestlifeonline.com/wp-content/uploads/2018/06/all-along-watchtower.jpg?w=1024&ssl=1',
        'https://i2.wp.com/bestlifeonline.com/wp-content/uploads/2018/06/american-woman.jpg?w=1024&ssl=1',
        'https://i1.wp.com/bestlifeonline.com/wp-content/uploads/2018/06/angel-mont-1.jpg?w=1024&ssl=1',
        'https://i0.wp.com/bestlifeonline.com/wp-content/uploads/2018/06/becausethenight.jpg?w=1024&ssl=1'
    ]

    for i in range(6):
        Album.create_album(1,
                           'album1',
                           cover_image=random.choice(cover_images))
def create_albums_and_likes():
    # 7 users
    for i in range(7):
        user = User(firstname=f'first-{i}',
                    lastname=f'last-{i}',
                    email=f'f{i}@l.com')
        user.set_password('test')
        db.session.add(user)
    db.session.commit()

    # 7 albumns
    for i in range(7):
        Album.create(user_pk=1,
                     name=f'album-{i}',
                     cover_image=f'google-{i}.com')

    # add likes: album 1 get 7 like, album 2 get 6 likes etc.
    for i in range(7):
        # print(
        Album.query.get(i + 1).like(1)
    # )
    # for j in range(i, 7):
    #     Album.query.get(i).like(i)
    for i in range(6):
        Album.query.get(i + 1).like(2)

    for i in range(5):
        Album.query.get(i + 1).like(3)

    for i in range(4):
        Album.query.get(i + 1).like(4)

    for i in range(3):
        Album.query.get(i + 1).like(5)

    for i in range(2):
        Album.query.get(i + 1).like(6)

    for i in range(1):
        Album.query.get(i + 1).like(7)
Ejemplo n.º 3
0
def create_albums():
    nu = User(firstname='f', lastname='l', email='*****@*****.**')
    nu.set_password('test')
    db.session.add(nu)
    db.session.commit()

    album1 = Album.create_album(user_pk=nu.pk,
                                name='album1',
                                cover_image='google.com')
    album2 = Album.create_album(user_pk=nu.pk,
                                name='album2',
                                cover_image='google.com')
    album3 = Album.create_album(user_pk=nu.pk,
                                name='album3',
                                cover_image='google.com')

    newsong = Song(name='song1', user=nu.pk, mp3_file='google.com')
    db.session.add(newsong)

    newsong = Song(name='song2', user=nu.pk, mp3_file='google.com')
    db.session.add(newsong)

    newsong = Song(name='song3', user=nu.pk, mp3_file='google.com')
    db.session.add(newsong)

    newsong = Song(name='notin1', user=nu.pk, mp3_file='google.com')
    db.session.add(newsong)

    newsong = Song(name='notin2', user=nu.pk, mp3_file='google.com')
    db.session.add(newsong)
    db.session.commit()

    album1.add_song(1)
    album1.add_song(2)
    album1.add_song(3)

    album2.add_song(4)
    album3.add_song(5)
Ejemplo n.º 4
0
    def post(self):
        if not current_user.is_authenticated:
            return {'sucess': False, 'is_authenticated': False, 'error': 'login then we can talk'}

        args = self.reqparse.parse_args()
        print('args', args)
        
        '''
            expected for data: 
            {
                'name': 'a name'
                'is_playlist': 'Album or Playlist' 
                'cover_image': 'url link to image'
                'songs': '[1,2,3,4,5,6]' (list of song ids)
            }
        '''
        name = args['name']
        cover_image = args['cover_image']
        songs = [] #args['songs']
        is_playlist = args['is_playlist']
        if is_playlist.lower() == 'playlist':
            print('creating playlist')
            new_playlist = Playlist.create(user_pk=current_user.pk, name=name, cover_image=cover_image)
            print('songs', songs)
            for song in songs:
                new_playlist.add_song(song)

            return {'success': True, 'message': 'playlist created'}, 201


        elif args['is_playlist'].lower() == 'album':
            print('creating albumn')
            new_album = Album.create(user_pk=current_user.pk, name=name, cover_image=cover_image)
            for song in songs:
                new_album.add_song(song)

            return {'success': True, 'message': 'albumn created'}, 201
        
        return {'success': False, 'message': 'invalid form'}
Ejemplo n.º 5
0
 def get(self):
     if not current_user.is_authenticated:
         return {'error': 'Not logged in'}
     q = Album.get_liked_albums(current_user.pk) 
     # print('query:', q)
     return q
Ejemplo n.º 6
0
 def get(self, artist_id):
     q = Album.get_artist_albumns(artist_id)
     return q
Ejemplo n.º 7
0
def create_albumns2():
    nu1 = User(firstname='f', lastname='l', email='*****@*****.**')
    nu1.set_password('test')
    db.session.add(nu1)
    db.session.commit()

    nu2 = User(firstname='f2', lastname='l2', email='*****@*****.**')
    nu2.set_password('test')
    db.session.add(nu2)
    db.session.commit()

    DisplayStatus.add_default_display_status()

    # user 1
    u1albumu1 = Album.create_album(user_pk=nu1.pk,
                                   name='album1',
                                   cover_image='google.com')
    u1albumu2 = Album.create_album(user_pk=nu1.pk,
                                   name='album2',
                                   cover_image='google.com')
    u1albumu3 = Album.create_album(user_pk=nu1.pk,
                                   name='album3',
                                   cover_image='google.com')

    pp = Playlist.create_playlist(nu1.pk,
                                  name='playlist1',
                                  cover_image='google.com',
                                  display_status=3)
    unlisted = Playlist.create_playlist(nu1.pk,
                                        name='playlist2',
                                        cover_image='google.com',
                                        display_status=2)
    user_private = Playlist.create_playlist(nu1.pk,
                                            name='playlist_p',
                                            cover_image='google.com',
                                            display_status=1)

    # user 2
    u2albumu1 = Album.create_album(user_pk=nu1.pk,
                                   name='album21',
                                   cover_image='google.com')
    u2albumu2 = Album.create_album(user_pk=nu1.pk,
                                   name='album22',
                                   cover_image='google.com')
    u2albumu3 = Album.create_album(user_pk=nu1.pk,
                                   name='album23',
                                   cover_image='google.com')

    newsong = Song(name='song1', user=nu2.pk, mp3_file='google.com')
    db.session.add(newsong)

    newsong = Song(name='song2', user=nu2.pk, mp3_file='google.com')
    db.session.add(newsong)

    newsong = Song(name='song3', user=nu1.pk, mp3_file='google.com')
    db.session.add(newsong)

    newsong = Song(name='song4', user=nu1.pk, mp3_file='google.com')
    db.session.add(newsong)

    newsong = Song(name='song5', user=nu1.pk, mp3_file='google.com')
    db.session.add(newsong)
    db.session.commit()

    u1albumu1.add_song(1)
    u1albumu1.add_song(2)
    u1albumu1.add_song(3)

    u2albumu1.add_song(4)
    u2albumu2.add_song(5)