def resenhaEdit(id): data = ResenhaRepository().FindById(id) spotifyId = data.spotify_id if data.tipo_review == 'artista': spotify = SpotifyGetOneArtist(spotifyId).oneArtist elif data.tipo_review == 'album': spotify = SpotifyGetOneAlbum(spotifyId).oneAlbum elif data.tipo_review == 'track': spotify = SpotifyGetOneTrack(spotifyId).oneTrack else: spotify = SpotifyGetOnePlaylist(spotifyId).onePlaylist if session['id'] != data.author_id: return redirect(url_for('ind.home')) else: voltarButton = request.headers.get("Referer") if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaEdit.html', data=data, spotify=spotify, voltarButton=voltarButton, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaEdit.html', data=data, spotify=spotify, voltarButton=voltarButton)
def index(): if 'id' not in session: __createSessionVariables() spotifyArtist = [] spotifyAlbum = [] spotifyTrack = [] spotifyPlaylist = [] users = UsersRepository().List() reviewsArtist = ResenhaRepository().List('artista', 6) reviewsAlbum = ResenhaRepository().List('album', 6) reviewsTrack = ResenhaRepository().List('track', 6) reviewsPlaylist = ResenhaRepository().List('playlist', 6) for item in reviewsArtist: spotifyArtist.append(SpotifyGetOneArtist(item.spotify_id).oneArtist) for item in reviewsAlbum: spotifyAlbum.append(SpotifyGetOneAlbum(item.spotify_id).oneAlbum) for item in reviewsTrack: spotifyTrack.append(SpotifyGetOneTrack(item.spotify_id).oneTrack) for item in reviewsPlaylist: spotifyPlaylist.append( SpotifyGetOnePlaylist(item.spotify_id).onePlaylist) if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('index.html', reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, reviewsPlaylist=reviewsPlaylist, users=users, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, spotifyPlaylist=spotifyPlaylist, mainFilter='index', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('index.html', reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, reviewsPlaylist=reviewsPlaylist, users=users, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, spotifyPlaylist=spotifyPlaylist, mainFilter='index')
def filterTrack(): if 'id' not in session: session['id'] = '' spotifyTrack = [] users = UsersRepository().List() reviewsTrack = ResenhaRepository().List('track') for item in reviewsTrack: spotifyTrack.append(SpotifyGetOneTrack(item.spotify_id).oneTrack) if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('filters/filterTracks.html', reviewsTrack=reviewsTrack, spotifyTrack=spotifyTrack, users=users, comments=comments, notifyComment=notifyComment, notifyLike=notifyLike, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll) else: return render_template('filters/filterTracks.html', reviewsTrack=reviewsTrack, spotifyTrack=spotifyTrack, users=users)
def adm_resenhas(): reviewsArtist = ResenhaRepository().List('artista') reviewsAlbum = ResenhaRepository().List('album') reviewsTrack = ResenhaRepository().List('track') reviewsPlaylist = ResenhaRepository().List('playlist') return render_template('_adm_resenhas.html', reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, reviewsPlaylist=reviewsPlaylist)
def resenhado(id): if 'id' not in session: session['id'] = '' data = ResenhaRepository().FindById(id) spotifyId = data.spotify_id if data.tipo_review == 'artista': spotify = SpotifyGetOneArtist(spotifyId).oneArtist elif data.tipo_review == 'album': spotify = SpotifyGetOneAlbum(spotifyId).oneAlbum elif data.tipo_review == 'track': spotify = SpotifyGetOneTrack(spotifyId).oneTrack else: spotify = SpotifyGetOnePlaylist(spotifyId).onePlaylist user_author = UsersRepository().FindById(data.author_id) date = DateConversion(str(data.date_register)) like = CurtidasRepository().CountLikes(id).count commentsList = CommentsRepository().List(id) comment_user = UsersRepository().List() try: if CurtidasRepository().FindById(session['id'], id): PNG = 'unclick' else: PNG = 'click' except: PNG = 'click' if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhado.html', data=data, spotify=spotify, user_author=user_author, date=date, commentsList=commentsList, comment_user=comment_user, like=like, PNG=PNG, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhado.html', data=data, spotify=spotify, user_author=user_author, date=date, commentsList=commentsList, comment_user=comment_user, like=like, PNG=PNG)
def editAccount(): if session['email'] == '' or 'email' not in session: flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('ind.home')) else: if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId( session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById( session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('account/editAccount.html', user=UsersRepository().FindById( session['id']), comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('account/editAccount.html', user=UsersRepository().FindById( session['id']))
def createResenha(): if session['email'] == '' or 'email' not in session: flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('log.login')) tipo_review = request.form['tipo_review'] author_id = session['id'] nome_review = request.form['nome_review'] spotify_id = request.form['spotify_id'] review = request.form['review'] spotifyArtistId = request.form['spotifyArtistId'] if spotifyArtistId: spotifyArtistGenres = SpotifyGetOneArtist(spotifyArtistId).createList().get('genres') elif tipo_review == 'playlist': spotifyArtistGenres = '' else: spotifyArtistGenres = SpotifyGetOneArtist(spotify_id).createList().get('genres') # -- get Genre -- genre = '' if spotifyArtistGenres: for genreName, value in genres.items(): for i in spotifyArtistGenres: if i in value: genre = genreName break # In case of error, review will be in session KeepInSession(request.form['spotify_id'], request.form['nome_review'], request.form['review']) ResenhaRepository().New(tipo_review, author_id, nome_review, spotify_id, review, genre) CleanSession() flash('Resenha criada com sucesso', 'success') return redirect(url_for('ind.home'))
def updateResenha(): id = request.form['id'] nome_review = str(request.form['nome_review']) review = request.form['review'] ResenhaRepository().Edit(id, nome_review, review) flash('Resenha atualizada com sucesso', 'success') return redirect(url_for('res.resenhado', id=id))
def comentario(): id_resenha = request.form['id'] id_user = session['id'] review = request.form['comentario'] CommentsRepository().New(id_resenha, id_user, review) authorID = ResenhaRepository().FindById(id_resenha).author_id CommentsRepository().CommentNew(authorID) id = int(id_resenha) return redirect(url_for('res.resenhado', id=id))
def curtida(resenha_id): if 'email' not in session: session['email'] = '' if session['email'] == '' or 'email' not in session: flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('log.login')) if CurtidasRepository().FindById(session['id'], resenha_id): CurtidasRepository().Delete(session['id'], resenha_id) else: CurtidasRepository().New(session['id'], resenha_id) authorID = ResenhaRepository().FindById(resenha_id).author_id CurtidasRepository().LikeNew(authorID) return redirect(url_for('res.resenhado', id=resenha_id))
def resenhaListArtist(): artists = SpotifyGetFiveArtists(request.form['artist']).listArtists session['resenhaArtist'] = request.form['artist'] if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaListArtist.html', artists=artists, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaListArtist.html', artists=artists)
def resenhaListTracks(): tracks = SpotifyGetTracks(request.form['spotifyTracks']).createList() session['resenhaTrack'] = request.form['spotifyTracks'] if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaListTracks.html', tracks=tracks, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaListTracks.html', tracks=tracks)
def resenhalistAlbums(artistId): albums = SpotifyGetAlbums(artistId).createList() session['resenhaAlbums'] = artistId if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaListAlbums.html', albums=albums, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaListAlbums.html', albums=albums)
def _adm(): if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('_adm.html', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('_adm.html')
def resenhaListPlaylists(): if SpotifyCheckUser(request.form['spotifyUsername']): playlists = SpotifyGetPlaylists(request.form['spotifyUsername']).createList() if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaListPlaylists.html', playlists=playlists, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaListPlaylists.html', playlists=playlists) else: flash('Nome de usuário não encontrado', 'danger') return redirect(url_for('res.resenhaIndex'))
def minhas_resenhas(id): if session['email'] == '' or 'email' not in session or session['id'] == '': flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('log.login')) if 'id' not in session: session['id'] = '' reviews = ResenhaRepository().FindAuthorById(id) user = UsersRepository().FindById(id) if not reviews: flash('Você ainda não criou nenhuma resenha', 'info') return redirect(url_for('ind.home')) else: return redirect( url_for('filter.myPage', name=str(user.name).lower(), surname=str(user.surname).lower()))
def resenhaIndex(): CleanSession() if session['email'] == '' or 'email' not in session: session['previous'] = 'res.resenhaIndex' flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('log.login')) if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaIndex.html', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaIndex.html')
def resenhaNewArtist(artistId): if session['email'] == '' or 'email' not in session: flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('log.login')) spotify = SpotifyGetOneArtist(artistId).createList() if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaNew.html', spotify=spotify, tipo_review='artista', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaNew.html', spotify=spotify, tipo_review='artista')
def filterGenres(): if 'id' not in session: session['id'] = '' genres = genres_model.genres resenhasListAll = ResenhaRepository().ListAll() for i in resenhasListAll: print(i.nome_review, i.genre) genreCount = {} for item in genres: count = 0 for genre in resenhasListAll: if genre.genre == item: count += 1 if count > 0: genreCount[item] = count return render_template('filters/filterGenres.html', genres=genres, genreCount=genreCount)
def ResenhasDelete(resenha_id): CommentsRepository().DeleteAllComments(resenha_id) ResenhaRepository().Delete(resenha_id) flash('Resenha Successfully removed', 'info') return redirect(url_for('adm.adm_resenhas'))
def myPage(name, surname): if 'id' not in session: session['id'] = '' try: authorID = ResenhaRepository().FindAuthorByNameSurname( str(name).title(), str(surname).title()).id if not authorID: return redirect(url_for('ind.home')) reviews = ResenhaRepository().FindAuthorById(authorID) if not reviews: flash( f'{str(name).title()} {str(surname).title()} ainda não criou resenhas', 'info') return redirect(url_for('ind.home')) else: flash( f'Resenhas de {str(name).title()} {str(surname).title()}: ' f" resenhando.co/{str(name).lower()}-{str(surname).lower()} ", 'info') spotifyArtist = [] spotifyAlbum = [] spotifyTrack = [] spotifyPlaylist = [] reviewsArtist = [] reviewsAlbum = [] reviewsTrack = [] reviewsPlaylist = [] users = UsersRepository().List() for item in reviews: if item.tipo_review == 'artista': reviewsArtist.append(item) elif item.tipo_review == 'album': reviewsAlbum.append(item) elif item.tipo_review == 'track': reviewsTrack.append(item) elif item.tipo_review == 'playlist': reviewsPlaylist.append(item) for item in reviews: if item.tipo_review == 'artista': spotifyArtist.append( SpotifyGetOneArtist(item.spotify_id).oneArtist) elif item.tipo_review == 'album': spotifyAlbum.append( SpotifyGetOneAlbum(item.spotify_id).oneAlbum) elif item.tipo_review == 'track': spotifyTrack.append( SpotifyGetOneTrack(item.spotify_id).oneTrack) elif item.tipo_review == 'playlist': spotifyPlaylist.append( SpotifyGetOnePlaylist(item.spotify_id).onePlaylist) if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId( session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById( session['id']).read_comment notifyLike = UsersRepository().FindById( session['id']).read_like return render_template('resenha/resenhaViews.html', reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, reviewsPlaylist=reviewsPlaylist, users=users, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, spotifyPlaylist=spotifyPlaylist, mainFilter='myPage', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('index.html', reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, reviewsPlaylist=reviewsPlaylist, users=users, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, spotifyPlaylist=spotifyPlaylist, mainFilter='myPage') except: flash('Usuário não identificado', 'danger') return redirect(url_for('ind.home'))
def genresBody(genreLink): if 'id' not in session: session['id'] = '' genreLink = genreLink users = UsersRepository().List() genres = genres_model.genres resenhasListAll = ResenhaRepository().ListAll() spotifyArtist = [] spotifyAlbum = [] spotifyTrack = [] reviewsArtist = ResenhaRepository().ListOneGenre('artista', genreLink) for item in reviewsArtist: print(item.genre) reviewsAlbum = ResenhaRepository().ListOneGenre('album', genreLink) reviewsTrack = ResenhaRepository().ListOneGenre('track', genreLink) for item in reviewsArtist: spotifyArtist.append(SpotifyGetOneArtist(item.spotify_id).oneArtist) for item in reviewsAlbum: spotifyAlbum.append(SpotifyGetOneAlbum(item.spotify_id).oneAlbum) for item in reviewsTrack: spotifyTrack.append(SpotifyGetOneTrack(item.spotify_id).oneTrack) genreCount = {} for item in genres: count = 0 for genre in resenhasListAll: if genre.genre == item: count += 1 if count > 0: genreCount[item] = count if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('filters/genresBody.html', users=users, reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, notifyComment=notifyComment, notifyLike=notifyLike, genres=genres, genreCount=genreCount, genreLink=genreLink) else: return render_template('filters/genresBody.html', users=users, reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, genres=genres, genreCount=genreCount, genreLink=genreLink)