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")
def view(id): article = helper.getArticle(id) render_article = helper.render_article(article) render_article['title'] = render_article['title'] return fl.render_template('archive/article.html', article=render_article)
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)
def article(alias): article = helper.getArticleByAlias(alias) render_article = helper.render_article(article) if render_article['hidden']: # fl.abort(404) return fl.render_template('archive/article.html', article=render_article) else: return fl.render_template('archive/article.html', article=render_article)
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)
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")