...
Note |
---|
The functionality of your own scripts cannot be guaranteed in future versions of Portrait. |
Environment
The Python Runtime we provide is a customized version of the official Python image. Specifically, we use python:3-alpine
as the base image. This means that the specific Python version is determined for each release of Portrait.
...
The container is connected to the same network as the other portrait services. So you are able to access the Portrait API as well as other APIs or web services.
Configuration
onSubmit with Python supports the following settings:
...
Info |
---|
There is a runtime limit of 15 seconds for the combination of setup script and python script. |
Setup Scripts
The setup script needs to be a shell script, which is called each time the form is submitted. The main purpose is to install additional dependencies through pip. The Portrait server will call this script without any parameters.
...
Note |
---|
The setup script and the main process runs in a different session. So changes that are not permanent (local env variables, pipenv shell, …) are not visible in the main script. Hence, virtual environments (like pipenv or pyenv) can’t be used currently. Therefore, all scripts share the same python installation. This might change in the future. |
Python Scripts
The python script will contain the actual business logic and will be executed after the setup script execution finished.
Preparation
The script will be called via the command line. You can expect the following inputs:
...
Code Block |
---|
python /app/scripts/demo.py --scriptExecutionID 0620f736-68a1-45e7-b411-f71cb7d6ab8c --files /app/fileparameter/0620f736-68a1-45e7-b411-f71cb7d6ab8c/94141861p1-1670253160678.png /app/fileparameter/0620f736-68a1-45e7-b411-f71cb7d6ab8c/101454734p0-1670253163775.jpg --args '{"responses":[{"values":["Akku Tausch"],"name":"Name"},{"values":["iPhone XR"],"name":"ModelCode"},{"values":["3 - High"],"name":"Priority"},{"values":["94141861p1-1670253160678.png","101454734p0-1670253163775.jpg"],"name":"Photos"},{"values":["CREATE"],"name":"portrait-action"},{"values":["2022-12-05T15:12:44.581Z"],"name":"portrait-timestamp"}]}' |
Your custom script
In the script, you could create a PDF, call a web service, or implement business logic to your needs.
...
After the script is called, the /app/fileparameter/0620f736-68a1-45e7-b411-f71cb7d6ab8c
folder is deleted.
Simple Example
Code Block |
---|
- id: createServiceCallPython onSubmit: type: Python setupScriptName: installDependencies.sh scriptName: demo.py dialog: |- { ... } |
...
Code Block |
---|
Total arguments passed: 7 Name of Python script: /app/scripts/demo.py Arguments passed: Arguments passed: --scriptExecutionID 6f8e6a90-f7ed-4a7c-b224-af84f23b1f10 --files /app/fileparameter/6f8e6a90-f7ed-4a7c-b224-af84f23b1f10/adobestock229193709-1684236862689.png --args {"responses":[{"values":["IssueText"],"name":"Name"},{"values":["ModellText"],"name":"ModelCode"},{"values":["3 - High"],"name":"Priority"},{"values":["adobestock229193709-1684236862689.png"],"name":"Photos"},{"values":["CREATE"],"name":"portrait-action"},{"values":["2023-05-16T11:34:23.478Z"],"name":"portrait-timestamp"},{"values":["xiaoNgRRPsqdclKyAvbZkaYmfGiosEYaSoiFSMkNGXFrSSOJAwUH"],"name":"PORTRAIT_USER_ID"},{"values":["Linda Jackson"],"name":"PORTRAIT_USER_NAME"},{"values":["linda.jackson@larsens.portraitapp.co"],"name":"PORTRAIT_USER_EMAIL"},{"values":["ADMIN"],"name":"PORTRAIT_USER_ROLE"}]} |
Example Use cases
Generate Invoice PDF
Code Block | ||
---|---|---|
| ||
- id: createBill onSubmit: type: Python scriptName: genInvoice.py setupScriptName: setupGenInvoice.sh dialog: |- { "title": "Rechnung erstellen", "successMessage": "Rechnung erstellt. Verfügbar in config/output in VSCode Web", "languageCodeSuccessMessage": "ON_SUBMIT_SUCCESS_MESSAGE", "errorMessage": "Fehler beim Hochladen des Formulars. Bitte versuche Sie es später erneut.", "languageCodeErrorMessage": "ON_SUBMIT_ERROR_MESSAGE", "submitText": "Speichern", "languageCodeSubmitText": "SUBMIT_NOW", "description": "Mit diesem Formular können Sie ihre Rechnungen erstellen", "pages": [ { "label":"Rechnung", "fields": [ { "name": "Name", "displayText": "Empfänger", "description": "Geben Sie den Rechnungsempfänger an", "languageCode": "MOD_TXT_LABEL_SUBJECT", "languageCodeDescription": "MOD_TXT_DESCRIPTION_PLEASE_ENTER_A_SUBJECT", "type": "Textbox", "defaultValue": "", "options": { "required": true, "inputMaskType": "simple" } } ] } ] } |
...