The Course Load Project is a web portal built to automate the process of course load generation in various formats for the AUGSD office, BITS Pilani, K. K. Birla Goa Campus. The frontend is built on React.js and the backend is built using Django python. The database used is PostgreSQL. Hosted using Heroku and AWS.
Clone this repository into your system
git clone https://github.com/AdarshNandanwar/augsd-course-load.git
- Create and activate a virtualenv.
sudo apt-get install python3-pip sudo pip3 install virtualenv virtualenv venv source venv/bin/activate
- Install required dependencies.
pip install -r requirements.txt
- Initial setup
python manage.py makemigrations python manage.py migrate python manage.py createsuperuser python populate.py cd client npm install npm run build cd ..
- For AWS S3 setup (optional): Set up all environment variables and uncomment the code for boto3 and whitenoise in settings.py.
Note- Admin panel might not work without this properly (Server Error 500) setting up the AWS S3 storage bucket environment variables.
export SECRET_KEY="" export DEBUG_VALUE="True" export DISABLE_COLLECTSTATIC="1" export AWS_ACCESS_KEY_ID="" export AWS_SECRET_ACCESS_KEY="" export AWS_STORAGE_BUCKET_NAME=""
- Run the server.
python manage.py runserver <PORT_NUMBER> --insecure
- Press Fork button from this repository and select your account.
- In your GitHub fork, press Clone or Download and copy the url.
- Open the terminal and type:
git clone <copied_url> git remote add origin <copied_url> git remote add upstream https://github.com/AdarshNandanwar/augsd-course-load
- IMPORTANT: Create a branch development where you can do the changes, accepted changes will get merged with master branch
- IMPORTANT: Do the following to disable push on upstream handle
git remote set-url --push upstream no_push
git add <filename>
# or to add everything using "git add ."
git commit -m <commit_message>
git pull upstream master
# Resolve merge conflicts (if any)
git push origin master
On your GitHub development branch, press Compare & pull request and then Create Pull Request on the next page
- Clone the repo.
- Run the server process in the new screen session window. Replace port_number with the port number available in the server.
sudo venv/bin/python3 manage.py runserver 0.0.0.0:{port_number} --insecure
- Make sure to setup staticfiles app for css, js, images to load properly:
- Add all the STATICFILES_DIRS in settings.py:
eg.
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'client/build/static'), os.path.join(BASE_DIR, 'course_load/static'), ]
- Run:
This will create an app named staticfiles containing all the static files of the project
$ python manage.py collectstatic
- Disable collectstatic for deployment:
$ heroku config:set DISABLE_COLLECTSTATIC=1
- For React, read this.
- Commit and push to heroku master.
- Add all the STATICFILES_DIRS in settings.py:
eg.
- Set environment variables in heroku console.
export SECRET_KEY="" export DEBUG_VALUE="True" export DISABLE_COLLECTSTATIC="1" export AWS_ACCESS_KEY_ID="" export AWS_SECRET_ACCESS_KEY="" export AWS_STORAGE_BUCKET_NAME=""
Follow these steps to retain database after modification in the database schema.
- Do all the changes in the development branch. Make sure all the new fields in the schema have some default value.
- Merge in the development branch in master.
- Delete local database [see steps below].
- Download and load the database dump from heroku to local [see steps below].
- Check if everything is working.
- Push the changes to heroku master.
- Check if everything is working, If yes, yay! We are done.
- Else, dump the working local database to heroku.
- Delete the sqlite database file (often named
db.sqlite3
) in your django project folder (or wherever you placed it). - Delete everything except
__init__.py
file from migration folder in all django apps. - Make changes in your models (
models.py
). - Run the command
python manage.py makemigrations
orpython3 manage.py makemigrations
. - Then run the command
python manage.py migrate
.
- Delete the sqlite database file (often named
db.sqlite3
) in your django project folder (or wherever you placed it). - Delete everything except
__init__.py
file from migration folder in all django apps. - Run the following commands. Replace file name in th3 loaddata command with the latest file name of the database dump.
$ heroku run python manage.py dumpdata --natural-foreign -- > data_dump_$(date +"%Y%m%d_%H%M%S").json $ python manage.py makemigrations $ python manage.py migrate $ python manage.py loaddata ${file_name}.json
- Delete the sqlite database file (often named
db.sqlite3
) in your django project folder (or wherever you placed it). - Delete everything except
__init__.py
file from migration folder in all django apps. -
$ python manage.py dumpdata > data_dump_local_$(date +"%Y%m%d_%H%M%S").json $ heroku pg:reset $ heroku restart $ heroku run python manage.py makemigrations $ heroku run python manage.py migrate $ cat ${file_name}.json | heroku run --no-tty -a augsd-course-load -- python manage.py loaddata --format=json -