def update_track(track_id): track = Track.query.get_or_404(track_id) if track.author != current_user: abort(403) form = TrackForm() if form.validate_on_submit(): tags = form.lyrics.data tags = tags.replace("<p>", '') tags = tags.replace("</p>", "<br/>") track.title = form.title.data track.lyrics = tags track.lyrics_with_scraps = tags track.description = form.description.data track.date_release = form.date_release.data track.lyrics_by = form.lyrics_by.data track.date_last_update = datetime.strptime(str(datetime.utcnow()), "%Y-%m-%d %H:%M:%S.%f") for scrap in track.scraps: db.session.delete(scrap) db.session.commit() flash("Wątek zaktualizowany!", 'success') return redirect(url_for('user_activity.track', track_id=track.id)) elif request.method == "GET": form.title.data = track.title form.lyrics.data = track.lyrics form.description.data = track.description form.date_release.data = track.date_release form.lyrics_by.data = track.lyrics_by return render_template('create_track.html', title="Edytuj utwór", track_id=track_id, legend="Edytuj utwór", form=form, image_file=check_image())
def scraps(track_id): track = Track.query.get_or_404(track_id) tags = track.lyrics_with_scraps scrap_descriptions = [] scrap_authors = [] for scrap in track.scraps: scrap_descriptions.append(scrap.description) scrap_authors.append(scrap.author.username) scrap_descriptions = json.dumps(scrap_descriptions) scrap_authors = json.dumps(scrap_authors) tags = Markup(tags) form = ScrapForm() if form.validate_on_submit(): lyrics_with_scraps = form.lyrics_with_scraps.data lyrics_with_scraps = lyrics_with_scraps.replace('<div id="darkLayer" class="darkClass" style="display: block;"></div>','') track.lyrics_with_scraps = lyrics_with_scraps new_scrap = Scrap(description=form.description.data, track_id=track_id, author=current_user) db.session.add(new_scrap) db.session.commit() flash("Fragment został oznaczony", "success") return redirect(url_for('user_activity.scraps', track_id=track_id)) return render_template('scraps.html', title=track.title, image_file=check_image(), track=track, tags=tags, form=form, scrap_descriptions=scrap_descriptions, scrap_authors=scrap_authors)
def new_track(): form = TrackForm() albums = Album.query.all() if form.validate_on_submit(): albums_list = request.form.getlist("albums") tags = form.lyrics.data tags = tags.replace("<p>", '') tags = tags.replace("</p>", "<br/>") track = Track(title=form.title.data, lyrics=tags, lyrics_with_scraps=tags, author=current_user, date_release=form.date_release.data, lyrics_by=form.lyrics_by.data, description=form.description.data) for cd in albums_list: album = Album.query.filter_by(id=int(cd)).first_or_404() track.albums.append(album) db.session.add(track) db.session.commit() db.session.commit() flash("Utwór został dodany", "success") return redirect(url_for('user_activity.tracks')) return render_template('create_track.html', title="Nowy Utwór", albums=albums, legend="Dodaj nowy utwór", form=form, image_file=check_image())
def admin_panel(): if not current_user.is_admin: abort(403) albums = Album.query.all() return render_template('admin_panel.html', image_file=check_image(), title="Panel administracyjny", albums=albums)
def forum(): threads = Thread.query.order_by(desc( Thread.date_last_update)).limit(5).all() tracks = Track.query.order_by(desc(Track.date_last_update)).limit(5).all() return render_template('forum-home.html', image_file=check_image(), threads=threads, tracks=tracks)
def interpretations(track_id): track = Track.query.get_or_404(track_id) tags = Markup(track.lyrics) interpretations = Interpretation.query. \ filter_by(track=track). \ order_by(asc(Interpretation.date_posted)) return render_template('interpretations.html', title=track.title, image_file=check_image(), track=track, tags=tags, interpretations=interpretations)
def new_thread(): form = ThreadForm() if form.validate_on_submit(): thread = Thread(topic=form.topic.data, description=form.description.data, author=current_user) db.session.add(thread) db.session.commit() flash("Wątek został dodany", "success") return redirect(url_for('main.forum')) return render_template('create_thread.html', title="Nowy wątek", legend="Rozpocznij nowy wątek", form=form, image_file=check_image())
def track_reply(track_id): form = PostForm() if form.validate_on_submit(): post = Track_Post(reply=form.reply.data, author=current_user, track_id=track_id) db.session.add(post) db.session.commit() flash("Odpowiedź została dodana", "success") return redirect(url_for('user_activity.track', track_id=track_id)) return render_template('track_reply.html', title="Dodaj Opinię", legend="Odpowiedz", form=form, image_file=check_image(), track_id=track_id, reply_id=None)
def thread(thread_id): thread = Thread.query.get_or_404(thread_id) tags = Markup(thread.description) posts = Thread_Post.query. \ filter_by(thread=thread). \ order_by(asc(Thread_Post.date_posted)) replies = [] for post in posts: replies.append(Markup(post.reply)) return render_template('thread.html', title=thread.topic, image_file=check_image(), thread=thread, tags=tags, posts=posts, replies=replies)
def track(track_id): track = Track.query.get_or_404(track_id) tags = Markup(track.lyrics) comments = Track_Post.query. \ filter_by(track=track). \ order_by(asc(Track_Post.date_posted)) tags_description = Markup(track.description) replies = [] for comment in comments: replies.append(Markup(comment.reply)) return render_template('track.html', title=track.title, image_file=check_image(), track=track, tags=tags, tags_description=tags_description, comments=comments, replies=replies)
def update_track_post(post_id, track_id): track = Track.query.get_or_404(track_id) post = Track_Post.query.get_or_404(post_id) if post.author != current_user: abort(403) form = PostForm() if form.validate_on_submit(): post.reply = form.reply.data post.date_last_update = datetime.strptime(str(datetime.utcnow()), "%Y-%m-%d %H:%M:%S.%f") db.session.commit() flash("Odpowiedź została zaktualizowana!", 'success') return redirect(url_for('user_activity.track', track_id=track.id)) elif request.method == "GET": form.reply.data = post.reply return render_template('track_reply.html', title="Edytuj odpowiedź", legend="Edytuj odpowiedź", form=form, image_file=check_image(),track_id=track.id)
def update_thread(thread_id): thread = Thread.query.get_or_404(thread_id) if thread.author != current_user: abort(403) form = ThreadForm() if form.validate_on_submit(): thread.topic = form.topic.data thread.description = form.description.data thread.date_last_update = datetime.strptime(str(datetime.utcnow()), "%Y-%m-%d %H:%M:%S.%f") db.session.commit() flash("Wątek zaktualizowany!", 'success') return redirect(url_for('user_activity.thread', thread_id=thread.id)) elif request.method == "GET": form.topic.data = thread.topic form.description.data = thread.description return render_template('create_thread.html', title="Edytuj wątek", legend="Edytuj wątek", form=form, image_file=check_image(), thread_id=thread_id)
def update_album(album_id): if not current_user.is_admin: abort(403) album = Album.query.get_or_404(album_id) form = AlbumForm() if form.validate_on_submit(): album.title = form.title.data album.date_release = form.date_release.data album.description = form.description.data db.session.commit() flash("Album został zaktualizowany!", 'success') return redirect(url_for('main.admin_panel')) elif request.method == "GET": form.title.data = album.title form.description.data = album.description form.date_release.data = album.date_release return render_template('create_album.html', title="Edytuj album", form=form, image_file=check_image())
def create_album(): if not current_user.is_admin: abort(403) form = AlbumForm() if form.validate_on_submit(): year = int(datetime.utcnow().year) print("_____________________________________________________-", file=sys.stderr) print(year, file=sys.stderr) print("_____________________________________________________", file=sys.stderr) album = Album(title=form.title.data, date_release=form.date_release.data, description=form.description.data) db.session.add(album) db.session.commit() flash('Album dodano pomyślnie!', 'success') return redirect(url_for('main.admin_panel')) return render_template('create_album.html', title="Dodaj album", form=form, image_file=check_image())
def quote_track_post(track_id, post_id): post = Track_Post.query.get_or_404(post_id) form = PostForm() date_posted = str(datetime.strptime(str(post.date_posted), "%Y-%m-%d %H:%M:%S.%f")) date_posted = date_posted.split(".")[0] quote = "<div>" \ "<div style='background:#eeeeee;border:1px solid #cccccc;padding:5px 10px;'>" \ "<b>" + post.author.username + "</b> powiedział " + date_posted + \ "</div>" \ "<blockquote class='cke_contents_ltr blockquote'>" + post.reply + "</blockquote>" \ "<p></p></div>" if form.validate_on_submit(): post = Track_Post(reply=form.reply.data, author=current_user, track_id=track_id) db.session.add(post) db.session.commit() flash("Odpowiedź została dodana", "success") return redirect(url_for('user_activity.track', track_id=track_id)) elif request.method == "GET": form.reply.data = Markup(quote) return render_template('track_reply.html', title="Rozwiń wątek", legend="Odpowiedz użytkownikowi " + post.author.username, form=form, image_file=check_image(), track_id=track_id, reply_id=None)
def user_actions(username): strona = request.args.get('strona', 1, type=int) user = User.query.filter_by(username=username).first_or_404() threads = Thread.query. \ filter_by(author=user). \ order_by(desc(Thread.date_posted)). \ paginate(page=strona, per_page=5) return render_template('user_activity.html', title="Aktywność użytkownika", image_file=check_image(), threads=threads, user=user)
def tracks(): strona = request.args.get('strona', 1, type=int) tracks = Track.query.order_by(desc(Track.date_last_update)).paginate(page=strona, per_page=5) return render_template('tracks.html', title="Utwory", image_file=check_image(), tracks=tracks)
def threads(): strona = request.args.get('strona', 1, type=int) threads = Thread.query.order_by(desc(Thread.date_last_update)).paginate(page=strona, per_page=5) return render_template('threads.html', title="Wątki", image_file=check_image(), threads=threads)