-
Notifications
You must be signed in to change notification settings - Fork 0
Django File Structure of TA Application System
Date: Feb. 28, 2020
Github repository: https://github.com/UBC-LFS/ta-application-system
-
- App
- Model
- Form
- View
- API
- Templates
- Jinja engine
-
- ta_app
- fixtures
- templates
- saml_views
- urls
- settings
- accounts
- templates
- urls
- views
- users
- fixtures
- tests
- api
- forms
- models
- administrators
- fixtures
- templates
- tests
- api
- forms
- models
- url
- views
- instructors
- templates
- tests
- urls
- views
- students
- templates
- tests
- urls
- views
- static
- css
- fonts
- images
- js
- ta_app
After creating a project, we can add many modules called App in the project folder.
# Reference:
# https://docs.djangoproject.com/en/3.0/intro/tutorial01/
# Create a Django project
$ django-admin startproject ta_app
# Create an App
$ django-admin startapp accounts
Django is a full-stack framework that has a server and client pages itself, and each App contains Model, View, Templates, Form, Url, test files and so on.
- Data flow: Model <--> View <--> Templates
1-2. Model
Users can define many database tables and fields in a model. Also, Model has form validation features, so we can add some validators such as FileExtensionValidator or custom one. Form extends Model which means Form can have many different fields in a model. I would say that it's a good feature in Django.
For example, If I have a Confidentiality model, I can create two different Forms because required documents are different.
- ConfidentialityDomesticForm
- ConfidentialityInternationalForm
# Make migration files
$ python manage.py makemigrations
# Migrate created models to Database
$ python manage.py migrate
View is located in the middle of data flow, so it would be a controll centre in the framework. When users make actions or we want to display users' information in web pages, it manages to push or pull data from database through API to the client pages.
If we have some data fetched from database, we need to display them effectively in html pages called Templates. Django exists with Jinja template engine, so we can use for-loop and if-statement in html pages.
{% if conditions %}
{{ contents }}
{% else %}
{{ contents }}
{% endif %}
{% for app in apps %}
{{ app.id }}
{% endfor %}
ta_app is a core module in this system, and has settings.py file.
- fixtures: We can create some json files to add initial information to the system or to write some test cases.
- templates: It contains a base page and some sub-pages to reduce complexity.
- saml_views: It manages users who log in through CWL.
- urls: This url is a root which means it includes administrators.urls, students.urls and so on.
- key file/folder: fixtures, templates, saml_views, urls, settings
accounts is designed for login functionality. We have two different login pathways such as CWL and local login. Also, login is a landing page of the system.
- Landing URL: {URL}/accounts/login/
- key file/folder: templates, urls, views
We have three different index views/roles such as administrators, instructors, and students, and they have same attributes such as profile. So users App is designed to avoid redundant creation. These three Apps can fetch user's information such as profile from users model.
- key file/folder: fixtures, tests, api, forms, models
administrators module is the biggest App in this system. It includes a job related model and neccessary files, and manages all data to create, edit, and remove job related information and users. Also, instructors and students views sometimes call API to save and fetch data.
- tests: Many test cases are required because administrators has many user's actions
- key file/folder: fixtures, templates, tests, api, forms, models, url, views
# Test administrators
$ python manage.py test administrators
instructors has a few actions, and push and fetch data from users and administrators APIs.
- key file/folder: templates, tests, urls, views
# Test instructors
$ python manage.py test instructors
students has a few actions, and push and fetch data from users and administrators APIs.
- key file/folder: templates, tests, urls, views
# Test students
$ python manage.py test students
This module contains CSS stylesheet and Javascript, Image files. In production, we have to run the following command to collect static files.
# Collect static files
$ python manage.py collectstatic --noinput
- fonts: Implemented Font Awesome 4.7 library for icons
- key file/folder: css, fonts, images, js