Pptx generation CRUD
Created by: john525
Definitions used in this PR: submission - save questionnaire results to database calculation - calculate criteria/scores and/or cost estimates, save to database report file generation - generates PPTX file from calculated scores (does not download the file, or move it anywhere). report record generation - creates a database record which saves the (local filesystem) path of the pptx presentation, and records the time at which the pptx was generated
Report generation endpoints do NOT download the report file. They just return a json response that tells you where you can find the file
This PR adds a view ReportView which performs report file generation and report record generation. This view implements "create" and "read" methods (e.g. POST and GET), which respectively allow you to
- create a report (report file and record generation) for a building by sending a POST request with a building ID (only works if the building already has questionnaire answers, scores/criteria/oppurtunities, and cost estimates saved in the database). Returns a "report ID" from the report record generation
- send a GET request with building ID, and get a JSON response containing the path to the most recently generated pptx file (inside the bloclink container)
To test:
- Checkout this branch in bloclink repository (DO NOT SKIP THIS STEP!!!) and checkout the branch "bloclink_improvements" in development (ALSO DO NOT SKIP THIS STEP!!!)
- Make sure your postgres container is named "postgres" (or postgresql, or something similar. any name is fine as long as it is consistent)
- Go inside the container (docker exec -it postgres psql -U postgres) and create a user blocpower (make sure this user has a password, even if it is just "password" -- otherwise bloclink will not be able to connect), a database "bloclink", and a database "eng", both owned by blocpower user:
-- Create user
create user blocpower with password ‘blocpower12345’ superuser login;
-- Create DBs
create database bloclink with owner=blocpower;
create database eng with owner=blocpower;
-
Make sure your bloclink .env file has a link to BLOCLINK_DB and ENGINEERING_DB that points to this postgres container (the hostname should be the container name from part 2, with username and password from part 3) 4b. Check your docker-compose.yml file in development. Bloclink dockerfile should be: "./microservices/bloclink/config/local/bloclink.Dockerfile" and it should also have a build arg "github_token: ${GITHUB_TOKEN}"
-
Destroy and rebuild bloclink container (
docker-compose rm -fs bloclink && docker-compose build bloclink && docker-compose up -d) to get latest bpengine (if that doesn't work, you can either try destroying and rebuilding with no cache, or you can pip install the latest bpengine version 0.7.1 from github and pip install django rest framework v3.10.2 inside the container to avoid the length rebuilding process) -
Bash inside the bloclink container, make and run the migrations for app "pna" (
python manage.py makemigrations pna && python manage.py migrate pna --database engineering_db) Then run psql inside your postgres container. Run the scripts from the pna branch of oltp that contain insert operations (these are the ones that populate our "possible_answer" tables and other tables that are generally fixed, do not run the scripts that actually create tables because django orm already did this) -
Now with the psql shell, create dummy building data, e.g. insert fake questionnaire submissions for the HVAC questions and insert fake scores into the score table, for some specific building ID (e.g. 1234)
-
Then run
curl -XPOST http://0.0.0.0:5410/buildings/1234/pna/generatepna/(on your host machine terminal) which should return a JSON response with a report ID -
Then open http://0.0.0.0:5410/buildings/1234/pna/generatepna/?report_id=XXX in your browser (replacing XXX with the ID you just got)
-
Then find the file at that path in your bloclink container, use docker cp to copy it to your host machine filesystem, and make sure the pptx looks accurate/correctly formatted
What we need to add moving forward: submission, calculation need to upload generated report file from container to S3, and return that link instead of a local path, so the user can download it