Skip to content

Latest commit

 

History

History
 
 

backend

CampusAlert backend

##Django kick start- file structions forms check for user input, urls routes the user input (i.e. request) and send it to the right destination (i.e. url destination), views defines the http interaction between user

Set up

Pip requirement packages:

Django
django-debug-toolbar
django-rest-framework
firebase_admin
fcm-django
djangorestframework-jwt
django-extensions
django-simple-history

side note: virtual environment and python notebook and other IDEs may be remove, see

eva's requiremnt.txt pip install --no-deps -r requirements.txt

Virtual env (maintain the same terminal, Mac)

mkdir env mkdir env/bin

source env/bin/activate # start virtual space deactivate # turn off

side note: dependency varies on hardware etc, but gerneral tips are, (most important first)

0. use virtual environment

1. stay at python => 3.7

2. truncate exsiting requirement into smaller pieces to install

3. to avoid python selecting higher but not eligible versions for build that lead to build fail, try starting with an empty virtual environment

4. when installing requirement stocks, try install indepedntly and use command

pip cache purge

(clean up cache)

pip install --no-deps -r requirements.txt

(avoid re-installing/ caching exisitng libs found in env)

Running Django once resolved dependecy

DJANGO_SETTINGS_MODULE=campusalert.settings python manage.py runserver

NOTE: there is a risk that installing firebase_admin can cause damage to the OpenSSL package in Python distro. See here on how to fix it: https://stackoverflow.com/questions/73830524/attributeerror-module-lib-has-no-attribute-x509-v-flag-cb-issuer-check

After that, you need to get the Firebase secret JSON file from the Discord server and put that somewhere on your computer. Then have your environment variable GOOGLE_APPLICATION_CREDENTIALS point to it.

If you have Linux, Linux subsystem for Windows, or MacOS, you can do the following to add it to Bash:

sudo nano ~/.bashrc

Then add this line

export GOOGLE_APPLICATION_CREDENTIAL=<path to the JSON file>

Make sure to restart your terminal and you are in Bash and not zsh. zsh requires similar steps.

Running + developing

To start the program, run

python3 manage.py runserver 8080

Every time you update the field name or add new fields to a model, you MUST run this before committing!

python3 manage.py makemigrations
python3 manage.py migrate
  • and accept each rename correctly in the terminal prompts

Finally, go into admin.py and write

admin.site.register(NameOfYourModel)

DANGEROUS: Delete all data and migration

You might have to do this occassionally when Django is being super stubborn and refuse to migrate due to the data in your tables.

python manage.py reset_db

After that, delete every Python file in migrations as well. Then follow the step above to makemigration and migrate.

Create an admin account

python manage.py createsuperuser

You can ignore the warning about short password in development environment.

Kevin's admin account:

  • username: thundertonic
  • password: 123

Path

auth

/auth/whoami

  • returns the user info

accounts

  • API is auto generated by Django

playground

emergency

__debug__

  • reserved for debugging purposes, auto generated by Django

TODOs

  • Use todo tree vscode plugin to see what work still needs to be done. This plugin detects all of the TODOs and summarize it in one tab.

Other stuff

Building layout images: