Use named code blocks throughout documentation

This commit is contained in:
Christopher C. Wells 2022-05-28 13:47:48 -07:00
parent f95edd8957
commit e4345b03e7
5 changed files with 234 additions and 158 deletions

View File

@ -61,13 +61,18 @@ The `limit` and `offset` request parameters can be used to limit
and offset the results set respectively. For example, the following request and offset the results set respectively. For example, the following request
will return five diaper changes starting from the 10th diaper change entry: will return five diaper changes starting from the 10th diaper change entry:
```shell
curl -X GET 'https://[...]/api/changes/?limit=5&offset=10' -H 'Authorization: Token [...]' curl -X GET 'https://[...]/api/changes/?limit=5&offset=10' -H 'Authorization: Token [...]'
```
```json
{ {
"count": <int>, "count": 20,
"next": "https://[...]/api/changes/?limit=5&offset=15", "next": "https://[...]/api/changes/?limit=5&offset=15",
"previous": "https://[...]/api/changes/?limit=5&offset=5", "previous": "https://[...]/api/changes/?limit=5&offset=5",
"results": [...] "results": []
} }
```
Field-based filters for specific endpoints can be found the in the `filters` Field-based filters for specific endpoints can be found the in the `filters`
field of the `OPTIONS` response for specific endpoints. field of the `OPTIONS` response for specific endpoints.
@ -75,7 +80,11 @@ field of the `OPTIONS` response for specific endpoints.
Single entries can also be retrieved by adding the ID (or in the case of a Single entries can also be retrieved by adding the ID (or in the case of a
Child entry, the slug) of a particular entry: Child entry, the slug) of a particular entry:
```shell
curl -X GET https://[...]/api/children/gregory-hill/ -H 'Authorization: Token [...]' curl -X GET https://[...]/api/children/gregory-hill/ -H 'Authorization: Token [...]'
```
```json
{ {
"id":3, "id":3,
"first_name":"Gregory", "first_name":"Gregory",
@ -84,7 +93,13 @@ Child entry, the slug) of a particular entry:
"slug":"gregory-hill", "slug":"gregory-hill",
"picture":null "picture":null
} }
```
```shell
curl -X GET https://[...]/api/sleep/1/ -H 'Authorization: Token [...]' curl -X GET https://[...]/api/sleep/1/ -H 'Authorization: Token [...]'
```
```json
{ {
"id":480, "id":480,
"child":3, "child":3,
@ -93,17 +108,20 @@ Child entry, the slug) of a particular entry:
"duration":"04:09:00", "duration":"04:09:00",
"nap":false "nap":false
} }
```
### Response ### Response
Returns JSON data in the response body in the following format: Returns JSON data in the response body in the following format:
```json
{ {
"count":<int>, "count":<int>,
"next":<url>, "next":<url>,
"previous":<url>, "previous":<url>,
"results":[{...}] "results":[{...}]
} }
```
- `count`: Total number of records (*in the database*, not just the response). - `count`: Total number of records (*in the database*, not just the response).
- `next`: URL for the next set of results. - `next`: URL for the next set of results.
@ -126,6 +144,7 @@ Returns JSON data in the response body describing the endpoint, available
options for `POST` requests, and available filters for `GET` requests. The options for `POST` requests, and available filters for `GET` requests. The
following example describes the `/api/children` endpoint: following example describes the `/api/children` endpoint:
```json
{ {
"name": "Child List", "name": "Child List",
"renders": [ "renders": [
@ -154,6 +173,7 @@ following example describes the `/api/children` endpoint:
"slug" "slug"
] ]
} }
```
## `POST` Method ## `POST` Method
@ -267,11 +287,13 @@ for the entry to be updated. The `Content-Type` header for `PATCH` request must
be set to `application/json`. For example, to update a Diaper Change entry with be set to `application/json`. For example, to update a Diaper Change entry with
ID 947 to indicate a "wet" diaper only: ID 947 to indicate a "wet" diaper only:
```shell
curl -X PATCH \ curl -X PATCH \
-H 'Authorization: Token [...]' \ -H 'Authorization: Token [...]' \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"wet":1, "solid":0}' \ -d '{"wet":1, "solid":0}' \
https://[...]/api/changes/947/ https://[...]/api/changes/947/
```
Regular sanity checks will be performed on relevant data. See the `OPTIONS` Regular sanity checks will be performed on relevant data. See the `OPTIONS`
response for a particular endpoint for details on required fields and data response for a particular endpoint for details on required fields and data
@ -291,7 +313,9 @@ To delete an existing entry, send a `DELETE` request to the single entry
endpoint to be deleted. For example, to delete a Diaper Change entry with ID endpoint to be deleted. For example, to delete a Diaper Change entry with ID
947: 947:
```shell
curl -X DELETE https://[...]/api/changes/947/ -H 'Authorization: Token [...]' curl -X DELETE https://[...]/api/changes/947/ -H 'Authorization: Token [...]'
```
### Response ### Response

