Skip to content

Django File Structure of TA Application System

exponentian edited this page Feb 28, 2020 · 4 revisions

Django File Structure of TA Application System

By Brandon Oh

Date: Feb. 28, 2020

Github repository: https://github.com/UBC-LFS/ta-application-system

Table of Contents

  1. Overview of Django

    1. App
    2. Model
      • Form
    3. View
      • API
    4. Templates
      • Jinja engine
  2. File Structure

    1. ta_app
      • fixtures
      • templates
      • saml_views
      • urls
      • settings
    2. accounts
      • templates
      • urls
      • views
    3. users
      • fixtures
      • tests
      • api
      • forms
      • models
    4. administrators
      • fixtures
      • templates
      • tests
      • api
      • forms
      • models
      • url
      • views
    5. instructors
      • templates
      • tests
      • urls
      • views
    6. students
      • templates
      • tests
      • urls
      • views
    7. static
      • css
      • fonts
      • images
      • js

1. Overview of Django

1-1. 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

1-3. View

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.

1-4. Templates

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.

Jinja Syntax
{% if conditions %}
    {{ contents }}
{% else %}
    {{ contents }}
{% endif %}

{% for app in apps %}
    {{ app.id }}
{% endfor %}

2. File Structure

2-1. ta_app

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

2-2. accounts

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

2-3. users

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

2-4. administrators

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

2-5. instructors

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

6. students

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

7. static

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