2021-07-23 17:30:15 -04:00
|
|
|
# Copyright Sage Vaillancourt 2021
|
|
|
|
|
2021-07-24 15:44:24 -04:00
|
|
|
from flask import (Blueprint, render_template, request, make_response)
|
2021-07-23 17:30:15 -04:00
|
|
|
from wtforms import Form, BooleanField, StringField, TextAreaField, validators
|
2021-07-25 14:59:01 -04:00
|
|
|
import urllib.parse
|
2021-07-23 17:30:15 -04:00
|
|
|
|
2021-07-27 23:03:03 -04:00
|
|
|
from latty import CLData
|
2021-07-31 23:14:59 -04:00
|
|
|
import flaskr
|
2021-07-23 23:09:08 -04:00
|
|
|
|
2021-07-23 17:30:15 -04:00
|
|
|
|
|
|
|
writing_blueprint = Blueprint('writing', __name__,)
|
|
|
|
|
|
|
|
class CLForm(Form):
|
2021-07-24 14:51:13 -04:00
|
|
|
username = StringField('Username:',
|
2021-07-23 17:30:15 -04:00
|
|
|
[validators.Length(min=4, max=99)],
|
2021-07-24 14:51:13 -04:00
|
|
|
default="Sage Bernerner"
|
2021-07-23 17:30:15 -04:00
|
|
|
)
|
2021-07-24 14:51:13 -04:00
|
|
|
company = StringField('Company:',
|
2021-07-23 17:30:15 -04:00
|
|
|
[validators.Length(min=4, max=99)],
|
|
|
|
default="BananaCorp"
|
|
|
|
)
|
2021-07-24 14:51:13 -04:00
|
|
|
jobandpronoun = StringField('Job and Pronoun (a/an):',
|
2021-07-23 17:30:15 -04:00
|
|
|
[validators.Length(min=4, max=99)],
|
2021-07-24 01:08:18 -04:00
|
|
|
default="a banana stocker"
|
2021-07-23 17:30:15 -04:00
|
|
|
)
|
2021-07-24 14:51:13 -04:00
|
|
|
skilltypes = StringField('Skill Type:',
|
2021-07-23 17:30:15 -04:00
|
|
|
[validators.Length(min=4, max=99)],
|
|
|
|
default="practical"
|
|
|
|
)
|
2021-07-24 14:51:13 -04:00
|
|
|
myskills = StringField('My Skills:',
|
2021-07-23 17:30:15 -04:00
|
|
|
[validators.Length(min=4, max=99)],
|
2021-07-24 01:08:18 -04:00
|
|
|
default="stocking bananas"
|
2021-07-23 17:30:15 -04:00
|
|
|
)
|
2021-07-24 14:51:13 -04:00
|
|
|
closingtext = TextAreaField('Closing Text:',
|
2021-07-23 17:30:15 -04:00
|
|
|
[validators.Length(min=4, max=99)],
|
2021-07-24 14:51:13 -04:00
|
|
|
default="I look forward to hearing from you"
|
2021-07-23 17:30:15 -04:00
|
|
|
)
|
|
|
|
|
2021-07-28 22:04:24 -04:00
|
|
|
body_string = ("My name is {\\username}. I would like to work as "
|
2021-07-25 14:59:01 -04:00
|
|
|
"{\\jobandpronoun} with your company. I think my {\\skilltypes} knowledge "
|
|
|
|
"of {\\myskills} can contribute a lot to your team.\n\n"
|
2021-07-24 14:51:13 -04:00
|
|
|
|
2021-07-25 14:59:01 -04:00
|
|
|
"I am passionate about what I do, and I think we would work well together.\n\n"
|
2021-07-23 17:30:15 -04:00
|
|
|
|
2021-07-24 14:51:13 -04:00
|
|
|
"Thank you for your consideration.")
|
|
|
|
body = TextAreaField('Body:',
|
|
|
|
[validators.Length(min=4, max=9999)],
|
|
|
|
default=body_string
|
2021-07-23 17:30:15 -04:00
|
|
|
)
|
|
|
|
|
2021-07-31 23:14:59 -04:00
|
|
|
@writing_blueprint.route('/', methods=['GET'])
|
|
|
|
def index_get():
|
|
|
|
if flaskr.INDEX == None:
|
|
|
|
flaskr.INDEX = render_template(
|
|
|
|
'writing.html',
|
|
|
|
form=CLForm()
|
|
|
|
)
|
|
|
|
return flaskr.INDEX
|
|
|
|
|
|
|
|
@writing_blueprint.route('/', methods=['POST'])
|
|
|
|
def index_post():
|
2021-07-23 17:30:15 -04:00
|
|
|
form = CLForm(request.form)
|
2021-07-31 23:14:59 -04:00
|
|
|
if form.validate():
|
2021-07-23 23:09:08 -04:00
|
|
|
data = CLData(
|
|
|
|
username=form.username.data,
|
|
|
|
company=form.company.data,
|
|
|
|
jobandpronoun=form.jobandpronoun.data,
|
|
|
|
skilltypes=form.skilltypes.data,
|
|
|
|
myskills=form.myskills.data,
|
|
|
|
closingtext=form.closingtext.data,
|
|
|
|
body=form.body.data,
|
|
|
|
)
|
2021-07-23 17:30:15 -04:00
|
|
|
|
2021-07-28 18:43:19 -04:00
|
|
|
(resp, errors) = data.generate_pdf()
|
|
|
|
if errors:
|
2021-07-24 15:44:24 -04:00
|
|
|
resp = make_response(render_template('writing.html',
|
|
|
|
form=form,
|
2021-07-28 18:43:19 -04:00
|
|
|
errors=errors,
|
2021-07-24 15:44:24 -04:00
|
|
|
))
|
2021-07-28 19:21:02 -04:00
|
|
|
# Save entered data as cookies on user's machine
|
2021-07-24 00:26:44 -04:00
|
|
|
for pair in data.get_pairs():
|
2021-07-24 14:51:13 -04:00
|
|
|
resp.set_cookie(pair[0], urllib.parse.quote(pair[1]))
|
2021-07-24 00:26:44 -04:00
|
|
|
return resp
|
|
|
|
|
2021-07-23 17:30:15 -04:00
|
|
|
return render_template('writing.html',
|
|
|
|
form=form,
|
|
|
|
)
|