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/'
|
||||
css = open(static_dir + 'styles.css', 'r').read()
|
||||
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')
|
||||
)))
|
||||
minified = re.sub( r'/\*[\s\S]*?\*/', "", minified_with_comments)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import bcrypt
|
||||
import os
|
||||
import psycopg2
|
||||
import psycopg
|
||||
from dataclasses import dataclass
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ class UserWithHash:
|
|||
|
||||
|
||||
def connect():
|
||||
return psycopg2.connect(
|
||||
return psycopg.connect(
|
||||
host=os.environ['UNDERCOVER_POSTGRES_HOST'],
|
||||
dbname=os.environ['UNDERCOVER_POSTGRES_DBNAME'],
|
||||
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]:
|
||||
with connect() as con:
|
||||
cur = con.cursor()
|
||||
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())
|
||||
cur.execute("SELECT id, letter_name, letter_data FROM letter_data WHERE user_id = %s", (str(user_id),))
|
||||
return list(map(lambda row: Letter(row[0], row[1], row[2]), cur.fetchall()))
|
||||
|
||||
|
||||
def get_user(email: str) -> User:
|
||||
|
|
|
@ -11,17 +11,20 @@ body {
|
|||
font-family: sans;
|
||||
}
|
||||
|
||||
h1, h2 {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Small screens */
|
||||
@media only screen and (max-width: 1080px) {
|
||||
body {
|
||||
width: 95vw;
|
||||
font-size: 200%;
|
||||
width: 85vw;
|
||||
}
|
||||
h1 {
|
||||
font-size: 400%;
|
||||
font-size: 300%;
|
||||
}
|
||||
h2 {
|
||||
font-size: 300%;
|
||||
font-size: 200%;
|
||||
line-height: 100%;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0.5em;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" type="text/css" href="
|
||||
{{ 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">
|
||||
function init() {
|
||||
{% if errors %}
|
||||
|
@ -21,38 +22,39 @@
|
|||
window.onload = init;
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>UnderCover</h1>
|
||||
<h2>The secret cover letter generator</h2>
|
||||
{% from "_formhelpers.html" import render_field %}
|
||||
<form method=post>
|
||||
<dl>
|
||||
{{ render_field(form.username) }}
|
||||
{{ render_field(form.company) }}
|
||||
{{ render_field(form.jobandpronoun) }}
|
||||
{{ render_field(form.skilltypes) }}
|
||||
{{ render_field(form.myskills) }}
|
||||
{{ render_field(form.body, 'class=bigtext') }}
|
||||
{{ render_field(form.closingtext) }}
|
||||
</dl>
|
||||
{% if errors %}
|
||||
<div id=errors>
|
||||
<h3>Your letter has errors.</h3>
|
||||
<p>There is likely a typo in one of your variables (the {\blabla} bits).
|
||||
<br>Make sure each is spelled correctly, and has the correct brackets on either
|
||||
side</p>
|
||||
<p class=errors>
|
||||
{% for error in errors %}
|
||||
{{ error }}<br>
|
||||
{% endfor %}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<input class=submit type=submit value="Submit"
|
||||
{% if errors %}
|
||||
onclick="var e = document.getElementById('errors'); e.parentNode.removeChild(e);"
|
||||
{% endif %}
|
||||
>
|
||||
</form>
|
||||
<h1>Under<wbr>Cover</h1>
|
||||
<h2>The secret cover letter generator</h2>
|
||||
{% from "_formhelpers.html" import render_field %}
|
||||
<form method=post>
|
||||
<dl>
|
||||
{{ render_field(form.username) }}
|
||||
{{ render_field(form.company) }}
|
||||
{{ render_field(form.jobandpronoun) }}
|
||||
{{ render_field(form.skilltypes) }}
|
||||
{{ render_field(form.myskills) }}
|
||||
{{ render_field(form.body, 'class=bigtext') }}
|
||||
{{ render_field(form.closingtext) }}
|
||||
</dl>
|
||||
{% if errors %}
|
||||
<div id=errors>
|
||||
<h3>Your letter has errors.</h3>
|
||||
<p>There is likely a typo in one of your variables (the {\blabla} bits).
|
||||
<br>Make sure each is spelled correctly, and has the correct brackets on either
|
||||
side</p>
|
||||
<p class=errors>
|
||||
{% for error in errors %}
|
||||
{{ error }}<br>
|
||||
{% endfor %}
|
||||
</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<input class=submit type=submit value="Submit"
|
||||
{% if errors %}
|
||||
onclick="var e = document.getElementById('errors'); e.parentNode.removeChild(e);"
|
||||
{% endif %}
|
||||
>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
2
latty.py
2
latty.py
|
@ -82,7 +82,7 @@ class CLData():
|
|||
return (send_from_directory(
|
||||
output_dir,
|
||||
output_file,
|
||||
attachment_filename=self.username.replace(" ", "") + "_CoverLetter.pdf",
|
||||
download_name=self.username.replace(" ", "") + "_CoverLetter.pdf",
|
||||
as_attachment=True
|
||||
), None)
|
||||
else:
|
||||
|
|
|
@ -9,4 +9,4 @@ Jinja2==3.1.2
|
|||
MarkupSafe==2.1.1
|
||||
psycopg==3.1.1
|
||||
Werkzeug==2.2.2
|
||||
WTForms==3.0.1
|
||||
WTForms==3.0.1
|
||||
|
|
2
start
2
start
|
@ -14,7 +14,7 @@ fi
|
|||
|
||||
if [[ "$1" == "prod" ]]; then
|
||||
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
|
||||
echo "Starting local dev server..."
|
||||
export FLASK_ENV=development
|
||||
|
|
19
writing.py
19
writing.py
|
@ -7,6 +7,7 @@ import urllib.parse
|
|||
from latty import CLData
|
||||
import flaskr
|
||||
import flaskr.db as db
|
||||
import os
|
||||
|
||||
|
||||
writing_blueprint = Blueprint('writing', __name__,)
|
||||
|
@ -71,8 +72,22 @@ def index_get():
|
|||
|
||||
|
||||
@writing_blueprint.route('/dbtest', methods=['GET'])
|
||||
def index_get():
|
||||
return db.get_user_letters(1)[0].contents
|
||||
def dbtest_get():
|
||||
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'])
|
||||
|
|
Loading…
Reference in New Issue