Skip to content
Mayukha Vadari edited this page Jul 13, 2020 · 5 revisions

Table of Contents

Table of contents generated with markdown-toc

General Objects

Program

Represents an ESP program.

Fields:

  • name (CharField)
    • e.g. "Spark"
  • edition (CharField)
    • e.g. "2020"
  • student_reg_open (BooleanField)
    • Represents whether a new student can begin registration for the program.
  • student_reg_status (CharField)
  • url (property, string)
    • The URL that should be used for a given program, derived from name and edition

Functions:

Class

Represents a class for a program.

Fields:

  • title (CharField)
  • description (TextField)
  • capacity (PositiveIntegerField)
  • program (Program)

Section

Represents a section of a class.

Fields:

  • clazz (Class)
  • number (PositiveIntegerField)
  • program (property, Program)
    • TheProgram associated with clazz
  • num_students (property, int)
    • The number of students enrolled in the section

Constraints:

  • clazz and number are a unique pair
  • number_nonzero: number > 0

Timeslot

A Timeslot is a date x duration block during which a program is happening. The duration should be the smallest denomination of time that schedule offsets need to be able to accommodate.

Examples: A Splash where all classes are multiples of an hour may have 19 timeslots

  • 2019/11/16 10:00–11:00, 11:00–12:00, and so on (for a total of 10)
  • 2019/11/17 09:00–10:00, 10:00–11:00, and so on (for a total of 9)

An HSSP with 1-hour and 1.5-hour classes may have 42 timeslots (6 timeslots/day x 7 days/program)

  • 2020/02/29 13:00–13:30, 13:30–14:00, ... , 15:30–16:00 (total of 6)
  • and repeated for 2020/03/07, and so on (for 7 Saturdays)

Fields:

  • start (DateTimeField)
  • end (DateTimeField)
  • program (Program)

Constraints:

  • start, end, and program form a unique trio
  • start_lt_end: start < end
  • Durations are constant for a given program
  • Times are only a fixed set of values (e.g. on the hour/half hour)
  • start and end are in the same day

ScheduledBlock

A ScheduledBlock represents a section of a class scheduled at a timeslot of a program in a particular classroom.

A 2-hour section scheduled in a program with 1-hour timeslot durations would be represented by two ScheduledBlock objects. A 1.5-hour section scheduled in a program with half-hour timeslot durations would be represented by three ScheduledBlock objects.

StudentRegistration

Represents the relationship between a student and a program, and everything that is a part of that.

Fields:

  • student (ESPUser)
  • program (Program)
  • student_reg_status (CharField)
  • update_profile_check (BooleanField)
    • Whether the student has updated their profile as a part of registration
  • emergency_info_check (BooleanField)
    • Whether the student has filled out the emergency contact information
  • liability_check (BooleanField)
    • Whether the student has filled out the liability waiver
  • medliab_check (BooleanField)
    • Whether the student has filled out the medical liability waiver
  • availability_check (BooleanField)
    • Whether the student has filled out their availability
  • payment_check (BooleanField)
    • Whether the student has taken care of payment for the program
  • classes (property, Class queryset)
    • QuerySet of classes the student is enrolled in

Constraints:

  • student and program form a unique pair
  • student.is_student == True

StudentClassRegistration

Represents the relationship between a student(/studentreg) and a class section. If an object exists, the student is registered for that section.

Fields:

  • studentreg (StudentRegistration)
  • section (Section)
  • student (property, ESPUser)
    • The student connected to the StudentRegistration object
  • program (property, Program)
    • The program connected to the StudentRegistration object

Constraints:

  • studentreg and section form a unique pair
  • studentreg.program == section.program

TeacherRegistration

Represents the relationship between a teacher and a program, and everything that is a part of that.

Fields:

  • teacher (ESPUser)
  • program (Program)
  • update_profile_check (BooleanField)
    • Whether the teacher has updated their profile as a part of registration
  • classes (property, Class queryset)
    • QuerySet of classes the teacher is registered to teach for

Constraints:

  • teacher and program form a unique pair
  • teacher.is_teacher == True

TeacherClassRegistration

Represents the relationship between a teacher(/teacherreg) and a class. If an object exists, the teacher is registered to teach for that class.

