Save/fetch previous data. Better style. Unique IDs

This commit is contained in:
Sage Vaillancourt 2021-07-24 14:51:13 -04:00
parent 42c67985a6
commit 9a7787ef69
5 changed files with 130 additions and 30 deletions

View File

@ -6,11 +6,71 @@ body {
min-height: 90%; min-height: 90%;
text-size: 150%; text-size: 150%;
line-height: 200%; line-height: 200%;
width: 40vw;
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
font-family: sans;
}
/* Small screens */
@media only screen and (max-width: 1080px) {
body {
width: 95vw;
font-size: 200%;
}
h1 {
font-size: 400%;
}
h2 {
font-size: 300%;
line-height: 100%;
margin-top: 0;
margin-bottom: 0;
}
label {
font-size: 150%;
}
input {
font-size: 200%;
width: 100%;
}
form {
width: 90%;
}
dd {
margin-bottom: 2em;
margin-left: 0;
}
textarea {
width: 80vw;
font-size: 250%;
}
.bigtext {
min-height: 40vh;
}
}
/* Big screens */
@media only screen and (min-width: 1081px) {
body {
width: 40vw;
}
h1 {
font-size: 3em;
}
.content, .ret {
font-size: 1.2em;
}
img, small {
width: 30vw;
}
small {
font-size: 100%;
}
#closingtext {
width: 50%;
}
} }
form { form {
@ -30,7 +90,6 @@ dd {
} }
textarea { textarea {
width: 90%;
flex-grow: 1; flex-grow: 1;
} }
@ -41,7 +100,3 @@ textarea {
#body { #body {
flex-grow: 1; flex-grow: 1;
} }
#closingtext {
width: 50%;
}

View File

@ -1,5 +1,5 @@
{% macro render_field(field, extra="") %} {% macro render_field(field, extra="") %}
<dt>{{ field.label }}: <dt>{{ field.label }}
<dd {{extra}}>{{ field(**kwargs)|safe }} <dd {{extra}}>{{ field(**kwargs)|safe }}
{% if field.errors %} {% if field.errors %}
<ul class=errors> <ul class=errors>

View File

@ -3,6 +3,45 @@
<head> <head>
<link rel="stylesheet" type="text/css" href=" <link rel="stylesheet" type="text/css" href="
{{ url_for('static', filename='styles.css') }}"> {{ url_for('static', filename='styles.css') }}">
<meta name="viewport" content="user-scalable=no">
<script type="text/javascript">
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function loadCookies() {
console.log(document.cookie);
cookies = [
'username',
'company',
'jobandpronoun',
'skilltypes',
'myskills',
'closingtext',
'body',
]
for(let i = 0; i < cookies.length; i++) {
console.log(cookies[i]);
c = getCookie(cookies[i]);
console.log(c);
if (c) {
document.getElementById(cookies[i]).value=c
}
}
}
window.onload = loadCookies;
</script>
</head> </head>
<body> <body>
<h1>UnderCover</h1> <h1>UnderCover</h1>

View File

@ -36,8 +36,8 @@ def define(file, name, data, whitespace=""): file.write("\\def \\" + name + "{"
def generate(data: CLData, unique): def generate(data: CLData, unique):
proj_dir = os.path.dirname(os.getcwd()) + '/undercover/' proj_dir = os.path.dirname(os.getcwd()) + '/undercover/'
template_dir = os.path.dirname(os.getcwd()) + '/undercover/temp/' temp_dir = proj_dir + '/temp/'
unique_file = template_dir + unique + ".tex" unique_file = temp_dir + unique + ".tex"
f = open(unique_file, "w") f = open(unique_file, "w")
define(f, "username", data.username) define(f, "username", data.username)
define(f, "thecompany", data.company) define(f, "thecompany", data.company)
@ -49,9 +49,10 @@ def generate(data: CLData, unique):
f.write(open(proj_dir + "/writing_templates/base.tex", "r").read()) f.write(open(proj_dir + "/writing_templates/base.tex", "r").read())
f.close() f.close()
base_tex = template_dir + unique + ".tex" base_tex = temp_dir + unique + ".tex"
com = "pdflatex -jobname=outputs/" + unique + " " + base_tex com = "pdflatex -halt-on-error -jobname=outputs/" + unique + " " + base_tex
print("COM: '" + com + "'") print("COM: '" + com + "'")
#TODO: If error, don't try to return the pdf
subprocess.run(['bash', '-c', com]) subprocess.run(['bash', '-c', com])
root_dir = os.path.dirname(os.getcwd()) root_dir = os.path.dirname(os.getcwd())

View File

@ -9,47 +9,52 @@ from latty import (CLData, generate)
writing_blueprint = Blueprint('writing', __name__,) writing_blueprint = Blueprint('writing', __name__,)
class CLForm(Form): class CLForm(Form):
username = StringField('Username', username = StringField('Username:',
[validators.Length(min=4, max=99)], [validators.Length(min=4, max=99)],
default="Sage Bongos" default="Sage Bernerner"
) )
company = StringField('Company', company = StringField('Company:',
[validators.Length(min=4, max=99)], [validators.Length(min=4, max=99)],
default="BananaCorp" default="BananaCorp"
) )
jobandpronoun = StringField('Job and Pronoun', jobandpronoun = StringField('Job and Pronoun (a/an):',
[validators.Length(min=4, max=99)], [validators.Length(min=4, max=99)],
default="a banana stocker" default="a banana stocker"
) )
skilltypes = StringField('Skill Type', skilltypes = StringField('Skill Type:',
[validators.Length(min=4, max=99)], [validators.Length(min=4, max=99)],
default="practical" default="practical"
) )
myskills = StringField('My Skills', myskills = StringField('My Skills:',
[validators.Length(min=4, max=99)], [validators.Length(min=4, max=99)],
default="stocking bananas" default="stocking bananas"
) )
closingtext = StringField('Closing Text', closingtext = TextAreaField('Closing Text:',
[validators.Length(min=4, max=99)], [validators.Length(min=4, max=99)],
default="I am looking forward to hearing from you" default="I look forward to hearing from you"
) )
body = TextAreaField('Body',
body_string = ("My name is \\username. I would like to work as "
"\\jobandpronoun with your company. I think my \\skilltypes knowledge "
"of \\myskills will contribute well to your team.\n\n"
"I am passionate about my work, and think we would work well together.\n\n"
"Thank you for your consideration.")
body = TextAreaField('Body:',
[validators.Length(min=4, max=9999)], [validators.Length(min=4, max=9999)],
default=""" default=body_string
My name is \\username. I would like to work as \\jobandpronoun with your
company. I think my knowledge of \\myskills will contribute well to your
team.
I am passionate about my work, and think we would work well together.
Thank you for your consideration."""
) )
def get_unique(): def get_unique():
return "get_unique" import uuid
unique = str(uuid.uuid1().hex)[0:8]
print("Unique ID: " + unique)
return unique
@writing_blueprint.route('/', methods=('GET', 'POST')) @writing_blueprint.route('/', methods=('GET', 'POST'))
def index(): def index():
import urllib.parse
form = CLForm(request.form) form = CLForm(request.form)
if request.method == 'POST' and form.validate(): if request.method == 'POST' and form.validate():
data = CLData( data = CLData(
@ -65,7 +70,7 @@ def index():
resp = generate(data, get_unique()) resp = generate(data, get_unique())
# Save entered data as cookies on user's machine # Save entered data as cookies on user's machine
for pair in data.get_pairs(): for pair in data.get_pairs():
resp.set_cookie(pair[0], pair[1]) resp.set_cookie(pair[0], urllib.parse.quote(pair[1]))
return resp return resp
return render_template('writing.html', return render_template('writing.html',