Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

MaxJohansen
Copy link
Contributor

@MaxJohansen MaxJohansen commented Jul 3, 2018

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 in templates.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 IRL

Previews

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 parameters height and width 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:

{
   "Employee" : {
      "signature" : true,
      "fields" : [
         {
            "name" : "Name"
         },
         {
            "name" : "Date"
         },
         {
            "name" : "Boss"
         }
      ]
   },
  [... more stuff here...]
}

and the Gavin Belson signature:

{
  {
    "id": "gavinbelson",
    "name": "Gavin Belson"
  },
  [... more stuff here...]
}

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

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>')

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.

{
"id": "waltdisney",
"name": "Walt Disney",
"description": "Old-timey nazi sympathizer"
Copy link

@IsakSundeSingh IsakSundeSingh Jul 4, 2018

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.
@MaxJohansen MaxJohansen force-pushed the feature/signatures-and-previews branch from 32a1380 to 182402c Compare July 4, 2018 09:18
@MaxJohansen MaxJohansen changed the title [WIP] Add support for signatures and previews Add support for signatures and previews Jul 4, 2018
@MaxJohansen MaxJohansen force-pushed the feature/signatures-and-previews branch from 155491a to 23d86b0 Compare July 4, 2018 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants