Final Project's Backend of Mobile Development SIG 2021 using Django Rest Framework.
Database schema to as a guidance to data that will be used in this project
cd backendpython3 -m venv env
# Activate virtual environment
source env/bin/activate
# How to Deactivate
deactivate-
duplicate ./UlasKelas/.env.sample and rename to .env
-
run postgres db
docker-compose up -d- activate env and install requirement
source env/bin/activate
pip install -r requirements.txt- run project
python manage.py runserverdocker-compose -f docker-compose-prod.yml up -dif you make code changes, run this command
docker-compose -f docker-compose-prod.yml down && sudo docker-compose -f docker-compose-prod.yml build && docker-compose -f docker-compose-prod.yml up -dbefore migrate db, make sure ulas-pg container running
-
change or add the related models
-
make migrations file && migrate database
python manage.py makemigrations
python manage.py migrate-
change or add the related models
-
make migrations file make sure change pg host to localhost in settings.py before makemigrations
python manage.py makemigrationschange host to postgres again
- migrate database before migrate db, make sure ulas-pg container running
docker exec -it ulas-server python manage.py migratedocker exec -it ulas-pg bash
psql -U postgresor use database management and input credentials provided in settings.py
Now you can login with superuser you just create on https://localhost:8000 and interact with API view OR call the API endpoint with cURL or Postman.
Register Firebase device tokens through POST /api/device-tokens. Production
must set FIREBASE_ENABLED=true and provide either
FIREBASE_CREDENTIALS_BASE64 or Application Default Credentials. Firebase's
APNs integration must be configured for iOS delivery.
Configure the managed scheduler in the Asia/Jakarta timezone:
0 16 * * 5 python manage.py send_notification_reminders --type calculator
5 0 * * * python manage.py send_notification_reminders --type reviewThe review command safely skips every day except the calendar month's final day. Both commands use database deduplication and can be retried.
Sunjad all courses mock servers https://3e081de5-8b4c-46ea-8736-99476c47204b.mock.pstmn.io/courses
After applying migrations, populate all supported S1, D3, and D4 programs:
python manage.py migrate
python manage.py sync_courses --allTo refresh only one SSO/SunJad organization code:
python manage.py sync_courses --org-code 01.00.12.01Configure the production managed scheduler to run the all-program command
daily at 02:00 Asia/Jakarta (0 2 * * * when the scheduler supports an
explicit timezone, or 0 19 * * * in UTC):
python manage.py sync_courses --allRun the same command once immediately after the first deployment so the catalog is populated without waiting for the next schedule. The scheduler must retain stdout/stderr and alert on a non-zero exit status. A failed program is reported at the end without preventing the remaining programs from being synchronized. Programs that have no SunJad catalog yet are reported as unavailable without changing their existing course statuses.
SunJad requests use a 5-second connection timeout, a 20-second read timeout, and up to three attempts with exponential backoff for transient failures. Course mappings are deactivated only after a valid catalog snapshot; failed or untrusted responses never cause mass deactivation. Inactive courses stay in the database so existing reviews and calculator history remain accessible.
Before the first sync after deploying course-code validation, audit invalid legacy courses with the dry-run cleanup command:
python manage.py cleanup_invalid_course_codesAfter reviewing the output and taking a database backup, apply the cleanup:
python manage.py cleanup_invalid_course_codes --applyThe cleanup deactivates invalid catalog mappings. Invalid courses are deleted only when they have no review, bookmark, calculator, course-semester, or TanyaTeman references; referenced courses are retained for manual remediation.
This proof of concept runs only as a local management command. Install the temporary browser used by Playwright:
pip install -r requirements-slcm.txt
python -m playwright install chromiumRun a preview for a local Teman Kuliah profile and calculator semester:
python manage.py import_slcm_irs \
--username example.username \
--semester 1 \
--irs-url "https://slcm.ui.ac.id/path-to-irs" \
--dry-runThe command opens an isolated browser at the supplied SLCM IRS page. Complete
the SLCM login; no terminal confirmation is needed. After authentication, the
command previews only the latest academic period that contains courses. Remove
--dry-run to confirm the database import in the same browser session.
Existing calculator courses are skipped, and SLCM codes missing from the local
catalog are reported. The command does not save SLCM credentials, cookies, page
HTML, or browser storage. Use --login-timeout to override the default
five-minute login window.
Configure SLCM_IRS_URL with the fixed IRS page and expose the remote browser
using SLCM_BROWSER_PUBLIC_URL. The production Compose file includes the
single-session Chromium/noVNC service used by the login popup.
Create an authenticated session with POST /api/slcm-autofill/sessions. The
given_semester JSON field is optional: when omitted, the backend derives the
student's current semester from their NPM entry year and the current UI academic
period. Send a value such as {"given_semester":"1"} to override it manually.
Open the returned popup_url, poll
GET /api/slcm-autofill/sessions/{session_id}, display its preview once the
status is ready, and finish with
POST /api/slcm-autofill/sessions/{session_id}/confirm. Cancel an unfinished
session with DELETE /api/slcm-autofill/sessions/{session_id}.
The remote browser defaults to a touch-enabled 430x932 kiosk viewport, so
Chromium's tabs and address bar do not consume the mobile login area. noVNC
scales that fixed portrait framebuffer to the available frontend view, including
when the on-screen keyboard changes its height. Override the framebuffer with
SLCM_BROWSER_SCREEN_WIDTH and SLCM_BROWSER_SCREEN_HEIGHT when needed.
The frontend should keep polling after opening the popup and close its popup or
browser view when the session becomes ready, failed, expired, or
cancelled; the course preview remains in the regular application UI.
Changes to the Selenium screen environment require recreating the service;
docker compose restart keeps the old container environment. Apply them with:
docker compose -f docker-compose-prod.yml up -d \
--force-recreate slcm-browser serverSend POST request to /login/. This endpoint will redirect user to SSO Login page. If login success, login page will be directed to /token/ endpoint where you can retrieve token and username in its URL parameters.
Example:
{BACKEND_ROOT_URL}/token?token=f039021efcvery-long-tokencbe90717daded39&username=dummy.dumdum
This token will be used in authorization header as token authorization. Set Token {very-long-token} as value of Authorization on the headers of every endpoint that need authorization.
Example:
curl {BACKEND_ROOT_URL}/any-restricted-endpoint/
-H "Accept: application/json"
-H "Authorization: Token f039021efcvery-long-tokencbe90717daded39"