A fork of babybuddy so that I can build a tracker for my grown-ass self.
Go to file
Christopher C. Wells 7030258f94 Remove vendor CSS file separation 2020-01-26 09:30:43 -08:00
.ebextensions Update Amazon EB deployment config. 2018-11-04 08:20:05 -08:00
api Add Temperature data to API. 2019-05-16 22:13:14 -07:00
babybuddy Improve contrast in datetime picker widget (#96) 2020-01-26 09:26:54 -08:00
core Add YYYY-MM-DD support to frontend library 2020-01-23 20:33:36 -08:00
dashboard Add "trimmed" key to `blocktrans` tags and update formatting 2020-01-23 20:00:32 -08:00
etc Add nanobox config files. 2017-11-13 16:21:33 -05:00
locale Update example French translations 2020-01-23 20:22:41 -08:00
reports Add locale support for datetime picker 2020-01-20 15:50:35 -08:00
static Remove vendor CSS file separation 2020-01-26 09:30:43 -08:00
.coveragerc Add specific, fixtures-based tests for Dashboard cards. 2017-11-19 11:13:35 -05:00
.gitignore Update documentation throughout 2020-01-19 08:49:45 -08:00
.travis.yml Update to Node 10 minimum version for development (#97) 2020-01-24 21:24:43 -08:00
CONTRIBUTING.md Update to Node 10 minimum version for development (#97) 2020-01-24 21:24:43 -08:00
Dockerfile Update Docker deployment config. 2018-11-04 08:37:33 -08:00
LICENSE Update documentation throughout 2020-01-19 08:49:45 -08:00
Pipfile Update Python dependencies (Django 3.x) 2020-01-04 06:37:42 -08:00
Pipfile.lock Update Python dependencies (Django 3.x) 2020-01-04 06:37:42 -08:00
Procfile Add a release migrate command to the Procfile for Heroku. 2019-05-02 12:01:52 -07:00
README.md Update documentation throughout 2020-01-19 08:49:45 -08:00
app.json Update Heroku deployment configuration. 2018-11-05 18:38:38 -08:00
docker-compose.yml Update docker-compose.yml 2019-10-05 06:37:03 -07:00
docker.env.example Add environment variable-based settings and configuration documentation. 2017-11-29 15:02:14 -05:00
gulpfile.config.js Remove vendor CSS file separation 2020-01-26 09:30:43 -08:00
gulpfile.js Remove vendor CSS file separation 2020-01-26 09:30:43 -08:00
manage.py Check for and load environment variables from a `.env` file. 2017-11-30 22:54:50 -05:00
package-lock.json Update to Node 10 minimum version for development (#97) 2020-01-24 21:24:43 -08:00
package.json Update to Node 10 minimum version for development (#97) 2020-01-24 21:24:43 -08:00
runtime.txt Update Heroku Python version 2020-01-04 08:40:08 -08:00
screenshot.png Update screenshot and add mobile screenshots. 2017-10-27 23:20:52 -04:00
screenshot_mobile.png Update screenshot and add mobile screenshots. 2017-10-27 23:20:52 -04:00

README.md

Baby Buddy

License Gitter

A buddy for babies! Helps caregivers track sleep, feedings, diaper changes, tummy time and more to learn about and predict baby's needs without (as much) guess work.

Baby Buddy desktop view

Baby Buddy mobile views

Table of Contents

Demo

A demo of Baby Buddy is available on Heroku. The demo instance resets every hour. Login credentials are:

  • Username: admin
  • Password: admin

Deployment

The default user name and password for Baby Buddy is admin/admin. For any deployment, log in and change the default admin password immediately.

Many of Baby Buddy's configuration settings can be controlled using environment variables - see Configuration for detailed information.

AWS Elastic Beanstalk

A basic Elastic Beanstalk configuration is provided in .ebextensions/babybuddy.config. The steps below are a rough guide to deployment. See Working with Python for detailed information.

  1. Clone/download the Baby Buddy repo

     git clone https://github.com/cdubz/babybuddy.git
    
  2. Enter the cloned/downloaded directory

     cd babybuddy
    
  3. Change the SECRET_KEY value to something random in .ebextensions/babybuddy.config

  4. Create an IAM user in AWS with EB, EC2, RDS and S3 privileges.

  5. Initialize the Elastic Bean application (using the IAM user from the previous step)

     eb init -p python-3.6
    
  6. Create/deploy the environment! 🚀

     eb create -db -db.engine postgres
    

The create command will also do an initial deployment. Run eb deploy to redeploy the app (e.g. if there are errors or settings are changed).

Docker

A Docker deployment requires Docker and Docker Compose to create two containers - one for the database and one for the application.

  1. Copy the docker.env.example to docker.env and set the ALLOWED_HOSTS and SECRET_KEY variables

     cp docker.env.example docker.env
     editor docker.env
    

    See Configuration for other settings that can be controlled by environment variables added to the docker.env file.

  2. Build/run the application

     docker-compose up -d
    
  3. Initialize the database (first run/after updates)

     docker-compose exec app python manage.py migrate
    

The app should now be locally available at http://127.0.0.1:8000. See Docker's "Get Started" documentation for detailed information about deployment methods with Docker.

Heroku

Deploy

For manual deployments to Heroku without using the deploy button, make sure to create the following settings before pushing:

heroku config:set DJANGO_SETTINGS_MODULE=babybuddy.settings.heroku
heroku config:set SECRET_KEY=<CHANGE TO SOMETHING RANDOM>
heroku config:set DISABLE_COLLECTSTATIC=1

See Configuration for other settings that can be controlled by heroku config:set.

Manual

There are many ways to deploy Baby Buddy manually to any server/VPS. The basic requirements are Python, a web server, an application server, and a database.

Requirements

Example deployment

This example assumes a 512MB VPS instance with Ubuntu 18.04. It uses Python 3.6+, nginx, uwsgi and sqlite and should be sufficient for a few users (e.g. two parents and 1+ child).

  1. Install system packages

     sudo apt-get install python3 python3-pip nginx uwsgi uwsgi-plugin-python3 git libopenjp2-7-dev
    
  2. Default python3 to python for this session

     alias python=python3
    
  3. Install pipenv

     sudo -H pip3 install pipenv
    
  4. Set up directories and files

     sudo mkdir /var/www/babybuddy
     sudo chown user:user /var/www/babybuddy
     mkdir -p /var/www/babybuddy/data/media
     git clone https://github.com/cdubz/babybuddy.git /var/www/babybuddy/public
    
  5. Move in to the application folder

     cd /var/www/babybuddy/public
    
  6. Set pipenv to install locally.

     export PIPENV_VENV_IN_PROJECT=1
    
  7. Initiate and enter the Python environment

     pipenv install --three
     pipenv shell
    

    Note: Python dependencies are locked on x86-64 architecture. Installs on other architectures (like Raspberry Pi's ARM) may result in a THESE PACKAGES DO NOT MATCH THE HASHES FROM Pipfile.lock! error. Add the --skip-lock flag to the above command to suppress this error (i.e.: pipenv install --three --dev --skip-lock).

  8. Create a production settings file and set the SECRET_KEY and ALLOWED_HOSTS values

     cp babybuddy/settings/production.example.py babybuddy/settings/production.py
     editor babybuddy/settings/production.py
    
  9. Initiate the application

     export DJANGO_SETTINGS_MODULE=babybuddy.settings.production
     python manage.py migrate
    
  10. Set appropriate permissions on the database and data folder

     sudo chown -R www-data:www-data /var/www/babybuddy/data
     sudo chmod 640 /var/www/babybuddy/data/db.sqlite3
     sudo chmod 750 /var/www/babybuddy/data
    
  11. Create and configure the uwsgi app

     sudo editor /etc/uwsgi/apps-available/babybuddy.ini
    

    Example config:

     [uwsgi]
     plugins = python3
     project = babybuddy
     base_dir = /var/www/babybuddy
    
     chdir = %(base_dir)/public
     virtualenv = %(chdir)/.venv
     module =  %(project).wsgi:application
     env = DJANGO_SETTINGS_MODULE=%(project).settings.production
     master = True
     vacuum = True
    

    See the uWSGI documentation for more advanced configuration details.

  12. Symlink config and restart uWSGI:

     sudo ln -s /etc/uwsgi/apps-available/babybuddy.ini /etc/uwsgi/apps-enabled/babybuddy.ini
     sudo service uwsgi restart
    
  13. Create and configure the nginx server

     sudo editor /etc/nginx/sites-available/babybuddy
    

    Example config:

     upstream babybuddy {
         server unix:///var/run/uwsgi/app/babybuddy/socket;
     }
    
     server {
         listen 80;
         server_name babybuddy.example.com;
    
         location / {
             uwsgi_pass babybuddy;
             include uwsgi_params;
         }
    
         location /media {
             alias /var/www/babybuddy/data/media;
         }
     }
    

    See the nginx documentation for more advanced configuration details.

  14. Symlink config and restart NGINX:

     sudo ln -s /etc/nginx/sites-available/babybuddy /etc/nginx/sites-enabled/babybuddy
     sudo service nginx restart
    
  15. That's it (hopefully)! 🎉

Configuration

Environment variables can be used to define a number of configuration settings. Baby Buddy will check the application directory structure for an .env file or take these variables from the system environment. System environment variables take precedence over the contents of an .env file.

ALLOWED_HOSTS

Default: * (any)

This option may be set to a single host or comma-separated list of hosts (without spaces). This should always be set to a specific host or hosts in production deployments.

See also: Django's documentation on the ALLOWED_HOSTS setting

ALLOW_UPLOADS

Default: True

Whether or not to allow uploads (e.g. of Child photos). For some deployments (AWS, Heroku) this setting will default to False due to the lack of available persistent storage.

AWS_ACCESS_KEY_ID

Default: None

Required to access your AWS S3 bucket, should be uniquely generated per bucket for security.

See also: AWS_STORAGE_BUCKET_NAME

AWS_SECRET_ACCESS_KEY

Default: None

Required to access your AWS S3 bucket, should be uniquely generated per bucket for security.

See also: AWS_STORAGE_BUCKET_NAME

AWS_STORAGE_BUCKET_NAME

Default: None

If you would like to use AWS S3 for storage on ephemeral storage platforms like Heroku you will need to create a bucket and add it's name. See django-storages' Amazon S3 documentation.

DEBUG

Default: False

When in debug mode, Baby Buddy will print much more detailed error information for exceptions. This setting should be False in production deployments.

See also Django's documentation on the DEBUG setting.

NAP_START_MAX

Default: 18:00

The maximum start time (in the instance's time zone) before which a sleep entry is consider a nap. Expects the 24-hour format %H:%M.

NAP_START_MIN

Default: 06:00

The minimum start time (in the instance's time zone) after which a sleep entry is considered a nap. Expects the 24-hour format %H:%M.

SECRET_KEY

Default: None

A random, unique string must be set as the "secret key" before Baby Buddy can be deployed and run.

See also Django's documentation on the SECRET_KEY setting.

TIME_ZONE

Default: Etc/UTC

The time zone to use for the instance. See List of tz database time zones for all possible values.

Languages

Baby Buddy includes translation support as of v1.2.2. Language can be set on a per-user basis from the user settings page (/user/settings/). See CONTRIBUTING.md for information about how to create/update translations.

Available languages

🇺🇸 English (U.S.) (base)

🇫🇷 French

🇩🇪 German

🇲🇽 🇪🇸 Spanish

🇸🇪 Swedish

🇹🇷 Turkish

API

Baby Buddy uses the Django REST Framework (DRF) to provide a REST API.

The only requirement for (most) requests is that the Authorization header is set as described in the Authentication section. The one exception is the /api endpoint, which lists all available endpoints.

Currently, the following endpoints are available for GET, OPTIONS, and POST requests:

  • /api/children/
  • /api/changes/ (Diaper Changes)
  • /api/feedings/
  • /api/notes/
  • /api/sleep/
  • /api/temperature/
  • /api/timers/
  • /api/tummy-times/
  • /api/weight/

Authentication

By default, the TokenAuthentication and SessionAuthentication classes are enabled. Session authentication covers local API requests made by the application itself. Token authentication allows external requests to be made.

In a production environment, token authentication should only be used for API calls to an https endpoint.

Each user is automatically assigned an API key that can be used for token authentication. This key can be found on the User Settings page for the logged in the user. To use a key for an API request, set the request Authorization header to Token <user-key>. E.g.

Authorization: Token 2h23807gd72h7hop382p98hd823dw3g665g56

If the Authorization header is not set or the key is not valid, the API will return 403 Forbidden with additional details in the response body.

GET Method

Request

The limit and offset request parameters can be used to limit and offset the results set respectively. For example, the following request will return five diaper changes starting from the 10th diaper change entry:

curl -X GET 'https://[...]/api/changes/?limit=5&offset=10' -H 'Authorization: Token [...]'
{
    "count": <int>,
    "next": "https://[...]/api/changes/?limit=5&offset=15",
    "previous": "https://[...]/api/changes/?limit=5&offset=5",
    "results": [...]
}

Field-based filters for specific endpoints can be found the in the filters field of the OPTIONS response for specific endpoints.

Response

Returns JSON data in the response body in the following format:

{
    "count":<int>,
    "next":<url>,
    "previous":<url>,
    "results":[{...}]
}
  • count: Total number of records (in the database, not just the response).
  • next: URL for the next set of results.
  • previous: URL for the previous set of results.
  • results: An array of the results of the request.

OPTIONS Method

Request

All endpoints will respond to an OPTIONS request with detailed information about the endpoint's purpose, parameters, filters, etc.

Response

Returns JSON data in the response body describing the endpoint, available options for POST requests, and available filters for GET requests. The following example describes the /api/children endpoint:

{
    "name": "Child List",
    "renders": [
        "application/json",
        "text/html"
    ],
    "parses": [
        "application/json",
        "application/x-www-form-urlencoded",
        "multipart/form-data"
    ],
    "actions": {
        "POST": {
            "id": {
                "type": "integer",
                "required": false,
                "read_only": true,
                "label": "ID"
            },
            [...]
        }
    },
    "filters": [
        "first_name",
        "last_name",
        "slug"
    ]
}

POST Method

Request

To add new entries for a particular endpoint, send a POST request with the entry data in JSON format in the request body. The Content-Type header for POST request must be set to application/json.

Regular sanity checks will be performed on relevant data. See the OPTIONS response for a particular endpoint for details on required fields and data formats.

Response

Returns JSON data in the response body describing the added/updated instance or error details if errors exist. Errors are keyed by either the field in error or the general string non_field_errors (usually when validation involves multiple fields).

Contributing

Contributions are welcome! See CONTRIBUTING.md for detailed information about how to contribute to Baby Buddy.