View File

@ -19,29 +19,41 @@ information and steps below to set up a local development environment for Baby B
1. Install required Python packages, including dev packages 1. Install required Python packages, including dev packages
```shell
pipenv install --three --dev pipenv install --three --dev
```
- If this fails, install `libpq-dev` (e.g. `sudo apt install libpq-dev`) and try again. If this fails, install `libpq-dev` (e.g. `sudo apt install libpq-dev`) and try again.
1. Installed Node 14.x (if necessary) 1. Installed Node 14.x (if necessary)
```shell
nvm install 14 nvm install 14
```
1. Activate Node 14.x 1. Activate Node 14.x
```shell
nvm use nvm use
```
1. Install Gulp CLI 1. Install Gulp CLI
```shell
npm install -g gulp-cli npm install -g gulp-cli
```
1. Install required Node packages 1. Install required Node packages
```shell
npm install npm install
```
1. Set, at least, the `DJANGO_SETTINGS_MODULE` environment variable 1. Set, at least, the `DJANGO_SETTINGS_MODULE` environment variable
```shell
export DJANGO_SETTINGS_MODULE=babybuddy.settings.development export DJANGO_SETTINGS_MODULE=babybuddy.settings.development
```
This process will differ based on the host OS. The above example is for This process will differ based on the host OS. The above example is for
Linux-based systems. See [Configuration](../setup/configuration.md) for other Linux-based systems. See [Configuration](../setup/configuration.md) for other
@ -49,15 +61,21 @@ information and steps below to set up a local development environment for Baby B
1. Migrate the database 1. Migrate the database
```shell
gulp migrate gulp migrate
```
1. Create cache table 1. Create cache table
```shell
gulp createcachetable gulp createcachetable
```
1. Build assets and run the server 1. Build assets and run the server
```shell
gulp gulp
```
This command will also watch for file system changes to rebuild assets and This command will also watch for file system changes to rebuild assets and
restart the server as needed. restart the server as needed.

View File

@ -22,7 +22,9 @@ must also be updated to reflect the change. This is necessary because hosting en
do not provide adequate support for pipenv. To update the `requirements.txt` file to be in do not provide adequate support for pipenv. To update the `requirements.txt` file to be in
sync with the `Pipenv` file run: sync with the `Pipenv` file run:
pipenv lock -r > requirements.txt ```shell
pipenv requirements > requirements.txt
```
Add and commit the changes to the `requirements.txt` file. Add and commit the changes to the `requirements.txt` file.

View File

