Better styling, variable syntax, and cookies

Adjusted text sizes on mobile. New default variable syntax makes for more
consistent whitespace (allowing for simpler internal code). JS won't load
cookies if the company name is unchanged from the default.
This commit is contained in:
Sage Vaillancourt 2021-07-25 14:59:01 -04:00
parent 1ad6f56e14
commit 3cdbfdcb04
4 changed files with 22 additions and 25 deletions

View File

@ -44,11 +44,10 @@ body {
} }
textarea { textarea {
width: 80vw; width: 80vw;
font-size: 250%; font-size: 200%;
} }
.bigtext { .bigtext {
min-height: 40vh; min-height: 40vh;
font-size: 80%;
} }
} }

View File

@ -21,6 +21,9 @@
return ""; return "";
} }
function loadCookies() { function loadCookies() {
if (document.getElementById('company').value === "BananaCorp") {
return
}
console.log(document.cookie); console.log(document.cookie);
cookies = [ cookies = [
'username', 'username',

View File

@ -27,21 +27,24 @@ class CLData():
("body", self.body), ("body", self.body),
] ]
def define(file, name, data, whitespace=""): file.write("\\def \\" + name + "{" + data + whitespace + "}\n") def define(file, name, data, whitespace=""):
file.write("\\def \\" + name + "{" + data + whitespace + "}\n")
def generate(data: CLData, unique): def get_unique():
import uuid
unique = str(uuid.uuid1().hex)
print("Unique ID: " + unique)
return unique
def generate(data: CLData):
import threading import threading
unique = get_unique()
proj_dir = os.path.dirname(os.getcwd()) + '/undercover/' proj_dir = os.path.dirname(os.getcwd()) + '/undercover/'
output_dir = proj_dir + 'outputs/' output_dir = proj_dir + 'outputs/'
unique_file = output_dir + unique + ".tex" unique_file = output_dir + unique + ".tex"
f = open(unique_file, "w") f = open(unique_file, "w")
define(f, "username", data.username) for pair in data.get_pairs():
define(f, "thecompany", data.company) file.write("\\def \\" + pair[0] + "{" + pair[0] + "}\n")
define(f, "jobandpronoun", data.jobandpronoun, " ")
define(f, "skilltypes", data.skilltypes, " ")
define(f, "myskills", data.myskills, " ")
define(f, "closingtext", data.closingtext)
define(f, "body", data.body)
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()

View File

@ -2,6 +2,7 @@
from flask import (Blueprint, render_template, request, make_response) from flask import (Blueprint, render_template, request, make_response)
from wtforms import Form, BooleanField, StringField, TextAreaField, validators from wtforms import Form, BooleanField, StringField, TextAreaField, validators
import urllib.parse
from latty import (CLData, generate) from latty import (CLData, generate)
@ -34,11 +35,11 @@ class CLForm(Form):
default="I look forward to hearing from you" default="I look forward to hearing from you"
) )
body_string = ("My name is \\username. I would like to work as " body_string = ("My name is {\\username}. I would like to work as "
"\\jobandpronoun with your company. I think my \\skilltypes knowledge " "{\\jobandpronoun} with your company. I think my {\\skilltypes} knowledge "
"of \\myskills will contribute well to your team.\n\n" "of {\\myskills} can contribute a lot to your team.\n\n"
"I am passionate about my work, and think we would work well together.\n\n" "I am passionate about what I do, and I think we would work well together.\n\n"
"Thank you for your consideration.") "Thank you for your consideration.")
body = TextAreaField('Body:', body = TextAreaField('Body:',
@ -46,15 +47,8 @@ class CLForm(Form):
default=body_string default=body_string
) )
def get_unique():
import uuid
unique = str(uuid.uuid1().hex)
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(
@ -67,12 +61,11 @@ def index():
body=form.body.data, body=form.body.data,
) )
resp = generate(data, get_unique()) resp = generate(data)
# Save entered data as cookies on user's machine # Save entered data as cookies on user's machine
if not resp: if not resp:
resp = make_response(render_template('writing.html', resp = make_response(render_template('writing.html',
form=form, form=form,
unique=get_unique(),
)) ))
for pair in data.get_pairs(): for pair in data.get_pairs():
resp.set_cookie(pair[0], urllib.parse.quote(pair[1])) resp.set_cookie(pair[0], urllib.parse.quote(pair[1]))
@ -80,5 +73,4 @@ def index():
return render_template('writing.html', return render_template('writing.html',
form=form, form=form,
unique=get_unique(),
) )