Assignment 4: Creating a document
Photo by Cytonn Photography on Unsplash
Something from Nothing: Assembling Your First Documents with Docassemble
We have already explored ways to show text to the user, from our very first Hello, World exercise.
We can create documents using the same method. We need to learn about a new
attachment specifier. You can read more about
attachments here, or check out the official documentation.
Let's demonstrate a simple interview that assembles a Hello, World document.
We'll use a few new specifiers: the
attachment specifier, and a few options that fall underneath it to control the name and content of the document we create.
As a best practice, let's continue to use an object whenever we collect information about a person. Check out Assignment 2 if you need to refresh your memory.
- client: Individual
This block controls the order of questions in the interview
What is your name?
- First: client.name.first
- Last: client.name.last
As a reminder, an event specifier is used for an ending screen.
Your file is ready
name: Hello World
Let's take a closer look our sample interview. As a reminder, instead of a standard variable name, we're using an Individual object to store the information about our user. We use the
objects block to create our
The only new feature of our interview comes in the
attachment specifier at the end. Notice we have three options indented below the
name: A descriptive name that is shown by Docassemble on the screen
filename: The filename that the user will download (we don't need to include .pdf or .rtf)
content: the actual text that the document will contain, which can include Mako + Markdown. If we click the "preview" link, we can see a preview of the attachment.
Here's how those options will appear on the screen:
Docassemble also offers us an option to email the completed document.
Putting it into practice
Amnesty International uses international letter writing and other pressure campaigns to get governments around the world to release "prisoners of conscience". Let's write a tool that might help someone write letters more efficiently.
Our letter will request the release of Dr. Martin Luther King, Jr. from the Birmingham jail.
In addition to the
attachment specifier, we introduce two new kinds of screens:
- An information screen with a continue button, which uses the specifier
- A signature screen, which uses the specifier
Let's start with some working code. We'll modify this to improve it.
- user: Individual
Using an introduction screen is a good idea. It helps your
user understand what the tool can and cannot do.
Use the specifier field for a screen that doesn't do anything
except display a continue button.
Letter writing tool
This tool will help you send a letter to request the release of Dr. Martin Luther King, Jr. He was arrested in August 1963 during non-violent demonstrations against segregation in the city of Birmingham, Alabama.
At the end, we'll ask you sign the letter, print it, and mail it to the city prosecutor's office.
continue button field: introduction
What is your name
- no label: user.name.first
input type: area lets you collect more than one line of text
Add a custom paragraph
- no label: custom_paragraph
input type: area
Your letter is ready to download and print
Print the letter below. Mail it to the Birmingham prosecutor
name: Letter to the Birmingham Jail
Birmingham City Prosecutor
## The charges against Martin Luther King Jr. must be dropped
I am writing to you concerning the prosecution of Martin Luther King Jr., who is currently incarcerated in the Birmingham Jail.
Dr. King was arrested as a non-violent participant in protests against segregation. His arrest is unfair and in violation of international law.
In conclusion, I ask you to immediately release Dr. King.
- Change the file name of the letter to be more descriptive
- Add a yes/no question to the interview that prompts the user about whether they live in Alabama. Look back at assignment 3 for one way to add a yes/no question using the
fieldsspecifier. You could also use yes/no buttons.
- Add an optional paragraph using
% if ...:and
% endiftags that only displays if they live in Alabama. For example, it might say "As an Alabama resident, I am disappointed..." You may want to review the section in Mako on conditional text. We also used conditional text in Assignment 1.
Turning in your work
Download the final YAML file and copy the link to run your interview. Upload to Blackboard.