示例#1
0
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)
示例#2
0
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)
示例#3
0
文件: wiki.py 项目: yxm0513/flask-ims
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)
示例#4
0
文件: todo.py 项目: yxm0513/flask-ims
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')
示例#5
0
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)
示例#6
0
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)
示例#7
0
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)
示例#8
0
def todos():
    return render_template("admin/todos.html", todos=Todo.query.order_by(Todo.pub_date.desc()).all())
示例#9
0
def deltodo():
    return render_template("admin/deltodo.html")
示例#10
0
def addtodo():
    return render_template("admin/addtodo.html")
示例#11
0
def users():
    users = User.query.all()
    return render_template("admin/users.html", users=users)
示例#12
0
def index():
    return render_template("admin/index.html")
示例#13
0
def index():
    return render_template('photo/index.html', photo = Photo.query.all())
示例#14
0
def help():
    return render_template("general/help.html")
示例#15
0
def forbidden(error):
    if request.is_xhr:
        return jsonify(error=_("Sorry, not allowed"))
    return render_template("error/403.html", error=error)
示例#16
0
def server_error(error):
    if request.is_xhr:
        return jsonify(error=_("Sorry, an error has occurred"))
    return render_template("error/500.html", error=error)
示例#17
0
def page_not_found(error):
    if request.is_xhr:
        return jsonify(error=_("Sorry, page not found"))
    return render_template("error/404.html", error=error)
示例#18
0
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)
示例#19
0
def about():
    return render_template("general/about.html")
示例#20
0
def themes():
    themes = get_themes_list()
    return render_template("admin/themes.html", themes=themes)
示例#21
0
def settings():
    return render_template("general/settings.html")
示例#22
0
def database():
    return render_template("admin/database.html")
示例#23
0
文件: test.py 项目: yxm0513/flask-ims
def test():
    form = TestForm()
    return render_template("test/test.html", form = form)
示例#24
0
文件: feed.py 项目: yxm0513/flask-ims
def reader():
    d = parse("https://github.com/yxm0513/flask-ims/commits/master.atom")
    return render_template('feed/reader.html', d=d)
示例#25
0
def index():
    return render_template('general/index.html')
示例#26
0
def unauthorized():
    return render_template("account/unauthorized.html")
示例#27
0
文件: test.py 项目: yxm0513/flask-ims
def jquery1():
    return render_template("test/jquery_antimate.html")
示例#28
0
文件: test.py 项目: yxm0513/flask-ims
def jquery2():
    return render_template("test/jquery_slide.html")
示例#29
0
文件: todo.py 项目: yxm0513/flask-ims
def index():
    return render_template('todo/index.html',
        todos=Todo.query.order_by(Todo.pub_date.desc()).all()
    )