Visitors will enter their PID (or scan their OneCard) when they arrive. They'll submit their name, PID, and reason on the check-in page and then check out when they leave.
Check-In App Page: http://app-lab-check-in.herokuapp.com/
Django Database: http://app-lab-check-in.herokuapp.com/admin/
KPIs Dashboard: http://app-lab-check-in.herokuapp.com/dashboard
Suggested IDE: Visual Studio Code
After cloning project:
npm install
Backend for the App Lab visitors check-in system using Django and Python
- Python 3.7.4
- Pip
- Postgres
cd backend
pip install pipenv
pipenv shell & cd backend again
pipenv install django
If you see an error installing psycopg2, install postgres via homebrew and expose the source header files by modifying LDFLAGS and CPPFLAGS env vars (pypa/pipenv#3991): run export LDFLAGS="-L/usr/local/opt/openssl/lib" and export CPPFLAGS="-I/usr/local/opt/openssl/include"
*If you are using the m1 chip: run `export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"` and `export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"`. Then, run `pip uninstall psycopg2` and `pip install psycopg2-binary`.*
After initial setup and installations, only the commands cd backend, pipenv shell, and cd backend again will need to be run before starting the server when re-opening the application.
(Without these instructions, you will likely see the following error when trying to run the server: django.db.utils.OperationalError: FATAL: role "applab" does not exist)
- Make sure that Python and Postgres are added to Environment/Path Variables - the commands
python --versionandpsql postgresorpsql -U postgresshould work on the command line (Linux:sudo -iu postgres). - On the terminal (doesn't have to be within the repository), run
psql postgresorpsql -U postgres(Linux:sudo -iu postgres). - Within postgres, run the commands
CREATE USER applab;andCREATE DATABASE checkindb;(Linux:createuser --interactive- username needs to be applab,exit, andcreatedb checkindb -U applab). - Back within the repository and backend directory that contains the
manage.pyfile (cd backendfrom the root folder), runpython manage.py migrate. - In the same backend directory, run
python manage.py createsuperuser. This command creates a superuser account to access the Django admin interface locally - make sure to remember the credentials (suggested username and password areapplab), and the email can be left blank.
Make sure you're in the backend directory that contains the manage.py file (cd backend from the root folder):
Run npm watch build in this directory (from a seperate terminal) to build the website and automatically update it.
python manage.py runserver
After the commands and installations are completed correctly, you can view the web application, Django admin dashboard, and APIs on the following local host addresses:
Start the server: python manage.py runserver
Instance of front-end application: http://localhost:8000
Admin dashboard (database for checkins): http://localhost:8000/admin (login credentials are what were set in createsuperuser command during setup)
KPIs dashboard: http://localhost:8000/dashboard
Before accessing the API, install the djangorestframework and django-cors-headers using Pipev:
pipenv install djangorestframework django-cors-headers
API: http://localhost:8000/api/checkins
After making changes to the front-end (src folder), run npm run build in the root folder to see the changes the next time the app is run locally or deployed.
Updating fields in the database:
- Add, remove, or change the desired field(s) in backend/checkin/models.py.
- In the terminal (in the backend directory containing the manage.py file), run
python manage.py makemigrations checkinandpython manage.py migrate checkin. - Update backend/checkin/admin.py and backend/checkin/serializers.py with the altered fields.
-
Define new function in backend/checkin/views.py (model off of the existing visitor_chart functions)
-
In checkin/templates directory, create a new file named KPI#.js (e.g., KPI2.js) with jquery function to render the chart (make sure to set
var $visitorChartequal to$("#visitor-chart#"), e.g.var $visitorChart = $("#visitor-chart2");) -
In checkin/templates/dashboard.html, add the script src for this file under the existing scripts within head element:
<script src="{% static 'KPI2.js' %}"></script> -
In dashboard.html, insert new container div within body element, similar to the existing containers:
<div id="container2" style="width: 40%;"> <canvas id="visitor-chart2" data-url="{% url 'visitor-chart2' %}"></canvas> </div>
-
In backend/backend/urls.py file, insert a path for the chart's data:
path('visitor-chart2/', views.visitor_chart2, name="visitor-chart2") -
(Optional) Hard refresh the dashboard page on the browser or run
python manage.py collectstatic --noinput --clearin outer backend folder beforepython manage.py runserverto refresh static files if needed
To see what your new changes will look like deployed, make a pull request on GitHub for the branch you are working on.
Commit and push these changes to your branch and then make sure you review app redeploys. You should now be able to click "Open App" to view your deployed branch.