Beispiel #1
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)
Beispiel #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)
Beispiel #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("/")
Beispiel #4
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)
Beispiel #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)
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/',
Beispiel #7
0
def articlesAdmin():
	lista = [dict(article) for article in Articles.all()]
	return render_template("admin/articles/index.html", articles = lista )
Beispiel #8
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)
Beispiel #9
0
def article_details(article_id):
	article = Articles.find_one(id=article_id)
	return render_template("default/article-details.html", article=article)
Beispiel #10
0
def index():
	articles = [dict(article) for article in Articles.all()]
	return render_template("default/index.html", articles= articles)
Beispiel #11
0
def del_article(article_id):
	Articles.delete(id=article_id)
	return redirect("/admin/articles")
Beispiel #12
0
def articlesAdmin():
    lista = [dict(article) for article in Articles.all()]
    return render_template("admin/articles/index.html", articles=lista)
Beispiel #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)
Beispiel #14
0
def article_details(article_id):
    article = Articles.find_one(id=article_id)
    return render_template("default/article-details.html", article=article)
Beispiel #15
0
def index():
    articles = [dict(article) for article in Articles.all()]
    return render_template("default/index.html", articles=articles)
Beispiel #16
0
def del_article(article_id):
    Articles.delete(id=article_id)
    return redirect("/admin/articles")