Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archiving #270

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open

Archiving #270

wants to merge 22 commits into from

Conversation

rsmcconnell
Copy link

Changes only to models.py. Includes:

  1. current_semester_sid() function outside of any class to clean up filters
  2. Validating Model now has past_objects_included, an alternative to objects, that includes all objects in the db across all semesters in a query.
  3. Semester Model added. Only one field: sid. More recent semesters have higher sid's. By default, all queries to other objects will filter for objects only from the most recent a.k.a. current semester. Because of highlight 2 (above), any query can replace objects with past_objects_included to bypass this filter. (i.e. Student.objects.all() -> queryset of current students, Student.past_objects_included.all() -> queryset of students from all semesters in db).
  4. Course has a semester field. All other models are connected to a semester via the course model.
  5. Every model has a manager. For example, Attendance has the AttendanceModelManager. These managers enforce the default current semester only query behavior. Student, Mentor, and other models that inherit from profile don't have individual managers; there is just one manager for Profile.

Note: When first implementing these changes, every course will have its semester field set to None, and queries will error. This will be resolved as soon as a semester object is created for the current semester and each course's semester field is assigned that semester.

@csm-SPA csm-SPA temporarily deployed to csm-web-pr-270 April 15, 2022 00:45 Inactive
@csm-SPA csm-SPA temporarily deployed to csm-web-pr-270 April 16, 2022 00:41 Inactive
@csm-SPA csm-SPA temporarily deployed to csm-web-pr-270 April 16, 2022 00:47 Inactive
@csm-SPA csm-SPA temporarily deployed to csm-web-pr-270 April 16, 2022 00:50 Inactive
@csm-SPA csm-SPA temporarily deployed to csm-web-pr-270 April 16, 2022 00:54 Inactive
Copy link
Member

@smartspot2 smartspot2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all, this looks really good; the model managers look good, and the semester object overall is pretty good (the fields could be tweaked slightly though).

In testing though, I've found a couple bugs. First, the pytest tests are failing because the Course factory has not been updated with the Semester object; this should be changed to ensure that pytest is still working. Some additional tests should probably be added to ensure that the distinguishing of semesters is respected with the queries.

Another bug I've found is that in accessing the section from the UI, an internal error occurs when accessing the Spacetime.objects attribute. This could be because it hasn't been overridden, though it seems a little bit weird that the base class would stop working; it'd be good to look into more.

In all, make sure that the pytest tests are all passing after each commit (at least, after each commit with finished features), to ensure that no regressions happen. This can be done locally with just pytest csm_web, and should run relatively quickly too. If possible, adding more tests would be great, to ensure that the functionality is still working as desired, and to check for any edge cases, though I know that's a work in progress still.

@@ -278,4 +278,5 @@ def generate_test_data(preconfirm=False):
val = random.randint(1, 100)
ResourceFactory.create(course=course, week_num=i+1, date=date, topics=f"Topic {val}")
print("Done generating resources")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure why there's a newline here; likely a leftover from another reverted change? In general, it's always good to do a quick git status and a git diff to check over all your changes before committing just to avoid these kinds of extraneous diffs.

Course = apps.get_model("scheduler", "Course")
Semester = apps.get_model("scheduler", "Semester")
initial_semester = Semester()
initial_semester.sid = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be necessary to specify this value on creation; it should be automatically assigned to be the next available integer value.

@@ -58,6 +62,8 @@ class ValidatingModel(models.Model):
This abstract class fixes that insanity
"""

past_objects_included = models.Manager()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would perhaps rename this to all_objects just to be briefer, but it's up to you; it's just a preference thing.

@@ -66,6 +72,22 @@ class Meta:
abstract = True


class Semester(ValidatingModel):
sid = models.PositiveSmallIntegerField(primary_key=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A PositiveSmallIntegerField requires the user to manually specify the value; this isn't very optimal, since the user would need to know which integer values have been used and have not been used so far. An AutoField would be best here (I believe it is also the default for the primary key), as it is automatically specified on creation.

@@ -66,6 +72,22 @@ class Meta:
abstract = True


class Semester(ValidatingModel):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also add a field for the user-readable name of the semester, since currently it's only defined by the sid, which is not related to the meaning/interpretation of the semester object. This could just be a small CharField, or something similar; I'm envisioning it to just hold something like sp22 or fa20, etc. You could even add some validation to ensure that it's of the form (sp|fa)\d\d if you'd like.

@@ -1,7 +1,7 @@
from rest_framework import serializers
from enum import Enum
from django.utils import timezone
from .models import Attendance, Course, SectionOccurrence, User, Student, Section, Mentor, Override, Spacetime, Coordinator, DayOfWeekField, Resource, Worksheet
from .models import Attendance, Course, SectionOccurrence, User, Student, Section, Mentor, Override, Spacetime, Coordinator, DayOfWeekField, Resource, Worksheet, Semester
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the Semester model is imported here without ever being used.

objects = models.Manager()

def __str__(self):
return f"{self.sid}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do end up adding the extra description field, that should be added here to describe the semester model a little bit more.

@smartspot2 smartspot2 added the enhancement New feature or request label Jun 6, 2022
@smartspot2 smartspot2 changed the title Feat/archiving/main Archiving Jun 9, 2022
@@ -1,7634 +1,8 @@
{
"name": "csm_web",
"version": "1.0.0",
"lockfileVersion": 2,
"lockfileVersion": 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you have an outdated version of node, which changes the lockfile version here; update your node and revert these changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants