Пример #1
0
def edit_preview(id):
    article = helper.getArticle(id)
    render_article = helper.render_article(article)

    form = forms.EditStaticItem(fl.request.form)

    if fl.request.method == 'POST' and form.validate():  # method is POST
        preview = form.body.data
        trimmed = helper.trimPreview(preview)
        cursor = mysql.get_db().cursor()
        if cursor.execute("select * from preview where id = %s", id) != 0:
            cursor.execute("update preview set preview=%s where id=%s" , (trimmed, id))
        else:
            cursor.execute("insert into preview values (%s, %s)" , (id, trimmed))            
        mysql.get_db().commit()
        cursor.close()

        return fl.redirect(fl.url_for('panel'))

    else:  # method is probably GET
        title = render_article['title']
        preview = helper.getPreview(id)
        # Fill form with existing content
        form.static_type.data = title
        form.body.data = preview


        return fl.render_template('archive/edit_static.html', form=form, heading="Edit preview")
Пример #2
0
def new_article():
    form = forms.EditArticle(fl.request.form)
    # if request.method == 'POST' and form.validate(), do real stuff:
    if fl.request.method == 'POST' and form.validate():
        author = form.author.data
        title = form.title.data
        alias = form.alias.data
        if len(alias) == 0:
            alias = helper.title2alias(title)
        body = form.body.data
        hidden = form.hidden.data

        cursor = mysql.get_db().cursor()
        _no_of_alias    = cursor.execute("select * from archive where alias=%s", (alias))
        _id             = cursor.fetchone()
        while _no_of_alias > 0 and _id == id:
            alias = alias + "-"
        if hidden:
            cursor.execute("insert into archive values(NULL, %s, NULL, NULL, %s, %s, %s, 1)", (author, title, alias, body))
        else:
            cursor.execute("insert into archive values(NULL, %s, NULL, NULL, %s, %s, %s, 0)", (author, title, alias, body)) 
        
        mysql.get_db().commit()
        cursor.close()

        return fl.redirect(fl.url_for('panel'))

    return fl.render_template('archive/edit_article.html', form=form, heading="New article")
Пример #3
0
def delArticle(id):
    try:
        cursor = mysql.get_db().cursor()
        cursor.execute("delete from archive where id=%s" , (id))
        mysql.get_db().commit()
        cursor.close()

        return fl.redirect(fl.url_for("panel"))
    except:
        fl.abort(404)
Пример #4
0
def login():
    if fl.request.method == 'POST':
        # get form details
        username = fl.request.form['username']
        password_candidate = fl.request.form['password']

        # create cursor
        cursor = mysql.get_db().cursor()

        # get user by username
        result = cursor.execute("SELECT * FROM users WHERE username = %s", [username])

        if result > 0:
            # get stored hash
            data = cursor.fetchone()
            password = data[3]

            # authenticate
            if hs.sha256_crypt.verify(password_candidate, password):
                fl.session['logged_in'] = True
                fl.session['username'] = username

                fl.flash("You're now logged in.", "success")
                return fl.redirect(fl.url_for('panel'))
            else:
                fl.flash("Failure", "error")
    
    return fl.render_template("archive/login.html")
Пример #5
0
def lab():
    ''' get the list of article '''
    cursor = mysql.get_db().cursor()
    result = cursor.execute("SELECT * FROM archive")  # result gives # of query results
    articles = cursor.fetchall()  # articles gives a tuple of all results (explicit informaiton)
    # print("result", result)  # DEBUG
    # print("articles", articles)  # DEBUG
    # for article in articles:  # DEBUG
    #     print(article)

    article_list = list()  # make a list of articles, easy to retrieve
    for article in articles:
        render_article = helper.render_article(article)
        article_list.append(render_article)
        # print(render_article)  # DEBUG
    
    ''' Get the list of static items'''
    result = cursor.execute("SELECT * FROM static")  # result gives # of query results
    static = cursor.fetchall()  # articles gives a tuple of all results (explicit informaiton)

    static_list = list()
    for static_item in static:
        render_static = helper.render_static_item(static_item)
        static_list.append(render_static)
        # print(static_item)  # DEBUG

    cursor.close()

    return fl.render_template("archive/lab.html", articles=article_list, static=static_list)
Пример #6
0
def getMCSbyId(id):
    cursor = mysql.get_db().cursor()
    result = cursor.execute("SELECT * FROM mcs where id=%s", id)  # get preview
    mcs_entry = cursor.fetchone()
    cursor.close()

    return mcs_entry
Пример #7
0
def getArticle(id):
    cursor = mysql.get_db().cursor()
    cursor.execute("SELECT * FROM archive WHERE id = %s",
                   [id])  # only one will be returned (if > 1, serious bug!!)
    article = cursor.fetchone()
    cursor.close()

    return article
Пример #8
0
def getStaticItem(static_type):
    cursor = mysql.get_db().cursor()
    cursor.execute(
        "SELECT * FROM static WHERE static_type = %s",
        [static_type])  # only one will be returned (if > 1, serious bug!!)
    static_item = cursor.fetchone()
    cursor.close()

    return static_item
Пример #9
0
def getPreview(id):
    cursor = mysql.get_db().cursor()
    result = cursor.execute("SELECT preview FROM preview where id=%s",
                            id)  # get preview
    preview = cursor.fetchone()
    if not preview is None:
        preview = preview[0]
    else:
        preview = ""
    cursor.close()

    return preview
Пример #10
0
def edit_article(id):
    article = helper.getArticle(id)
    render_article = helper.render_article(article)

    form = forms.EditArticle(fl.request.form)

    if fl.request.method == 'POST' and form.validate():  # method is POST
        author = form.author.data
        title = form.title.data
        body = form.body.data
        alias = form.alias.data
        if len(alias) == 0:
            alias = helper.title2alias(title)
        hidden = form.hidden.data

        cursor = mysql.get_db().cursor()
        _no_of_alias    = cursor.execute("select * from archive where alias=%s", (alias))
        _id             = cursor.fetchone()
        while _no_of_alias > 0 and _id == id:
            alias = alias + "-"
        if hidden:
            cursor.execute("update archive set author=%s, title=%s, alias=%s, body=%s, hidden=1 where id=%s" , (author, title, alias, body, id))
        else:
            cursor.execute("update archive set author=%s, title=%s, alias=%s, body=%s, hidden=0 where id=%s" , (author, title, alias, body, id))            
        mysql.get_db().commit()
        cursor.close()

        return fl.redirect(fl.url_for('panel'))

    else:  # method is probably GET
        # Fill form with existing content
        form.author.data = render_article['author']
        form.title.data = render_article['title']
        form.body.data = helper.pprint_html(render_article['body'])
        form.alias.data = render_article['alias']
        form.hidden.data = render_article['hidden']


        return fl.render_template('archive/edit_article.html', form=form, heading="Edit article")
Пример #11
0
def edit_static(static_type):
    static_item = helper.getStaticItem(static_type)
    render_static_item = helper.render_static_item(static_item)

    form = forms.EditStaticItem(fl.request.form)

    if fl.request.method == 'POST' and form.validate():  # method is POST
        static_type = form.static_type.data
        body = form.body.data

        cursor = mysql.get_db().cursor()
        cursor.execute("update static set static_type=%s, body=%s where static_type=%s" , (static_type, body, static_type))
        mysql.get_db().commit()
        cursor.close()

        return fl.redirect(fl.url_for('panel'))

    else:  # method is probably GET
        # Fill form with existing content
        form.static_type.data = render_static_item['static_type']
        form.body.data = render_static_item['body']

        return fl.render_template('archive/edit_static.html', form=form)
Пример #12
0
def getAllStatic():
    # Get static_dic
    cursor = mysql.get_db().cursor()
    result = cursor.execute(
        "SELECT * FROM static")  # result gives # of query results
    static = cursor.fetchall(
    )  # articles gives a tuple of all results (explicit informaiton)

    static_list = list()
    for static_item in static:
        render_static = render_static_item(static_item)
        static_list.append(render_static)
    cursor.close()

    return classify_static(static_list)
Пример #13
0
def archive():
    cursor = mysql.get_db().cursor()
    result = cursor.execute("SELECT * FROM archive")  # result gives # of query results
    articles = cursor.fetchall()  # articles gives a tuple of all results (explicit information)

    article_list = list()  # make a list of articles, easy to retrieve
    for article in articles:
        if article[7] == 0:  # only display articles that are not hidden
            render_article = helper.render_article(article)
            # preview = getPreview(render_article['id'])  # get preview by id
            # render_article['preview'] = preview
            article_list.append(render_article)
    
    cursor.close()

    return fl.render_template('archive/index.html', articles=article_list)