Skip to content

CityofPittsburgh/pittsburgh-purchasing-suite

 
 

Repository files navigation

Build Status Documentation Status

Pittsburgh Purchasing Suite

What is it?

The Pittsburgh Purchasing Suite is a collection of small applets backed by a common data store. These applets allow users to manage, view, and advertise contracts. Read all about it in the Team Pittsburgh End of Year Report

What's the status?

Core Pittsburgh Purchasing Suite features are in alpha, with other features in different stages of early development.

Feature status:
Feature Status User Guides (PDF)
Scout - a tool to look up contracts Beta Deployed User Guide
Atlas - a tool to explore the procurement process Deprecated n/a
Beacon - a tool to be notified about new opportunities Beta Deployed User Guide
Conductor - a tool for managing contracts & contract renewal Beta Deployed (required login) User Guide
Admin - an administrative backend built with Flask-admin Beta Deployed User Guide
Technical Documentation

In addition to the user guides listed above, technical documentation for the Pittsburgh Purchasing Suite is available on Read the Docs. If you want to build the docs yourself, make sure you have the development dependencies installed. Then you can use the make doc command to build the docs from source.

Who made it?

The purchasing suite is a project of the 2015 Pittsburgh Code for America fellowship team.

How

Core Dependencies

The purchasing suite is a Flask app. It uses Postgres for a database and uses bower to manage most of its dependencies. It also uses less to compile style assets. In production, the project uses Celery with Redis as a broker to handle backgrounding various tasks. Big thanks to the cookiecutter-flask project for a nice kickstart.

It is highly recommended that you use use virtualenv (and virtualenvwrapper for convenience). For a how-to on getting set up, please consult this howto. Additionally, you'll need node to install bower (see this howto for more on Node), and it is recommended that you use postgres.app to handle your Postgres (assuming you are developing on OSX).

Installation and setup

Quick local installation using Make

First, create a virtualenv and activate it. Then:

git clone git@github.com:codeforamerica/pittsburgh-purchasing-suite.git
cd pittsburgh-purchasing-suite
# create the 'purchasing' database
psql -c 'create database purchasing;'
# set environmental variables - it is recommended that you set these for your
# your virtualenv, using a tool like autoenv or by modifying your activate script
export ADMIN_EMAIL='youremail@someplace.net'
export DEFAULT_DOMAIN='someplace.net'
export CONFIG=beacon.settings.DevConfig
# this next command will do all installs, add tables to the database,
# and insert seed data (note that this needs an internet connection to
# scrape data from Allegheny County)
make setup
# start your server
python manage.py server
More detailed installation instructions

If you want to walk through the complete setup captured above in make setup, use the following commands to bootstrap your development environment:

python app:

# clone the repo
git clone https://github.com/codeforamerica/pittsburgh-purchasing-suite
# change into the repo directory
cd pittsburgh-purchasing-suite
# install python dependencies
# NOTE: if you are using postgres.app, you will need to make sure to
# set your PATH to include the bin directory. For example:
# export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin/
pip install -r requirements/dev.txt
# note, if you are looking to deploy, you won't need dev dependencies.
# uncomment & run this command instead:
# pip install -r requirements.txt

NOTE: The app's configuration lives in settings.py. When different configurations (such as DevConfig) are referenced in the next sections, they are contained in that file.

email:

The app uses Flask-Mail to handle sending emails. This includes emails about subscriptions to various contracts, notifications about contracts being followed, and others. In production, the app relies on Sendgrid, but in development, it uses the Gmail SMTP server. If you don't need to send emails, you can disable emails by setting MAIL_SUPPRESS_SEND = True in the DevConfig configuration object.

If you would like to send email over the Gmail SMTP server, you will need to add two environmental variables: MAIL_USERNAME and MAIL_PASSWORD. You can use Google's app passwords to create a unique password only for the app.

database:

# login to postgres. If you are using postgres.app, you can click
# the little elephant in your taskbar to open this instead of using
# psql
psql
create database purchasing;

Once you've created your database, you'll need to open purchasing/settings.py and edit the DevConfig object to use the proper SQLAlchemy database configuration string. If you named your database purchasing, you probably won't have to change anything. Then:

# upgrade your database to the latest version
python manage.py db upgrade

By default, SQLAlchemy logging is turned off. If you want to enable it, you'll need to add a SQLALCHEMY_ECHO flag to your environment.

front-end:

If you haven't installed npm, please consult this howto for the best way to do so. On Mac, you can also use homebrew.

Once you install node, run the following:

# install bower, less, and uglifyjs
# you may need to use sudo
npm install -g bower
npm install -g uglifyjs
npm install -g less
# use bower to install the dependencies
bower install

login and user accounts

A manage task has been created to allow you to quickly create a user to access the admin and other staff-only tasks. To add an email, run the following command (NOTE: if you updated your database as per above, you will probably want to give youself a role of 1, which will give you superadmin privledges), putting your email/desired role in the appropriate places:

python manage.py seed_user -e <your-email-here> -r <your-desired-role> -p <your-desired password>
# if you leave the password blank, it will default to `password`

WARNING The password you create on seeding will be stored as plaintext. Please reset this password as soon as possible!


**up and running**

If you boot up the app right now, it will have no data. If you want to add some data, a small manage task has been added to allow for quick data importation.

```bash
# run the data importers
python manage.py seed

Now you should be ready to roll with some seed data to get you started!

# run the server
python manage.py server

Celery and Redis

To get started with development, you won't need to do any additional setup. However, if you want to emulate the production environment on your local system, you will need to install Redis and configure Celery. To do everything, you'll need to run Redis (our broker), Celery (our task queue), and the app itself all at the same time.

Get started by installing redis. On OSX, you can use homebrew:

brew install redis

Once this is all installed, you should see a handy command you can use to start the Redis cluster locally (something like the following):

redis-server /usr/local/etc/redis.conf

Now, redis should be up and running. Before we launch our web app, we'll need to configure it to use our Celery/Redis task queue as opposed to using the eager fake queue. Navgate to purchasing/settings.py. In the DevConfig, there should be three settings related to Celery. Commenting out CELERY_ALWAYS_EAGER and un-commenting CELERY_BROKER_URL and CELERY_RESULT_BACKEND will signal the app to use Redis for Celery's broker.

At this point, you'll be abel to boot up the celery worker. Our app's celery workers live in purchasing/celery_worker.py. Start them as follows:

celery --app=purchasing.celery_worker:celery worker --loglevel=debug

You can log at a higher level than debug (info, for example), if you want to get fewer messages. Finally, we'll need to start our web app. You can do this as normal:

python manage.py server

When all of these are running, you should be ready to go!

Testing

In order to run the tests, you will need to create a test database. You can follow the same procedures outlined in the install section. By default, the database should be named purchasing_test:

psql
create database purchasing_test;

Tests are located in the purchasing_test directory. To run the tests, run

PYTHONPATH=. nosetests purchasing_test/

from inside the root directory. For more coverage information, run

PYTHONPATH=. nosetests purchasing_test/ -v --with-coverage --cover-package=purchasing_test --cover-erase

License

See LICENSE.md.

Releases

No releases published

Packages

No packages published

Languages

  • Python 65.0%
  • HTML 29.9%
  • JavaScript 2.4%
  • CSS 2.3%
  • Shell 0.3%
  • Makefile 0.1%