Skip to content

tankca/store

Repository files navigation

bookstore

An online book store for our Database module. Project is based off this cookiecutter skeleton.

Setup

You will need to have node and npm installed and you will need to use npm to install bower. Instructions for node and npm here. And for bower here.

If you are using Ubuntu:

You need to install python-dev and libpq-dev.

sudo apt install libpq-dev python3-dev

If you are using pip3:

First, you need to install virtualenv. This ensures that you only have the necessary packages for this project. You don't want to pollute the global python "namespace" with many libraries you might not need.

If you are using conda:

You just need to know how to create a virtual environment in conda for python.

Creation, activation and deactivation.

conda create -n bookstore python
source activate bookstore
source deactivate

You will see something like this in terminal:

(bookstore) robin-lee: <cursor>

Further instructions will be for conda.

Quickstart

First, set your app's secret key as an environment variable. For example, add the following to .bashrc or .bash_profile.

export STORE_SECRET='something-really-secret'

Before running shell commands, set the FLASK_APP and FLASK_DEBUG environment variables

export FLASK_APP=/path/to/autoapp.py
export FLASK_DEBUG=1

Then run the following commands to bootstrap your environment and ensure that flask test runs smoothly. After activating the environment, check that pip --version references the anaconda path for python. Example:pip 8.1.2 from /Users/robin/anaconda/envs/bookstore/lib/python3.5/site-packages (python 3.5)

git clone https://github.com/robin-lee/store
cd store
conda create -n bookstore python
source activate bookstore
pip install -r requirements/dev.txt
bower install
flask test
flask run

You will see this for successful tests.

doc_images/doc_test_success.png

For a successful run, you will see a pretty welcome screen. Explore the various files and try to make sense of it.

doc_images/doc_welcome_success.png

Once you have installed your DBMS, run the following to create your app's database tables and perform the initial migration.

flask db init
flask db migrate
flask db upgrade
flask run

Deployment

In your production environment, make sure the FLASK_DEBUG environment variable is unset or is set to 0, so that ProdConfig is used.

Shell

To open the interactive shell, run

flask shell

By default, you will have access to the flask app.

Running Tests

To run all tests, run

flask test

Migrations

Whenever a database migration needs to be made. Run the following commands

flask db migrate

This will generate a new migration script. Then run

flask db upgrade

To apply the migration.

For a full migration command reference, run flask db --help.

Git Work Flow

  1. On Github, fork the orignal repository to create your own copy.
  2. Go to your forked repository page and clone it to your local environment (e.g. Desktop). You should have done the setup in the Getting Started section. If you have not please make sure it works.
git clone https://github.com/<your-username>/store
cd store
  1. Activate environment.
source activate bookstore
  1. Check that tests work.
flask test
  1. Now to ensure that git is setup properly. Run the command below and you should see that you have exactly one remote called origin. ("Remotes" are like nicknames for the URLs of repositories - origin is one, for example.)
git remote
  1. Add the original Github repository as a new remote and call it upstream. (Then try "git remote" again, you should now see two remotes listed.) When you cloned you cloned from your fork. Now we want to add the original (robin-lee) as a new remore so you can pull updates.
git remote add upstream https://github.com/robin-lee/store.git
git remote
  1. To get updates. Check you are on YOUR master branch then fetch upstream.
git checkout master
git fetch upstream
  1. Rewrite your master branch so that any commits of yours that aren't already in upstream/master are replayed on top of that other branch. This where there might be merge conflicts. You will want to always do this before starting work and before you make a pull-request.
git rebase upstream/master
  1. After you have made changes you can push changes to your fork.
git add templates/newfile.html
git add --all
git commit -m "Added newfile that shows important stuff."
git push origin master
  1. Now you will want to submit a pull request to the repo. Make sure your project is synced with latest updates from the original repository. ENSURE TESTS RUN SUCCESSFULLY. If not fix it.
git fetch upstream
git rebase upstream/master
flask test
  1. Go to https://github.com/robin-lee/store/pulls and create new pull request.
  2. You should see something like: "base fork: robin-lee/store, base: master; head fork: <you-user>/store, compare: master".
  3. Confirm the code changes and create the pull request with a DESCRIPTIVE title and sensible comments.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published