Student App

The Student model is an abstraction over the Django user to provide us with a more full user profile including information pulled from social authentication via Google and/or Facebook (and/or Microsoft JHED at JHU). This app handles utilities for overriding the Python Social Auth authentication pipeline, while also handling the functionality for logged in users.

The student app also encapsulates all models tied directly to a user like PersonalTimetables, PersonalEvents, Reactions, and notification tokens.

Models

Models pertaining to Students.

class student.models.PersonalEvent(*args, **kwargs)[source]

A custom event that has been saved to a user’s PersonalTimetable so that it persists across refresh, device, and session. Marks when a user is not free. Courses are scheduled around it.

exception DoesNotExist
exception MultipleObjectsReturned
class student.models.PersonalTimetable(*args, **kwargs)[source]

Database object representing a timetable created (and saved) by a user.

A PersonalTimetable belongs to a Student, and contains a list of Courses and Sections that it represents.

exception DoesNotExist
exception MultipleObjectsReturned
class student.models.Reaction(*args, **kwargs)[source]

Database object representing a reaction to a course.

A Reaction is performed by a Student on a Course, and can be one of REACTION_CHOICES below. The reaction itself is represented by its title field.

exception DoesNotExist
exception MultipleObjectsReturned
class student.models.RegistrationToken(*args, **kwargs)[source]

A push notification token for Chrome notification via Google Cloud Messaging

exception DoesNotExist
exception MultipleObjectsReturned
class student.models.Student(*args, **kwargs)[source]

Database object representing a student.

A student is the core user of the app. Thus, a student will have a class year, major, friends, etc. An object is only created for the user if they have signed up (that is, signed out users are not represented by Student objects).

exception DoesNotExist
exception MultipleObjectsReturned

Views

class student.views.ClassmateView(**kwargs)[source]

Handles the computation of classmates for a given course, timetable, or simply the count of all classmates for a given timetable.

get(request, sem_name, year)[source]
Returns

If the query parameter ‘count’ is present Information regarding the number of friends only:

{
    "id": Course with the most friends,
    "count": The maximum # of friends in a course,
    "total_count": the total # in all classes on timetable,
}

If the query parameter course_ids is present a list of dictionaries representing past classmates and current classmates. These are students who the authenticated user is friends with and who has social courses enabled.:

[{
    "course_id":6137,
    "past_classmates":[...],
    "classmates":[...]
}, ...]

Otherwise a list of friends and non-friends alike who have social_all enabled to be displayed in the “find-friends” modal. Sorted by the number courses the authenticated user shares.:

[{
    "name": "...",
    "is_friend": Whether or not the user is current user's friend,
    "profile_url": link to FB profile,
    "shared_courses": [...],
    "peer": Info about the user,
}, ...]

class student.views.PersonalEventView(**kwargs)[source]
class student.views.ReactionView(**kwargs)[source]

Manages the creation of Reactions to courses.

post(request)[source]

Create a Reaction for the given course id, with the given title matching one of the possible emojis. If already present, remove that reaction.

class student.views.UserTimetablePreferenceView(**kwargs)[source]

Used to update timetable preferences

get_queryset()[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

serializer_class

alias of timetable.serializers.PersonalTimeTablePreferencesSerializer

class student.views.UserTimetableView(**kwargs)[source]

Responsible for the viewing and managing of all Students’ PersonalTimetable.

delete(request, sem_name, year, tt_name)[source]

Deletes a PersonalTimetable by name/year/term.

get(request, sem_name, year)[source]

Returns student’s personal timetables

post(request)[source]

Duplicates a personal timetable if a ‘source’ is provided. Else, creates a personal timetable based on the courses, custom events, preferences, etc. which are provided.

update_events(tt, events)[source]

Replace tt’s events with input events. Deletes all old events to avoid buildup in db

class student.views.UserView(**kwargs)[source]

Handles the accessing and mutating of user information and preferences.

delete(request)[source]

Delete this user and all of its data

get(request)[source]

Renders the user profile/stats page which indicates all of a student’s reviews of courses, what social they have connected, whether notificaitons are enabled, etc.

patch(request)[source]

Updates a user settings to match the corresponding values passed in the request body. (e.g. social_courses, class_year, major)

student.views.accept_tos(request)[source]

Accepts the terms of services for a user, saving the datetime the terms were accepted.

student.views.log_ical_export(request)[source]

Logs that a calendar was exported on the frotnend and indicates it was downloaded rather than exported to Google calendar.

Utils

student.utils.get_classmates_from_course_id(school, student, course_id, semester, friends=None, include_same_as=False)[source]

Get’s current and past classmates (students with timetables containing the provided course ID). Classmates must have social_courses enabled to be included. If social_sections is enabled, info about what section they are in is also passed.

Parameters
  • school (str) – the school code (e.g. ‘jhu’)

  • student (Student) – the student for whom to find classmates

  • course_id (int) – the database id for the course

  • semester (Semester) – the semester that is current (to check for)

  • friends (list of Students) – if provided, does not re-query for friends list, uses provided list.

  • include_same_as (bool) – If provided as true, searches for classmates in any courses marked as “same as” in the database.

student.utils.get_classmates_from_tts(student, course_id, tts)[source]

Returns a list of classmates a student has from a list of other user’s timetables. This utility does the leg work for get_classmates_from_course_id() by taking either a list of current or past timetables and finding classmates relevant to that list.

If both students have social_offerings enabled, adds information about what sections the student is enrolled in on each classmate.

student.utils.get_friend_count_from_course_id(student, course_id, semester)[source]

Computes the number of friends a user has in a given course for a given semester.

Ignores whether or not those friends have social courses enabled. Never exposes those user’s names or infromation. This count is used purely to upsell user’s to enable social courses.

student.utils.get_student(request)[source]
Returns

the student belonging to the authenticated user

Return type

(Student)

student.utils.get_student_tts(student, school, semester)[source]

Returns serialized list of a student’s PersonalTimetable objects ordered by last updated for passing to the frontend.

Serializers

class student.serializers.StudentSerializer(*args, **kwargs)[source]
student.serializers.get_student_dict(school, student, semester)[source]

Return serialized representation of a student.