def converter(): collected_audios = Content.query.all() my_audios = {} for c in collected_audios: my_audios[c.c_audio] = str("/converter/" + str(c.c_id)) form = SearchForm() if form.validate_on_submit(): a_search = form.search.data a_format = form.radios.data content = Content.query.filter_by(c_link=a_search, c_format=a_format).first() if content is None: #TODO: fix exceptions a_link, a_audio, a_format = yt_service.get_audio(a_search, a_format) content = Content(a_link, a_audio, a_format) db.add(content) db.commit() return redirect("converter/"+ str(content.c_id)) return render_template("converter.html", title="Download Audio", form=form, my_audios=my_audios)
def register(): if current_user.is_authenticated: redirect("home") form = RegisterForm() if form.validate_on_submit(): my_user = User.query.filter_by(u_username=form.username.data).first() if my_user is not None: flash("This username is alrdy in use") return redirect("register") else: if form.password.data != form.password2.data: flash("Your passwords are not equal") return redirect("register") else: my_user = User(form.username.data, form.password.data) db.add(my_user) db.commit() flash("Register completed... wait till the admin activates your account") #strange bug... user get logged in?? logout_user() return redirect("register") return render_template("register.html", title="Register", form=form)