Several fixes and improvements.
"Better" CSS minifying. Adjust psycopg imports and some usages. Fix viewport scaling for mobile. Switch gunicorn to default https port when running in prod. Correct /dbtest route and add simple /update skeleton
This commit is contained in:
parent
b5e892f57e
commit
0c07b5b0f2
|
@ -17,7 +17,7 @@ def optimize_css():
|
||||||
static_dir = root + '/undercover/flaskr/static/'
|
static_dir = root + '/undercover/flaskr/static/'
|
||||||
css = open(static_dir + 'styles.css', 'r').read()
|
css = open(static_dir + 'styles.css', 'r').read()
|
||||||
minified_with_comments = "".join(list(map(
|
minified_with_comments = "".join(list(map(
|
||||||
lambda line: line if 'media' in line else line.replace(' ', ''),
|
lambda line: line if 'media' in line or 'padding' in line or 'transition' in line else line.replace(' ', ''),
|
||||||
css.split('\n')
|
css.split('\n')
|
||||||
)))
|
)))
|
||||||
minified = re.sub( r'/\*[\s\S]*?\*/', "", minified_with_comments)
|
minified = re.sub( r'/\*[\s\S]*?\*/', "", minified_with_comments)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import bcrypt
|
import bcrypt
|
||||||
import os
|
import os
|
||||||
import psycopg2
|
import psycopg
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class UserWithHash:
|
||||||
|
|
||||||
|
|
||||||
def connect():
|
def connect():
|
||||||
return psycopg2.connect(
|
return psycopg.connect(
|
||||||
host=os.environ['UNDERCOVER_POSTGRES_HOST'],
|
host=os.environ['UNDERCOVER_POSTGRES_HOST'],
|
||||||
dbname=os.environ['UNDERCOVER_POSTGRES_DBNAME'],
|
dbname=os.environ['UNDERCOVER_POSTGRES_DBNAME'],
|
||||||
port=os.environ['UNDERCOVER_POSTGRES_PORT'],
|
port=os.environ['UNDERCOVER_POSTGRES_PORT'],
|
||||||
|
@ -90,8 +90,8 @@ def edit_letter(letter_id: int, letter_title: str, letter_content: str):
|
||||||
def get_user_letters(user_id: int) -> [Letter]:
|
def get_user_letters(user_id: int) -> [Letter]:
|
||||||
with connect() as con:
|
with connect() as con:
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
cur.execute("SELECT id, letter_name, letter_data FROM letter_data WHERE user_id = %s", str(user_id))
|
cur.execute("SELECT id, letter_name, letter_data FROM letter_data WHERE user_id = %s", (str(user_id),))
|
||||||
return map(lambda row: Letter(row[0], row[1], row[2]), cur.fetchall())
|
return list(map(lambda row: Letter(row[0], row[1], row[2]), cur.fetchall()))
|
||||||
|
|
||||||
|
|
||||||
def get_user(email: str) -> User:
|
def get_user(email: str) -> User:
|
||||||
|
|
|
@ -11,17 +11,20 @@ body {
|
||||||
font-family: sans;
|
font-family: sans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h1, h2 {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
/* Small screens */
|
/* Small screens */
|
||||||
@media only screen and (max-width: 1080px) {
|
@media only screen and (max-width: 1080px) {
|
||||||
body {
|
body {
|
||||||
width: 95vw;
|
width: 85vw;
|
||||||
font-size: 200%;
|
|
||||||
}
|
}
|
||||||
h1 {
|
h1 {
|
||||||
font-size: 400%;
|
font-size: 300%;
|
||||||
}
|
}
|
||||||
h2 {
|
h2 {
|
||||||
font-size: 300%;
|
font-size: 200%;
|
||||||
line-height: 100%;
|
line-height: 100%;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
margin-bottom: 0.5em;
|
margin-bottom: 0.5em;
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" type="text/css" href="
|
<link rel="stylesheet" type="text/css" href="
|
||||||
{{ url_for('static', filename='styles_min.css') }}">
|
{{ url_for('static', filename='styles_min.css') }}">
|
||||||
<meta name="viewport" content="user-scalable=no">
|
<meta name="viewport" content="user-scalable=no;width=device-width">
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function init() {
|
function init() {
|
||||||
{% if errors %}
|
{% if errors %}
|
||||||
|
@ -21,11 +22,12 @@
|
||||||
window.onload = init;
|
window.onload = init;
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>UnderCover</h1>
|
<h1>Under<wbr>Cover</h1>
|
||||||
<h2>The secret cover letter generator</h2>
|
<h2>The secret cover letter generator</h2>
|
||||||
{% from "_formhelpers.html" import render_field %}
|
{% from "_formhelpers.html" import render_field %}
|
||||||
<form method=post>
|
<form method=post>
|
||||||
<dl>
|
<dl>
|
||||||
{{ render_field(form.username) }}
|
{{ render_field(form.username) }}
|
||||||
{{ render_field(form.company) }}
|
{{ render_field(form.company) }}
|
||||||
|
@ -53,6 +55,6 @@
|
||||||
onclick="var e = document.getElementById('errors'); e.parentNode.removeChild(e);"
|
onclick="var e = document.getElementById('errors'); e.parentNode.removeChild(e);"
|
||||||
{% endif %}
|
{% endif %}
|
||||||
>
|
>
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
2
latty.py
2
latty.py
|
@ -82,7 +82,7 @@ class CLData():
|
||||||
return (send_from_directory(
|
return (send_from_directory(
|
||||||
output_dir,
|
output_dir,
|
||||||
output_file,
|
output_file,
|
||||||
attachment_filename=self.username.replace(" ", "") + "_CoverLetter.pdf",
|
download_name=self.username.replace(" ", "") + "_CoverLetter.pdf",
|
||||||
as_attachment=True
|
as_attachment=True
|
||||||
), None)
|
), None)
|
||||||
else:
|
else:
|
||||||
|
|
2
start
2
start
|
@ -14,7 +14,7 @@ fi
|
||||||
|
|
||||||
if [[ "$1" == "prod" ]]; then
|
if [[ "$1" == "prod" ]]; then
|
||||||
echo "Starting gunicorn production server..."
|
echo "Starting gunicorn production server..."
|
||||||
gunicorn -b 0.0.0.0:1312 "flaskr:create_app()"
|
gunicorn -b 0.0.0.0:443 "flaskr:create_app()"
|
||||||
else
|
else
|
||||||
echo "Starting local dev server..."
|
echo "Starting local dev server..."
|
||||||
export FLASK_ENV=development
|
export FLASK_ENV=development
|
||||||
|
|
19
writing.py
19
writing.py
|
@ -7,6 +7,7 @@ import urllib.parse
|
||||||
from latty import CLData
|
from latty import CLData
|
||||||
import flaskr
|
import flaskr
|
||||||
import flaskr.db as db
|
import flaskr.db as db
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
writing_blueprint = Blueprint('writing', __name__,)
|
writing_blueprint = Blueprint('writing', __name__,)
|
||||||
|
@ -71,8 +72,22 @@ def index_get():
|
||||||
|
|
||||||
|
|
||||||
@writing_blueprint.route('/dbtest', methods=['GET'])
|
@writing_blueprint.route('/dbtest', methods=['GET'])
|
||||||
def index_get():
|
def dbtest_get():
|
||||||
return db.get_user_letters(1)[0].contents
|
response = make_response(db.get_user_letters(1)[0].contents, 200)
|
||||||
|
response.mimetype = "text/plain"
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@writing_blueprint.route('/update', methods=['POST'])
|
||||||
|
def update_get():
|
||||||
|
if os.environ['GITLAB_HOOK_TOKEN'] == request.headers['X-Gitlab-Token'] and request.headers['X-Gitlab-Event'] == "Push Hook":
|
||||||
|
print("Update notification received.")
|
||||||
|
# TODO: Git clone
|
||||||
|
response = make_response("", 200)
|
||||||
|
response.mimetype = "text/plain"
|
||||||
|
return response
|
||||||
|
else:
|
||||||
|
return make_response("", 404)
|
||||||
|
|
||||||
|
|
||||||
@writing_blueprint.route('/', methods=['POST'])
|
@writing_blueprint.route('/', methods=['POST'])
|
||||||
|
|
Loading…
Reference in New Issue