@ -34,7 +34,7 @@ See [HTTPS/SSL configuration](ssl.md) for information on how to secure Baby Budd
For doing administrative work within the LSIO container, setting an environment variable may be necessary. For doing administrative work within the LSIO container, setting an environment variable may be necessary.
For example: For example:
``` ```shell
docker exec -it babybuddy /bin/bash docker exec -it babybuddy /bin/bash
export DJANGO_SETTINGS_MODULE="babybuddy.settings.base" export DJANGO_SETTINGS_MODULE="babybuddy.settings.base"
python3 /app/babybuddy/manage.py clearsessions python3 /app/babybuddy/manage.py clearsessions
@ -47,18 +47,22 @@ python3 /app/babybuddy/manage.py clearsessions
For manual deployments to Heroku without using the "deploy" button, make sure to For manual deployments to Heroku without using the "deploy" button, make sure to
create the following settings before pushing: create the following settings before pushing:
```shell
heroku config:set DISABLE_COLLECTSTATIC=1 heroku config:set DISABLE_COLLECTSTATIC=1
heroku config:set DJANGO_SETTINGS_MODULE=babybuddy.settings.heroku heroku config:set DJANGO_SETTINGS_MODULE=babybuddy.settings.heroku
heroku config:set SECRET_KEY=<CHANGE TO SOMETHING RANDOM> heroku config:set SECRET_KEY=<CHANGE TO SOMETHING RANDOM>
heroku config:set TIME_ZONE=<DESIRED DEFAULT TIMEZONE> heroku config:set TIME_ZONE=<DESIRED DEFAULT TIMEZONE>
```
See [Configuration](configuration.md) for other settings that can be controlled See [Configuration](configuration.md) for other settings that can be controlled
by `heroku config:set`. by `heroku config:set`.
After an initial push, execute the following commands: After an initial push, execute the following commands:
```shell
heroku run python manage.py migrate heroku run python manage.py migrate
heroku run python manage.py createcachetable heroku run python manage.py createcachetable
```
## Manual ## Manual
@ -80,53 +84,73 @@ and any number of children).
1. Install system packages 1. Install system packages
```shell
sudo apt-get install python3 python3-pip nginx uwsgi uwsgi-plugin-python3 git libopenjp2-7-dev libpq-dev sudo apt-get install python3 python3-pip nginx uwsgi uwsgi-plugin-python3 git libopenjp2-7-dev libpq-dev
```
2. Default python3 to python for this session 2. Default python3 to python for this session
```shell
alias python=python3 alias python=python3
```
3. Install pipenv 3. Install pipenv
```shell
sudo -H pip3 install pipenv sudo -H pip3 install pipenv
```
4. Set up directories and files 4. Set up directories and files
```shell
sudo mkdir /var/www/babybuddy sudo mkdir /var/www/babybuddy
sudo chown $USER:$(id -gn $USER) /var/www/babybuddy sudo chown $USER:$(id -gn $USER) /var/www/babybuddy
mkdir -p /var/www/babybuddy/data/media mkdir -p /var/www/babybuddy/data/media
git clone https://github.com/babybuddy/babybuddy.git /var/www/babybuddy/public git clone https://github.com/babybuddy/babybuddy.git /var/www/babybuddy/public
```
5. Move in to the application folder 5. Move in to the application folder
```shell
cd /var/www/babybuddy/public cd /var/www/babybuddy/public
```
6. Initiate and enter a Python environment with Pipenv locally. 6. Initiate and enter a Python environment with Pipenv locally.
```shell
export PIPENV_VENV_IN_PROJECT=1 export PIPENV_VENV_IN_PROJECT=1
pipenv install --three pipenv install --three
pipenv shell pipenv shell
```
7. Create a production settings file and set the ``SECRET_KEY`` and ``ALLOWED_HOSTS`` values 7. Create a production settings file and set the ``SECRET_KEY`` and ``ALLOWED_HOSTS`` values
```shell
cp babybuddy/settings/production.example.py babybuddy/settings/production.py cp babybuddy/settings/production.example.py babybuddy/settings/production.py
editor babybuddy/settings/production.py editor babybuddy/settings/production.py
```
8. Initiate the application 8. Initiate the application
```shell
export DJANGO_SETTINGS_MODULE=babybuddy.settings.production export DJANGO_SETTINGS_MODULE=babybuddy.settings.production
python manage.py migrate python manage.py migrate
python manage.py createcachetable python manage.py createcachetable
```
9. Set appropriate permissions on the database and data folder 9. Set appropriate permissions on the database and data folder
```shell
sudo chown -R www-data:www-data /var/www/babybuddy/data sudo chown -R www-data:www-data /var/www/babybuddy/data
sudo chmod 640 /var/www/babybuddy/data/db.sqlite3 sudo chmod 640 /var/www/babybuddy/data/db.sqlite3
sudo chmod 750 /var/www/babybuddy/data sudo chmod 750 /var/www/babybuddy/data
```
10. Create and configure the uwsgi app 10. Create and configure the uwsgi app
```shell
sudo editor /etc/uwsgi/apps-available/babybuddy.ini sudo editor /etc/uwsgi/apps-available/babybuddy.ini
```
Example config: Example config:
@ -152,12 +176,16 @@ and any number of children).
11. Symlink config and restart uWSGI: 11. Symlink config and restart uWSGI:
```shell
sudo ln -s /etc/uwsgi/apps-available/babybuddy.ini /etc/uwsgi/apps-enabled/babybuddy.ini sudo ln -s /etc/uwsgi/apps-available/babybuddy.ini /etc/uwsgi/apps-enabled/babybuddy.ini
sudo service uwsgi restart sudo service uwsgi restart
```
12. Create and configure the nginx server 12. Create and configure the nginx server
```shell
sudo editor /etc/nginx/sites-available/babybuddy sudo editor /etc/nginx/sites-available/babybuddy
```
Example config: Example config:
@ -189,8 +217,10 @@ and any number of children).
14. Symlink config and restart NGINX: 14. Symlink config and restart NGINX:
```shell
sudo ln -s /etc/nginx/sites-available/babybuddy /etc/nginx/sites-enabled/babybuddy sudo ln -s /etc/nginx/sites-available/babybuddy /etc/nginx/sites-enabled/babybuddy
sudo service nginx restart sudo service nginx restart
```
15. That's it (hopefully)! 15. That's it (hopefully)!

View File

@ -29,7 +29,9 @@ protected requests to succeed.
Note: multiple origins can be added by separating origins with commas. E.g.: Note: multiple origins can be added by separating origins with commas. E.g.:
```shell
CSRF_TRUSTED_ORIGINS=https://baby.example.com,https://baby.example.org CSRF_TRUSTED_ORIGINS=https://baby.example.com,https://baby.example.org
```
### [`SECURE_PROXY_SSL_HEADER`](../configuration#secure_proxy_ssl_header) ### [`SECURE_PROXY_SSL_HEADER`](../configuration#secure_proxy_ssl_header)