Fields:

  • teacherreg (TeacherRegistration)
  • clazz (Class)
  • teacher (property, ESPUser)
    • The teacher connected to the TeacherRegistration object
  • program (property, Program)
    • The program connected to the TeacherRegistration object

Constraints:

  • teacherreg and clazz form a unique pair
  • teacherreg.program == clazz.program

User Objects

ESPUser

This inherits from django.contrib.auth.models.AbstractUser. It is the type that is used for authentication. Every user on the website has an ESPUser object that represents their account.

Fields inherited from AbstractUser:

  • username (CharField)
  • first_name (CharField)
  • last_name (CharField)
  • email (EmailField)
  • is_staff (BooleanField)
    • Whether the user has access to the admin panel
  • is_superuser (BooleanField)
    • Whether the user can edit objects in the admin panel
  • is_student (property, boolean)
    • Whether the user has an attached student_profile
  • is_teacher (property, boolean)
    • Whether the user has an attached teacher_profile
  • profile (property, Profile)
    • The connected Profile object

Constraints:

  • staff_equals_superuser (user.is_staff == user.is_superuser)
  • Object can have a student profile or a teacher profile, but not both (defined in clean)

Profile

This is an abstract class. All user types inherit from it.

Fields:

  • phone_number (CharField)
  • pronouns (CharField)
  • city (CharField)
  • state (CharField)
  • country (CharField)

StudentProfile

This inherits from Profile. It contains all the fields that only students have.

Fields:

  • user (OneToOneField mapped to ESPUser, to connect the user and the profile)
  • date_of_birth (DateField)
  • grad_year (IntegerField)
  • school (CharField)

TeacherProfile

  • user (OneToOneField mapped to ESPUser, to connect the user and the profile)
  • affiliation (CharField)

Text Choices

RegStatusOptions

This is all possible student registration status options.

  • CLASS_PREFERENCES (lottery selections)
  • FROZEN_PREFERENCES (after lottery deadline, before FCFS opens)
  • CHANGE_CLASSES (FCFS)
  • PRE_PROGRAM (after FCFS deadline)
  • DAY_OF (day of the program)
  • POST_PROGRAM (after the program)
  • EMPTY (only on the frontend, used to initialize the variable)

Understanding the Code

Field Types

Full reference can be found here.

Standard Types

  • AutoField
    • Integer field that increments on each new element
    • Used by IDs, probably not necessary to use directly
  • BooleanField (equivalent to python boolean)
  • CharField (equivalent to python string)
  • DateField
  • DateTimeField
  • DurationField (for storing periods of time)
  • EmailField
  • FileField (for file uploads)
  • FloatField
  • ImageField (FileField but only images)
  • IntegerField
  • PositiveIntegerField
    • includes 0 as an option
  • SlugField
    • Basically a URL-friendly string (e.g. no spaces)
  • TextField (for large amounts of text)
  • TimeField
  • URLField

Special Types

  • ForeignKey
    • Allows the db to store a reference to another model
    • Parameter:
      • to (the main required parameter): what model to reference
      • on_delete: what to do if the reference model is deleted
        • This is usually models.CASCADE
      • related_name: how to reference the collection of objects connected to the model being referenced, with a backwards reference
        • e.g. if a Tag has an Article foreign key, and related_name=tags, then article.tags references all the tags connected to an article
        • default is [modelname]_set
      • related_query_name: analogous to related_name but for queries
        • e.g. Article.objects.filter(tag__name="important")
  • OneToOneField
    • Essentially a ForeignKey, but forces a one-to-one relationship, and using backwards references returns only one object

Meta

Full reference can be found here.

  • verbose_name
    • Human-readable name for the object
    • Defaults to converting camel case to spaced case
  • verbose_name_plural
    • Human-readable plural for the object
    • Defaults to verbose_name + "s"
  • unique_together
    • Tuple/list of tuples of fields in the object that together form a unique collection
    • e.g. Section has a unique_together of clazz and number, so no other Section can have the same clazz-number pair
  • ordering
    • Tuple/list of fields, in order of priority of how to default-order these objects in the admin panel/querysets
  • constraints