def register(): """Registers the user.""" form = RegisterForm(request.form) if not (current_user.is_anonymous()): flash("you are logined") return render_template("logout.html") if request.method == "POST" and form.validate_on_submit(): username = form.username.data password = form.password.data password2 = form.password2.data email = form.email.data if User.query.filter_by(username=username).first(): flash("The username is already taken") elif cmp(password, password2) != 0: flash("password mismatched") else: user = User(username, None, email) user.set_password(password) try: user.store_to_db() return render_template("account/registerok.html") except: flash("You were register failed, pls contact %s for help." % app.config["ADMIN"][1]) else: return render_template("account/register.html", form=form) return render_template("account/register.html", form=form)
def upload(): form = UploadForm(request.form) if not form.validate: flash('form validation failed', 'error') return render_template('photo/upload.html', form = form) if request.method == 'POST' and 'photo' in request.files: filename = photos.save(request.files['photo']) rec = Photo(filename=filename, user=current_user.id) rec.store_to_db() flash("Photo saved.") return redirect(url_for('show', id=rec.id)) return render_template('photo/upload.html', form = form)
def wiki(name='MainPage'): if request.method == 'POST': #save if 'save' in request.form: wiki = Wiki.query.filter_by(title=name).first() form = WikiEditForm() if wiki: wiki.text = form.wikitext.data wiki.store_to_db() else: wiki = Wiki(title=name, text=form.wikitext.data) try: wiki.store_to_db() except: app.logger.debug('failed') return redirect(url_for('wiki', name=name)) #edit if 'edit' in request.form: wiki = Wiki.query.filter_by(title=name).first() if not wiki: flash("Creat a new page") form = WikiEditForm() form.set_default_text(text="Input text here") return render_template("wiki/edit.html", form=form, name = name) else: text = wiki.text form = WikiEditForm() form.set_default_text(text=text) return render_template("wiki/edit.html", form=form, name = name) if 'attach' in request.form: return render_template("wiki/attach.html", form=form, name = name) else: form = WikiShowForm() # get it from database wiki = Wiki.query.filter_by(title=name).first() # render to template return render_template("wiki/show.html", form=form, wiki=wiki, name=name) else: form = WikiShowForm() # get it from database wiki = Wiki.query.filter_by(title=name).first() # render to template return render_template("wiki/show.html", form=form, wiki=wiki, name=name)
def new(): if request.method == 'POST': if not request.form['title']: flash('Title is required', 'error') elif not request.form['text']: flash('Text is required', 'error') else: todo = Todo(request.form['title'], request.form['text']) todo.store_to_db() flash(u'Todo item was successfully created') return redirect(url_for('index')) return render_template('todo/new.html')
def deluser(): remove_form = RemoveUserForm(request.form) if request.method == "POST" and remove_form.validate_on_submit(): username = remove_form.username.data user = User.query.filter_by(username=username).first() if not user: flash("The username has not taken") else: try: user.delete_from_db() flash("del user %s done." % user.username) except: flash("del user failed %s" % user.username, "error") return render_template("admin/deluser.html", remove_form=remove_form)
def adduser(): add_form = AddUserForm(request.form) if request.method == "POST" and add_form.validate_on_submit(): username = add_form.username.data password = add_form.password.data email = add_form.email.data if User.query.filter_by(username=username).first(): flash("The username is already taken") hash_pass = generate_password_hash(password, method="sha1", salt_length=8) user = User(username, hash_pass, email) try: user.store_to_db() flash("add user %s done." % user.username) except: flash("add user failed %s" % user.username, "error") return render_template("admin/adduser.html", add_form=add_form)
def login(): form = LoginForm(request.form) if request.method == "POST" and form.validate_on_submit(): username = form.username.data password = form.password.data # remember = form.remember.data remember = 1 user = User.query.filter_by(username=username).first() if not len(form.errors): if user and user.check_password(password): loginuser = LoginUser(user.id, user.username) if login_user(loginuser, remember=remember): flash("Logged in successfully!") return redirect(request.args.get("next") or url_for("general.index")) else: flash("Sorry, but you could not log in.", "error") else: flash("Incorrect username or password", "error") return render_template("account/login.html", form=form)
def todos(): return render_template("admin/todos.html", todos=Todo.query.order_by(Todo.pub_date.desc()).all())
def deltodo(): return render_template("admin/deltodo.html")
def addtodo(): return render_template("admin/addtodo.html")
def users(): users = User.query.all() return render_template("admin/users.html", users=users)
def index(): return render_template("admin/index.html")
def index(): return render_template('photo/index.html', photo = Photo.query.all())
def help(): return render_template("general/help.html")
def forbidden(error): if request.is_xhr: return jsonify(error=_("Sorry, not allowed")) return render_template("error/403.html", error=error)
def server_error(error): if request.is_xhr: return jsonify(error=_("Sorry, an error has occurred")) return render_template("error/500.html", error=error)
def page_not_found(error): if request.is_xhr: return jsonify(error=_("Sorry, page not found")) return render_template("error/404.html", error=error)
def show(id): photo = Photo.query.filter_by(id=id).first() if photo is None: abort(404) return render_template('photo/show.html', photo=photo)
def about(): return render_template("general/about.html")
def themes(): themes = get_themes_list() return render_template("admin/themes.html", themes=themes)
def settings(): return render_template("general/settings.html")
def database(): return render_template("admin/database.html")
def test(): form = TestForm() return render_template("test/test.html", form = form)
def reader(): d = parse("https://github.com/yxm0513/flask-ims/commits/master.atom") return render_template('feed/reader.html', d=d)
def index(): return render_template('general/index.html')
def unauthorized(): return render_template("account/unauthorized.html")
def jquery1(): return render_template("test/jquery_antimate.html")
def jquery2(): return render_template("test/jquery_slide.html")
def index(): return render_template('todo/index.html', todos=Todo.query.order_by(Todo.pub_date.desc()).all() )