コード例 #1
0
ファイル: snippets.py プロジェクト: 365zph/flask-website
def new():
    category_id = None
    preview = None
    if 'category' in request.args:
        rv = Category.query.filter_by(slug=request.args['category']).first()
        if rv is not None:
            category_id = rv.id
    if request.method == 'POST':
        category_id = request.form.get('category', type=int)
        if 'preview' in request.form:
            preview = format_creole(request.form['body'])
        else:
            title = request.form['title']
            body = request.form['body']
            if not body:
                flash(u'Error: you have to enter a snippet')
            else:
                category = Category.query.get(category_id)
                if category is not None:
                    snippet = Snippet(g.user, title, body, category)
                    db_session.add(snippet)
                    db_session.commit()
                    flash(u'Your snippet was added')
                    return redirect(snippet.url)
    return render_template('snippets/new.html',
        categories=Category.query.order_by(Category.name).all(),
        active_category=category_id, preview=preview)
コード例 #2
0
ファイル: snippets.py プロジェクト: Vyz333/tf_flask
def new():
    category_id = None
    preview = None
    if 'category' in request.args:
        rv = Category.query.filter_by(slug=request.args['category']).first()
        if rv is not None:
            category_id = rv.id
    if request.method == 'POST':
        category_id = request.form.get('category', type=int)
        if 'preview' in request.form:
            preview = format_creole(request.form['body'])
        else:
            title = request.form['title']
            body = request.form['body']
            if not body:
                flash(u'Error: you have to enter a snippet')
            else:
                category = Category.query.get(category_id)
                if category is not None:
                    snippet = Snippet(g.user, title, body, category)
                    db_session.add(snippet)
                    db_session.commit()
                    flash(u'Your snippet was added')
                    return redirect(snippet.url)
    return render_template('snippets/new.html',
                           categories=Category.query.order_by(
                               Category.name).all(),
                           active_category=category_id,
                           preview=preview)
コード例 #3
0
 def storeAssociation(self, server_url, association):
     assoc = OpenIDAssociation(server_url=server_url,
                               handle=association.handle,
                               secret=association.secret.encode('base64'),
                               issued=association.issued,
                               lifetime=association.lifetime,
                               assoc_type=association.assoc_type)
     db_session.add(assoc)
     db_session.commit()
コード例 #4
0
ファイル: openid_auth.py プロジェクト: ambitos/flask-website
 def storeAssociation(self, server_url, association):
     assoc = OpenIDAssociation(
         server_url=server_url,
         handle=association.handle,
         secret=association.secret.encode("base64"),
         issued=association.issued,
         lifetime=association.lifetime,
         assoc_type=association.assoc_type,
     )
     db_session.add(assoc)
     db_session.commit()
コード例 #5
0
ファイル: general.py プロジェクト: ambitos/flask-website
def first_login():
    if g.user is not None or "openid" not in session:
        return redirect(url_for(".login"))
    if request.method == "POST":
        if "cancel" in request.form:
            del session["openid"]
            flash(u"Login was aborted")
            return redirect(url_for("general.login"))
        db_session.add(User(request.form["name"], session["openid"]))
        db_session.commit()
        flash(u"Successfully created profile and logged in")
        return redirect(oid.get_next_url())
    return render_template("general/first_login.html", next=oid.get_next_url(), openid=session["openid"])
コード例 #6
0
ファイル: openid_auth.py プロジェクト: ambitos/flask-website
 def useNonce(self, server_url, timestamp, salt):
     if abs(timestamp - time()) > nonce.SKEW:
         return False
     rv = OpenIDUserNonce.query.filter(
         (OpenIDUserNonce.server_url == server_url)
         & (OpenIDUserNonce.timestamp == timestamp)
         & (OpenIDUserNonce.salt == salt)
     ).first()
     if rv is not None:
         return False
     rv = OpenIDUserNonce(server_url=server_url, timestamp=timestamp, salt=salt)
     db_session.add(rv)
     db_session.commit()
     return True
コード例 #7
0
 def useNonce(self, server_url, timestamp, salt):
     if abs(timestamp - time()) > nonce.SKEW:
         return False
     rv = OpenIDUserNonce.query.filter(
         (OpenIDUserNonce.server_url == server_url)
         & (OpenIDUserNonce.timestamp == timestamp)
         & (OpenIDUserNonce.salt == salt)).first()
     if rv is not None:
         return False
     rv = OpenIDUserNonce(server_url=server_url,
                          timestamp=timestamp,
                          salt=salt)
     db_session.add(rv)
     db_session.commit()
     return True
コード例 #8
0
ファイル: general.py プロジェクト: fendouai/flask-website
def first_login():
    if g.user is not None or 'openid' not in session:
        return redirect(url_for('.login'))
    if request.method == 'POST':
        if 'cancel' in request.form:
            del session['openid']
            flash(u'Login was aborted')
            return redirect(url_for('general.login'))
        db_session.add(User(request.form['name'], session['openid']))
        db_session.commit()
        flash(u'Successfully created profile and logged in')
        return redirect(oid.get_next_url())
    return render_template('general/first_login.html',
                           next=oid.get_next_url(),
                           openid=session['openid'])
コード例 #9
0
ファイル: snippets.py プロジェクト: pallets/flask-website
def show(id):
    snippet = Snippet.query.get(id)
    if snippet is None:
        abort(404)
    if request_wants_json():
        return jsonify(snippet=snippet.to_json())
    if request.method == 'POST':
        title = request.form['title']
        text = request.form['text']
        if text:
            db_session.add(Comment(snippet, g.user, title, text))
            db_session.commit()
            flash(u'Your comment was added')
            return redirect(snippet.url)
    return render_template('snippets/show.html', snippet=snippet)
コード例 #10
0
ファイル: general.py プロジェクト: zhuhj89/flask-website
def first_login():
    if g.user is not None or 'openid' not in session:
        return redirect(url_for('.login'))
    if request.method == 'POST':
        if 'cancel' in request.form:
            del session['openid']
            flash(u'Login was aborted')
            return redirect(url_for('general.login'))
        db_session.add(User(request.form['name'], session['openid']))
        db_session.commit()
        flash(u'Successfully created profile and logged in')
        return redirect(oid.get_next_url())
    return render_template('general/first_login.html',
                           next=oid.get_next_url(),
                           openid=session['openid'])
コード例 #11
0
ファイル: snippets.py プロジェクト: zhuzhuxia480/callcenter
def show(id):
    snippet = Snippet.query.get(id)
    if snippet is None:
        abort(404)
    if request_wants_json():
        return jsonify(snippet=snippet.to_json())
    if request.method == 'POST':
        title = request.form['title']
        text = request.form['text']
        if text:
            db_session.add(Comment(snippet, g.user, title, text))
            db_session.commit()
            flash(u'Your comment was added')
            return redirect(snippet.url)
    return render_template('snippets/show.html', snippet=snippet)
コード例 #12
0
ファイル: snippets.py プロジェクト: 365zph/flask-website
def new_category():
    category = Category(name=request.form['name'])
    db_session.add(category)
    db_session.commit()
    flash(u'Category %s created.' % category.name)
    return redirect(url_for('.manage_categories'))
コード例 #13
0
ファイル: snippets.py プロジェクト: Vyz333/tf_flask
def new_category():
    category = Category(name=request.form['name'])
    db_session.add(category)
    db_session.commit()
    flash(u'Category %s created.' % category.name)
    return redirect(url_for('.manage_categories'))