From 069c3b8180851090f22a4e958fb4fbfb5ca7cc7f Mon Sep 17 00:00:00 2001 From: noloerino Date: Sat, 2 Mar 2019 04:11:10 -0800 Subject: [PATCH] Add LICENSE, clean up README, add setup script --- LICENSE | 9 +++++ README.md | 72 ++++++++++++++++++------------------- csm_web/csm_web/settings.py | 9 ----- setup.sh | 49 +++++++++++++++++++++++++ 4 files changed, 92 insertions(+), 47 deletions(-) create mode 100644 LICENSE create mode 100755 setup.sh diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..12741dc2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2019 Computer Science Mentors + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 2b395d67..c4e2e61a 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,35 @@ # CSM Web Applications -This repository is for the Django CSM Web project that contains the Scheduler -application (and possibly more applications to come). - -## Install -We recommend running this with a Python virtual environment. - -If you don't have virtualenv, -``` -pip install virtualenv -``` - -To create the virtualenv, run -``` -virtualenv venv -``` -You may need to specify the Python version -(you can find the path to Python3 with `which python3`) -in which case run the following instead -``` -virtualenv --python=/usr/local/bin/python3 venv -``` - -To create install dependencies, -``` -source venv/bin/activate -pip install -r csm_web/requirements.txt -npm i -``` - -## Starting Django -To start the Django server, -``` -npm run dev && python csm_web/manage.py runserver -``` -To populate the database with test data, -``` -python csm_web/manage.py createtestdata -``` +This repository contains webapps that help support the infrastructure of CSM. Currently, it only holds Scheduler (our section signup and attendance system), but more are on the way. +## Installing +### Requirements +We don't know what specific minimum version you would need for any of the following software, but the most recent version of any of the below should work. + +* Python 3.7 + * [virtualenv](https://packaging.python.org/guides/installing-using-pip-and-virtualenv/) (`pip install virtualenv`) + * [black](https://black.readthedocs.io/en/stable/) (`pip install black`) +* [npm](https://www.npmjs.com/get-npm) + * [prettier](https://prettier.io/) (`npm install -g prettier`) + * [eslint](https://eslint.org/) (`npm install -g eslint`; `npm install -g eslint-plugin-react`) +* [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli#download-and-install) (`brew tap heroku/brew && brew install heroku`) + +Other miscellaneous requirements will be installed by the commands below. + +### Setup +To ensure package version consistency and avoid polluting your global package installations, we highly recommend running the server with [virtualenv](https://virtualenv.pypa.io/en/stable/) (`pip install virtualenv`). + +From a terminal in the top level of the project directory, run `python3 -m virtualenv venv`. + +To activate the environment, run `source venv/bin/activate`. You will need to run this command every time you open a new terminal. + +Finally, run `./setup.sh`. This will install additional requirements needed by the server, and set up some necessary environment variables. + +## Running +To start the Django server, run `python csm_web/manage.py runserver` and visit `localhost:8000` in your browser. + +Run `python csm_web/manage.py createtestdata` to generate some test data. + +*If you make any frontend changes*: run `npm run dev` to rebuild the frontend JS bundle (this has to be done manually at the moment). + +## Troubleshooting +* OSX: error on running `pip` + * Try replacing `pip` with `pip3` instead. \ No newline at end of file diff --git a/csm_web/csm_web/settings.py b/csm_web/csm_web/settings.py index 61cfa582..fb5608b7 100644 --- a/csm_web/csm_web/settings.py +++ b/csm_web/csm_web/settings.py @@ -247,15 +247,6 @@ }, } - -if not os.environ.get("DEBUG_LOG_OFF"): - LOGGING["loggers"]["django.db.backends"] = { - "handlers": ["low-level"], - "level": "DEBUG", - "propagate": False, - } - - if DJANGO_ENV == PRODUCTION: # Security/HTTPS headers # https://docs.djangoproject.com/en/2.1/ref/middleware/#module-django.middleware.security diff --git a/setup.sh b/setup.sh new file mode 100755 index 00000000..33aaa5bd --- /dev/null +++ b/setup.sh @@ -0,0 +1,49 @@ +# #!/usr/bin/env bash +# # Sets up environment variables and such, assuming requirements already installed. +# # Kevin Svetlitski, rev. Jonathan Shi + +# [ ! -f 'package.json' ] && echo 'You are in the wrong directory!' && exit 1 +# [ -z "$VIRTUAL_ENV" ] && echo 'You must activate your virtualenv first!' && exit 1 + +# # Node and Python requirements +# npm i +# npm run dev +# pip3 install -r requirements.txt + +# # Set up environment variables +# echo "Setting up environment variables..." +# echo "BUILDPACK_URL='https://github.com/heroku/heroku-buildpack-python' +# DJANGO_ENV=dev +# DEBUG_LOG_OFF='True' +# WEB_CONCURRENCY=4" > .env + +# # Get a new key +# echo "Generating Django secret key..." +# export SECRET_KEY=$(echo "from django.core.management.utils import get_random_secret_key; \ +# print(get_random_secret_key())" | python3 csm_web/manage.py shell) +# echo "SECRET_KEY='$SECRET_KEY'" >> .env + +# # Must be pulled from Heroku (but not critical to running tests etc.) +# if [[ $(heroku whoami) ]]; then +# echo "Attempting to set OAUTH keys from heroku config..." +# echo $(heroku config:get SOCIAL_AUTH_GOOGLE_OAUTH2_KEY -s) >> .env +# echo $(heroku config:get SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET -s) >> .env +# else +# echo "Did not find Heroku CLI installation. OAUTH keys have not been set, so you will be unable to log in with your email." +# fi + +# pwd > "$VIRTUAL_ENV/.project_dir" + +# Slightly jank hack to get .env to source properly +cat <> $VIRTUAL_ENV/bin/activate +# Scheduler: get variables in .env +while read v; do + export \$v +done < $(pwd)/.env +EOF + +# # TODO put precommit hooks in git? +# echo "Getting precommit hooks..." +# curl "http://inst.eecs.berkeley.edu/~cs199-eug/pre-commit" -o .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit + +echo "Done installing. Please reactivate your virtualenv before running any more commands." \ No newline at end of file