/dos-census-events

Day of Service project to collect and publish events and resources for the 2020 census

Primary LanguageCSS

CircleCI

Census events and resources

Find census events and resources near you.

"Goals"

  • Events and resources
  • Partners can enter event information through forms
  • Events are published to Google Calendar
  • Export events via CSV
  • Integrate with SwORD via CSV export

Instead of re-creating a calendar tool, we're leveraging a fantastic and proven one: Google Calendar.

Usage

Census Events creates a publishing workflow around Google Calendar. Currently, the publishing is one-way, from Census Events to Google Calendar.

Workflow: Worflow Diagram

Setup Google Calendar

Census Events will publish events to Google Calendar. You need to create a Calendar as well as a Service Account, to publish events on your behalf.

  1. Make sure you are logged into Google with your G Suite account (you can also use your personal account if you don't have a G Suite organization).

  2. Create a new Google API Project. Click on "My Project" at the top of the page to create a new project.

  3. Create a Service Account for the project. Don't set any roles, they are not necessary.

  4. Create a (JSON) key for the Service Account and save the JSON file. Treat this file as a secret, please don't commit it to GitHub. This JSON string should be provided to the application as the GOOGLE_SERVICE_ACCOUNT_INFO environment variable. You can edit by hand into a single line or use jq.

    $ jq -c . ./google-service-account.json
    
  5. Enable the Calendar API for the API Project you just created.

  6. Create a Google Calendar and share the calendar with your Service Account's email address. You can find your Service Account's email address in the IAM Admin. Allow the Service Account to "Make changes to events" to your calendar. To access sharing settings, open your Google Calendar settings and then click the calendar you just created from the left navigation under "Settings for my calendars".

  7. Copy the Calendar Id from the settings in Google Calendar and set the environment variable GOOGLE_CALENDAR_ID.

Create calendar events

Create an event.

Setup Maps API

In our event creation form we have the google autocomplete api available.

  1. Enable the Maps Javascript API
  2. Enable the Places API
  3. Create an API Key
  4. Under API restrictions, you may restrict it to use only the Maps Javascript API and the Places API
  5. In the .env file, copy your API key to the GOOGLE_MAPS_API_KEY variable
  6. You must link a billing account to your project

Reference: (Developer Reference)[https://developers.google.com/maps/documentation/javascript/places-autocomplete]

Configuration

The application is configured through environment variables. You may set these in .env at the project root and they will be loaded automatically. Copy env.sample to .env as a template.

Variable Description Required Example
ALLOWED_HOSTS The list of hostnames to serve requests from. N app.example.com
DATABASE_URL The connection settings for the database in URL form. N postgresql://user:password@hostname/db_name?options
DJANGO_LOG_LEVEL Logging verbosity for django module. N INFO
DEBUG When true, enable debugging features for development. N 1
GOOGLE_CALENDAR_ID The Google Calendar Id where events will be published. N m7m16tqeokpbreeljd3m2n5jqg@group.calendar.google.com
GOOGLE_SERVICE_ACCOUNT_INFO JSON string containing your Service Account credentials. N {"type": "service_account", ... }
LOG_LEVEL Logging verbosity. N INFO
SECRET_KEY A secret key to provide cryptographic signing for Django. Y rHNbX.W^)fw0eS_t]GYm4BsB::Gn?Va8cLA${wtKFvE2RZrR#,
TIME_ZONE Set the server TZ to your local timezone. N America/Los_Angeles

Development

Thank you for considering a contribution to our project! Follow these instructions to get setup for development. Read over our CONTRIBUTING for more information on how we work.

Prerequisites

  • Python 3.6
  • pipenv

We assume you are installing to a python virtualenv using pipenv.

Check your versions (optional):

$ python --version
$ python3 --version
$ pip --version
$ pipenv --version

Setup

ONLY do this in the dos-census-events directory. Ensure you are currenty in the project directory.

Initialize new project virtualenv and enter the environment shell:

Initialize environment.

$ pipenv --python 3

Enter environment shell.

$ pipenv shell

Documentation resource: https://docs.python-guide.org/dev/virtualenvs/

Configuration

For development, copy these settings to a .env file in the project root directory.

DEBUG=1
DATABASE_URL=sqlite:///db.sqlite3
SECRET_KEY=not-a-secret

Install the requirements, initialize database and create a super user:

Install python dependencies.

$ pipenv install --dev

Initialize the database.

$ python manage.py migrate

Create an admin user by following the prompts.

$ python manage.py createsuperuser

(Optional) for development you can load in some initial data.

$ python manage.py loaddata --app census events

Setup CSS file references with Django

$ python manage.py collectstatic

Starting the Django server locally:

$ python manage.py runserver

Quitting the server and exiting the shell:

Quit the server using CONTROL-C

Exiting the shell using CONTROL-D or

$ exit

Working with database migrations

Anytime you make a change to the models, you should try to run makemigrations to generate a database migration.

$ python manage.py makemigrations census

If any modifications were made to the Event model, you might need to update the initial data sample.

$ python manage.py dumpdata --indent 4 census.Event > census/fixtures/events.json

Resources