コード例 #1
0
ファイル: articles.py プロジェクト: kaiocesar/auth-flask
def editArticle(article_id):
	flashMessage = None
	if request.method == "POST":
		datas = request.form.to_dict()
		image = request.files.get('image')
		if image:
			filename = secure_filename(image.filename)
			path = os.path.join(current_app.config['MEDIA_ROOT'], filename)
			image.save(path)
			datas['image'] = filename

		Articles.update(datas, ['id'])
		flashMessage = True

	article = Articles.find_one(id=article_id)

	return render_template("admin/articles/edit.html", article= article, flashMessage= flashMessage)
コード例 #2
0
def editArticle(article_id):
    flashMessage = None
    if request.method == "POST":
        datas = request.form.to_dict()
        image = request.files.get('image')
        if image:
            filename = secure_filename(image.filename)
            path = os.path.join(current_app.config['MEDIA_ROOT'], filename)
            image.save(path)
            datas['image'] = filename

        Articles.update(datas, ['id'])
        flashMessage = True

    article = Articles.find_one(id=article_id)

    return render_template("admin/articles/edit.html",
                           article=article,
                           flashMessage=flashMessage)
コード例 #3
0
def new_article():
    if request.method == "GET":
        return render_template("new_article_page.html")
    if request.method == "POST":
        title = request.form["title"]
        desc = request.form["description"]
        user_id = current_user.id

        session = get_session()
        article = Articles(title=title, content=desc, user_id=user_id)
        session.add(article)
        session.commit()
        return redirect("/")
コード例 #4
0
ファイル: articles.py プロジェクト: kaiocesar/auth-flask
def addArticle():
	flashMessage = None

	if request.method == "POST":
		datas = request.form.to_dict()
		image = request.files.get('image')
		if image:
			filename = secure_filename(image.filename)
			path = os.path.join(current_app.config['MEDIA_ROOT'], filename)
			image.save(path)
			datas['image'] = filename
		datas['create_at'] = datetime.now()
		new_article = Articles.insert(datas)
		flashMessage = True

	return render_template("admin/articles/add.html", flashMessage = flashMessage)
コード例 #5
0
def addArticle():
    flashMessage = None

    if request.method == "POST":
        datas = request.form.to_dict()
        image = request.files.get('image')
        if image:
            filename = secure_filename(image.filename)
            path = os.path.join(current_app.config['MEDIA_ROOT'], filename)
            image.save(path)
            datas['image'] = filename
        datas['create_at'] = datetime.now()
        new_article = Articles.insert(datas)
        flashMessage = True

    return render_template("admin/articles/add.html",
                           flashMessage=flashMessage)
コード例 #6
0
from db import db, Articles, Users, AddedArticles
from datetime import datetime

db.create_all()
print('Database created succesfully!')
print('Populating database...')

print('Adding Initial articles to database...')

tmp = Articles(
    date='02.01.2019',
    link=
    'www.wcjb.com/content/news/Florida-man-doesnt-get-straw-attacks-McDonalds-employee-503812581.html',
    headline="Florida man doesn't get straw, attacks McDonald's employee",
    modtime=datetime.now())
db.session.add(tmp)
db.session.commit()

tmp = Articles(
    date='01.02.2019',
    link=
    'www.orlandoweekly.com/Blogs/archives/2019/02/01/a-man-actually-punted-a-rabid-coyote-in-kissimmee',
    headline="A Man Actually Punted a Rabid Coyote in Kissimmee",
    modtime=datetime.now())
db.session.add(tmp)
db.session.commit()

tmp = Articles(
    date='01.03.2019',
    link=
    'www.tampabay.com/florida-politics/buzz/2019/03/01/florida-house-speaker-apologizes-for-referring-to-pregnant-women-as-host-bodies-in-interview-on-abortion/',
コード例 #7
0
ファイル: articles.py プロジェクト: kaiocesar/auth-flask
def articlesAdmin():
	lista = [dict(article) for article in Articles.all()]
	return render_template("admin/articles/index.html", articles = lista )
コード例 #8
0
ファイル: articles.py プロジェクト: kaiocesar/auth-flask
def search():
	q = request.args.get("question")
	results = Articles.query('SELECT * FROM articles WHERE title like "%%s%" ' % (q))
	questions = [dic(article) for article in results]
	return render_template("default/search.html", questions= questions)
コード例 #9
0
ファイル: articles.py プロジェクト: kaiocesar/auth-flask
def article_details(article_id):
	article = Articles.find_one(id=article_id)
	return render_template("default/article-details.html", article=article)
コード例 #10
0
ファイル: articles.py プロジェクト: kaiocesar/auth-flask
def index():
	articles = [dict(article) for article in Articles.all()]
	return render_template("default/index.html", articles= articles)
コード例 #11
0
ファイル: articles.py プロジェクト: kaiocesar/auth-flask
def del_article(article_id):
	Articles.delete(id=article_id)
	return redirect("/admin/articles")
コード例 #12
0
def articlesAdmin():
    lista = [dict(article) for article in Articles.all()]
    return render_template("admin/articles/index.html", articles=lista)
コード例 #13
0
def search():
    q = request.args.get("question")
    results = Articles.query(
        'SELECT * FROM articles WHERE title like "%%s%" ' % (q))
    questions = [dic(article) for article in results]
    return render_template("default/search.html", questions=questions)
コード例 #14
0
def article_details(article_id):
    article = Articles.find_one(id=article_id)
    return render_template("default/article-details.html", article=article)
コード例 #15
0
def index():
    articles = [dict(article) for article in Articles.all()]
    return render_template("default/index.html", articles=articles)
コード例 #16
0
def del_article(article_id):
    Articles.delete(id=article_id)
    return redirect("/admin/articles")