Skip to content

FECHoosier/fec-cms

 
 

Repository files navigation

Develop Build Status

Master Dependency Status

Campaign finance for everyone

The Federal Election Commission (FEC) releases information to the public about money that’s raised and spent in federal elections — that’s elections for US President, Senate, and House of Representatives.

Are you interested in seeing how much money a candidate raised? Or spent? How much debt they took on? Who contributed to their campaign? The FEC is the authoritative source for that information.

betaFEC is a collaboration between 18F and the FEC. It aims to make campaign finance information more accessible (and understandable) to all users.

FEC repositories

We welcome you to explore, make suggestions, and contribute to our code.

This repository, fec-cms, houses the content management system (CMS) for betaFEC.

  • FEC: a general discussion forum. We compile feedback from betaFEC’s feedback widget here, and this is the best place to submit general feedback.
  • openFEC: betaFEC’s API.
  • openFEC-web-app: the betaFEC web app for exploring campaign finance data.
  • fec-style: shared styles and user interface components.
  • fec-cms: the content management system (CMS) for betaFEC. This project uses Wagtail, an open source CMS written in Python and built on the Django framework.

Get involved

We’re thrilled you want to get involved!

  • Read our contributing guidelines. Then, file an issue or submit a pull request.
  • Send us an email at betafeedback@fec.gov.
  • If you're a developer, follow the installation instructions in the README.md page of each repository to run the apps on your computer.
  • Check out our StoriesonBoard FEC story map to get a sense of the user needs we'll be addressing in the future.

Set up

We are always trying to improve our documentation. If you have suggestions or run into problems please file an issue!

Project prerequisites

  1. Ensure you have the following requirements installed:

    • Python 3.5 (which includes pip and and a built-in version of virtualenv called pyvenv).
    • The latest long term support (LTS) or stable release of Node.js (which includes npm).
    • PostgreSQL (the latest 9.5 release).
  2. Set up your Node environment — learn how to do this with our Javascript Ecosystem Guide.

  3. Set up your Python environment — learn how to do this with our Python Ecosystem Guide.

  4. Clone this repository.

Install project dependencies

Use pip to install the Python dependencies:

pip install -r requirements.txt

Use npm to install JavaScript dependencies:

npm install

Give default user privileges to create database

If you would like your default user to create the database, alter their user role:

sudo su - postgres
psql
alter user [default_username] createdb;
\q
exit

Create local databases

Before you can run this project locally, you'll need a development database:

createdb cfdm_cms_test

You will also need to set environmental variables:

Connection string for the local database as an environment variable:

export DATABASE_URL=postgresql://:@/cfdm_cms_test

Finish project setup

Once all prerequisites and dependencies are installed, you can finish the project setup by running these commands:

npm run build
cd fec/
./manage.py migrate
./manage.py createsuperuser

Running the application

In the root project folder, run:

cd fec/
./manage.py runserver

Running tests

There are two kinds of tests that you can run with the project, Python tests and JavaScript tests.

To run the JavaScript tests, run this command in the root project directory:

npm run test-single

Note: You may be prompted to allow node to accept connections; this is okay and required for the tests to run.

To run the Python tests, run these commands in the root project directory:

cd fec/
./manage.py test

Enabling/toggling features

settings/base.py includes a set of FEATURES which can also be enabled using environment flags:

FEC_FEATURE_LEGAL=1 python fec/manage.py runserver

Additional local development instructions

Watch for static asset changes

To watch for changes to .js and .scss, run this command in the root project directory:

npm run watch

Developing with fec-style (optional)

If you're developing with a local instance of FEC-Style and want to pull in styles and script changes as you go, use npm link to create a symbolic link to your local fec-style repo:

cd ~/fec-style
npm link
cd ~/openFEC-web-app
npm link fec-style

After linking fec-style, npm run watch will rebuild on changes to your local copy of fec-style's .scss and .js files.

Developing with openFEC (optional)

To set the URL for the web app as an environment variable, run:

export FEC_APP_URL=http://localhost:3000

Or, to set it in the settings file directly, include this line:

FEC_APP_URL = 'http://localhost:3000'

Restoring your local database from a backup

Likely only useful for 18F FEC team members To restore your local database from a backup from production, download the database dump and run this command:

pg_restore --dbname cfdm_cms_test --no-acl --no-owner <path/to/backup_file>

Deploy

Likely only useful for 18F FEC team members

We use Travis for automated deploys after tests pass. If you want to deploy something it is much better to push an empty commit with a tag than doing a manual deploy.

If there is a problem with Travis and something needs to be deployed, you can do so with the following commands. Though, you will need to pull the environment variables from the space you are deploying to and remake your static assets. That will ensure things like the links are correct. You will also want to clear your dist/ directory. That way, you will not exceed the alloted space.

Before deploying, install the Cloud Foundry CLI and the autopilot plugin:

cf install-plugin autopilot -r CF-Community

Provision development database:

cf create-service rds micro-psql fec-rds-stage

Provision credentials service:

cf cups cms-creds-dev -p '{"DJANGO_SECRET_KEY": "..."}'

To deploy to Cloud Foundry, run invoke deploy. The deploy task will attempt to detect the appropriate Cloud Foundry space based the current branch; to override, pass the optional --space flag:

invoke deploy --space feature

The deploy task will use the FEC_CF_USERNAME and FEC_CF_PASSWORD environment variables to log in. If these variables are not provided, you will be prompted for your Cloud Foundry credentials.

Deploys of a single app can be performed manually by targeting the env/space, and specifying the corresponding manifest, as well as the app you want, like so:

cf target -s [feature|dev|stage|prod] && cf push -f manifest_<[feature|dev|stage|prod]>.yml [api|web]

NOTE: Performing a deploy in this manner will result in a brief period of downtime.

Backup

To restore data from a remote instance to a local instance, or between local instances, back up data using dumpdata and restore using loaddata. You'll also need to install cf-ssh. The following is an example of restoring remote data to a local instance.

Use cf target -s to select the space you want to create a manifest for, then:

# Local
cf create-app-manifest cms -p manifest_ssh.yml
cf-ssh -f manifest_ssh.yml

# Remote
cd fec
./manage.py dumpdata --settings fec.settings.production --exclude sessions.session --exclude contenttypes.ContentType --exclude auth.permission --exclude auth.user --output dump.json

# Local
cd fec/
cf files cms-ssh app/fec/dump.json | tail -n +4 > dump.json
./manage.py loaddata dump.json

Copyright and licensing

This project is in the public domain within the United States, and we waive worldwide copyright and related rights through CC0 universal public domain dedication. Read more on our license page.

A few restrictions limit the way you can use FEC data. For example, you can't use contributor lists for commercial purposes or to solicit donations. Learn more on FEC.gov.

About

The content management system (CMS) for the new Federal Election Commission website.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 56.0%
  • HTML 34.9%
  • JavaScript 8.5%
  • Other 0.6%