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-23 23:09:08 -04:00
|
|
|
from latty import (CLData, generate)
|
|
|
|
|
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-24 14:51:13 -04:00
|
|
|
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"
|
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-23 23:09:08 -04:00
|
|
|
def get_unique():
|
2021-07-24 14:51:13 -04:00
|
|
|
import uuid
|
2021-07-24 15:25:58 -04:00
|
|
|
unique = str(uuid.uuid1().hex)
|
2021-07-24 14:51:13 -04:00
|
|
|
print("Unique ID: " + unique)
|
|
|
|
return unique
|
2021-07-23 23:09:08 -04:00
|
|
|
|
2021-07-23 17:30:15 -04:00
|
|
|
@writing_blueprint.route('/', methods=('GET', 'POST'))
|
|
|
|
def index():
|
2021-07-24 14:51:13 -04:00
|
|
|
import urllib.parse
|
2021-07-23 17:30:15 -04:00
|
|
|
form = CLForm(request.form)
|
|
|
|
if request.method == 'POST' and 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-24 00:26:44 -04:00
|
|
|
resp = generate(data, get_unique())
|
|
|
|
# Save entered data as cookies on user's machine
|
2021-07-24 15:44:24 -04:00
|
|
|
if not resp:
|
|
|
|
resp = make_response(render_template('writing.html',
|
|
|
|
form=form,
|
|
|
|
unique=get_unique(),
|
|
|
|
))
|
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,
|
2021-07-23 23:09:08 -04:00
|
|
|
unique=get_unique(),
|
2021-07-23 17:30:15 -04:00
|
|
|
)
|