-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for signatures and previews #2
base: master
Are you sure you want to change the base?
Conversation
diploma.py
Outdated
faded_background = (255, 255, 255, 96) | ||
context.rectangle(bounding_box, outline=color, fill=faded_background) | ||
fontsize = 1 | ||
# Dirty hack to find the largest text we can fit in this box |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These dirty hacks aren't DRY
server.py
Outdated
return frontend_signatures_as_json() | ||
|
||
|
||
@app.route('/preview/<filename>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better if we have the preview paths for images and signatures separated?
E.g. Preview a template: /preview/template/<name>
and preview a signature: /preview/signature/<name>
.
This will make it more future-proof and we can more easily add support for previewing other things as well, without breaking changes to the API.
It also reduces the chance of a name conflict.
signatures/signatures.json
Outdated
{ | ||
"id": "waltdisney", | ||
"name": "Walt Disney", | ||
"description": "Old-timey nazi sympathizer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove these descriptions. They aren't even necessary.
Asking for templates/signatures json will now return the minimum amount of information that the frontend needs to know about.
32a1380
to
182402c
Compare
155491a
to
23d86b0
Compare
Signatures
Templates that take a signature (currently the
employee
template is the only one) can now accept an optional query parameter indicating which signature they wish to use. The signature is indicated by its name (e.g.gavinbelson
) and will be scaled and drawn onto the diploma in the position indicated intemplates.json
.To see which signatures are available you can use the
/signatures.json
endpoint.Example usage:
/employee?name=Joe&date=today&boss=Donald%20Trump&signature=donaldtrump
-> A diploma for Joe signed by the worlds most famous neo-nazi fascist scumbag./employee?name=Jane&date=01.01.1970&boss=Donald%20Knuth
-> A diploma for Jane with that needs to be signed by Donald Knuth IRLPreviews
To preview templates or images, you can use the new
/preview/<name>
endpoint, where indicates either a template name or a signature name. Template previews have boxes and text indicating where the field values will go. This endpoint also takes the optional query parametersheight
andwidth
to produce a "thumbnailed" version of the preview image which is nice if you only intend to render them in a list view on a tiny device anyway.Example usage:
/preview/template/employee
-> A full-sized version of the employee template decorated with boxes that indicate where the fields are./preview/template/employee?width=300
-> Same as above, but sized to fit into 300 pixels horizontally./preview/signature/waltdisney?width=200&height=80
-> Walt Disney's signature (black text on white background) resized to fit into a 200px by 80px rectangle.JSON structure
All of the JSON served is now in its most minimal form: the location of the fields is not (currently) relevant to the front end applications using this web API, so that information is stripped out. An example using the Employee template:
and the Gavin Belson signature: