Skip to content

Commit

Permalink
Merge pull request #7 from zxpower/update_reqs_20241114
Browse files Browse the repository at this point in the history
Update requirments + some small things
  • Loading branch information
zxpower authored Nov 14, 2024
2 parents c72f1c2 + b27f0ae commit d36c6a3
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 70 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg

3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.10-slim-bullseye
FROM python:3.11-slim-bookworm

RUN mkdir /app; chown -R 1000:1000 /app;
WORKDIR /app
Expand Down Expand Up @@ -34,4 +34,3 @@ EXPOSE 8080
USER 1000

CMD ["./start.sh"]

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Updated version of blog app Flaskr from Python tiny MVC framework [Flask tutorial](http://flask.pocoo.org/docs/tutorial/)

_by [digiBlink](http://digiblink.eu/)_
_by [digiBlink](https://digiblink.eu/)_

## Installation

Expand Down
1 change: 0 additions & 1 deletion buildImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
set -eu

docker build --no-cache -t reflaskr .

14 changes: 7 additions & 7 deletions configs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
click==8.1.6
Flask==2.3.2
itsdangerous==2.1.2
Jinja2==3.1.3
MarkupSafe==2.1.3
uWSGI==2.0.22
Werkzeug==2.3.6
click==8.1.7
Flask==3.1.0
itsdangerous==2.2.0
Jinja2==3.1.4
MarkupSafe==3.0.2
uWSGI==2.0.28
Werkzeug==3.1.3
1 change: 0 additions & 1 deletion configs/uwsgi.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ chmod-sock = 664
vacuum = true

die-on-term = true

88 changes: 44 additions & 44 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# --------
# Minimal blog engine based on Python's Flask Tutorial
# http://flask.pocoo.org/docs/tutorial/
#
#
# Created by: digiBlink - http://digibling.eu/
###################################################################

Expand All @@ -12,22 +12,22 @@
from sqlite3 import dbapi2 as sqlite3
from contextlib import closing
from flask import Flask, request, session, g, redirect, url_for, \
abort, render_template, flash
abort, render_template, flash

# create our little application :)
app = Flask(__name__)
app.config.from_pyfile('app.cfg')

# let's connect to DB
def connect_db():
return sqlite3.connect(app.config['DATABASE'])
return sqlite3.connect(app.config['DATABASE'])

# let's initialize it if it's not already done
def init_db():
with closing(connect_db()) as db:
with app.open_resource('schema.sql') as f:
db.cursor().executescript(f.read())
db.commit()
with closing(connect_db()) as db:
with app.open_resource('schema.sql') as f:
db.cursor().executescript(f.read())
db.commit()

def query_db(query, args=(), one=False):
cur = g.db.execute(query, args)
Expand All @@ -37,66 +37,66 @@ def query_db(query, args=(), one=False):

@app.before_request
def before_request():
g.db = connect_db()
g.db = connect_db()

@app.teardown_request
def teardown_request(exception):
g.db.close()
g.db.close()

@app.route('/')
def show_entries():
cur = g.db.execute('select id, title, text from entries order by id desc')
entries = [dict(id=row[0], title=row[1], text=row[2]) for row in cur.fetchall()]
return render_template('show_entries.html', entries=entries)
cur = g.db.execute('select id, title, text from entries order by id desc')
entries = [dict(id=row[0], title=row[1], text=row[2]) for row in cur.fetchall()]
return render_template('show_entries.html', entries=entries)

@app.route('/add', methods=['POST'])
def add_entry():
if not session.get('logged_in'):
abort(401)
g.db.execute('insert into entries (title, text) values (?, ?)',
[request.form['title'], request.form['text']])
g.db.commit()
flash('New entry was successfully posted')
return redirect(url_for('show_entries'))
if not session.get('logged_in'):
abort(401)
g.db.execute('insert into entries (title, text) values (?, ?)',
[request.form['title'], request.form['text']])
g.db.commit()
flash('New entry was successfully posted')
return redirect(url_for('show_entries'))

@app.route('/edit/<int:articleid>', methods=['GET', 'POST'])
def edit_entry(articleid):
if not session.get('logged_in'):
abort(401)
entry = query_db('select * from entries where id = ?', [articleid], one=True)
return render_template('show_entries.html', entries=entry)
if not session.get('logged_in'):
abort(401)
entry = query_db('select * from entries where id = ?', [articleid], one=True)
return render_template('show_entries.html', entries=entry)

@app.route('/delete/<int:articleid>', methods=['GET', 'POST'])
def delete_entry(articleid):
if not session.get('logged_in'):
abort(401)
g.db.execute('delete from entries where id = ?', [articleid])
g.db.commit()
return str(articleid)
if not session.get('logged_in'):
abort(401)
g.db.execute('delete from entries where id = ?', [articleid])
g.db.commit()
return str(articleid)

@app.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != app.config['USERNAME']:
error = 'Invalid username'
elif request.form['password'] != app.config['PASSWORD']:
error = 'Invalid password'
else:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('show_entries'))
return render_template('login.html', error=error)
error = None
if request.method == 'POST':
if request.form['username'] != app.config['USERNAME']:
error = 'Invalid username'
elif request.form['password'] != app.config['PASSWORD']:
error = 'Invalid password'
else:
session['logged_in'] = True
flash('You were logged in')
return redirect(url_for('show_entries'))
return render_template('login.html', error=error)

@app.route('/logout')
def logout():
session.pop('logged_in', None)
flash('You were logged out')
return redirect(url_for('show_entries'))
session.pop('logged_in', None)
flash('You were logged out')
return redirect(url_for('show_entries'))

@app.errorhandler(404)
def page_not_found(error):
return render_template('page_not_found.html'), 404

if __name__ == '__main__':
app.run()
app.run()
2 changes: 1 addition & 1 deletion src/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ create table entries (
id integer primary key autoincrement,
title string not null,
text string not null
);
);
17 changes: 8 additions & 9 deletions src/static/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ function postToURL(url, values)
values = values || {};

$.post(url, values, function(e){
$('ul').find('#article_'+e).remove();
if( $('div.flash').length == 0 ) {
$( 'div.notice' ).append( '<div class="flash"></div>' );
}
$( 'div.flash' ).text( 'Article with ID:' + e + ' was deleted succesfully!' );
if( $( 'ul' ).children().length == 0 ) {
$( 'ul' ).append( '<li><em>Unbelievable. No entries here so far!</em></li>' );
}
$('ul').find('#article_'+e).remove();
if( $('div.flash').length == 0 ) {
$( 'div.notice' ).append( '<div class="flash"></div>' );
}
$( 'div.flash' ).text( 'Article with ID:' + e + ' was deleted succesfully!' );
if( $( 'ul' ).children().length == 0 ) {
$( 'ul' ).append( '<li><em>Unbelievable. No entries here so far!</em></li>' );
}
})

}

function confirmation(question, location, post, values)
Expand Down
2 changes: 1 addition & 1 deletion src/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ h2 { font-size: 1.2em; }
.flash { background: #CEE5F5; padding: 0.5em;
border: 1px solid #AACBE2; }
.error { background: #F0D6D6; padding: 0.5em; }
.actions { font-size: 0.8em; border: 1px solid #eee; padding: 2px; background-color: #eee; }
.actions { font-size: 0.8em; border: 1px solid #eee; padding: 2px; background-color: #eee; }
2 changes: 1 addition & 1 deletion src/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ <h2>Login</h2>
<dd><input type=submit value=Login>
</dl>
</form>
{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion src/templates/page_not_found.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "layout.html" %}
{% block body %}
<div>Ups, page not found...</div>
{% endblock %}
{% endblock %}
Empty file modified start.sh
100644 → 100755
Empty file.

0 comments on commit d36c6a3

Please sign in to comment.