Added overview of the policy file and how to build a policy.

This commit is contained in:
kououken 2019-03-23 16:01:46 -07:00
parent 9011d3508e
commit 5c52903c20

View file

@ -73,12 +73,89 @@ Once the server is up and running, log in to `https://backendaddress.com:port/ad
Open the "Sites" view, and edit the one existing site's name to match your server name. This will be used in system emails. Open the "Sites" view, and edit the one existing site's name to match your server name. This will be used in system emails.
#### Policy File
The policy file, located at `back/backend/policy.py` is the heart of the application, defining the report sections, fields and rules which make up a reimbursement policy. You must build a policy file using these components in order to display the relevant text to your users, as well as collect the necessary data and give feedback based on rules.
##### Sections
The `Section` constructor is used to build a logical "section" of the report. A section corresponds to one idea or topic for which certain data should be collected, and certain rules applied. For example, to create a "Lodging" section, use the `Section` constructor with the following parameters:
- `title`: The title you wish to display for that section
- `html_description`: A string of html used to describe the section to the user. This should contain any necessary instructions or links to reference materials. Plain text should be wrapped in paragraph `<p></p>` tags.
- `fields`: This is a python object with one or more fields (see next section) defined.
Example python:
```
lodging_section = Section(
title="Hotel / Lodging",
html_description="<p>Please submit a receipt from your hotel including both the
total amount and the dates of your stay. Per diem rates can be found on <a href='htt
ps://www.gsa.gov/travel/plan-book/per-diem-rates' target='_blank'>the U.S. GSA websi
te</a>.</p>",
fields={
"per_diem_rate": {"number": 0, "label": "USGSA Per diem rate", "field_type":
"decimal"},
"cost": {"number": 1, "label": "Total cost for lodging", "field_type": "deci
mal"},
"check_in_date": {"number": 2, "label": "Check-in date", "field_type": "date
"},
"check_out_date": {"number": 3, "label": "Check-out date", "field_type": "da
te"},
"invoice_screenshot": {"number": 4, "label": "Screenshot of invoice", "field
_type": "file"},
}
)
```
A section can have any number of rules added to them. See the "Rules" section for more details.
Once a section is ready, add it to the policy file by calling:
```
pol.add_section(lodging_section)
```
Sections will be presented to the user in the order that they are added with this command.
##### Fields
Fields defined in the policy file for a section will appear as form fields in the application. When defined inside a Python object, they appear like this:
```
"per_diem_rate": {"number": 0, "label": "USGSA Per diem rate", "field_type": "decimal"},
```
- "per_diem_rate" becomes the key for this field, and is used to reference the field within rules for that section.
- "number" specifies the order in which the fields should be shown to the user.
- "label" is the text which will be displayed to the user for this field.
- "field_type" determines what type of data to get from the user. Depending on the type of field specified, the user will be prompted to fill in different types of information. The current supported types are:
- `boolean`: A true/false value. This is presented as "yes/no" to the user, and is useful to store the response to a yes/no question.
- `date`: An ISO date in YYYY-MM-DD format. The browser's native date picker should appear for this field
- `decimal`: A number with a whole part and fractional part up to two places. e.g. 10.50
- `integer`: An integer number. e.g. 10
- `file`: A generic file upload field. Currently this field can only hold one file at a time. To allow multiple file upload multiple fields should be provided.
- `string`: A string of unicode characters. e.g. "Portland"
##### Rules
Rules allow an administrator to validate the information entered by a user in a specific section and provide feedback messages if desired. Rules will be called with a dictionary of field values passed in via the `fields` parameter, and any string returned will be displayed to the user.
An example of a simple rule that checks the boolean value of the field named 'economy' to check if a user has purchased an economy class ticket would be as follows:
```
my_flight_section.add_rule(
title="Economy Check",
rule=lambda report, fields: "Only economy class tickets are allowed." if fields['economy'] else None
```
For more complex, multi-line rules, a temporary function may be defined and passed to the "rule" parameter when adding a rule. Currently, accessing fields from other sections via the "report" parameter is not supported.
### Admin Files ### Admin Files
In order to have CSS and JS working in the Django administrative pages, serve the contents of `admin/static` using the http server of your choice, and edit `back/reimbursinator/settings.py` to set the `STATIC_URL` address to the correct address to access these files. In order to have CSS and JS working in the Django administrative pages, serve the contents of `admin/static` using the http server of your choice, and edit `back/reimbursinator/settings.py` to set the `STATIC_URL` address to the correct address to access these files.
## Usage
## Tools, Libraries and Frameworks Used ## Tools, Libraries and Frameworks Used
The following are the versions used in development of Reimbursinator, and the versions pinned in `back/Pipfile`. The following are the versions used in development of Reimbursinator, and the versions pinned in `back/Pipfile`.