Improved code for uupdating course year level and semester for student and for postmigration generation of subjects per course

This commit is contained in:
Keannu Bernasol 2023-07-18 22:15:42 +08:00
parent 41b2747495
commit bf9ed11a9e
2 changed files with 14 additions and 15 deletions

View file

@ -50,10 +50,10 @@ class CustomUserSerializer(BaseUserSerializer):
# First, we'll remove all the existing subjects from the user
print(validated_data)
# If course, year_level, or semester is changed
if ('course' in validated_data or 'year_level' in validated_data or 'semester' in validated_data):
if (instance.course is not validated_data['course'] or
instance.year_level is not validated_data['year_level'] or
instance.semester is not validated_data['semester']):
if any(field in validated_data for field in ['course', 'year_level', 'semester']):
if (instance.course != validated_data['course'] or
instance.year_level != validated_data['year_level'] or
instance.semester != validated_data['semester']):
# Clear all subjects
instance.subjects.clear()

View file

@ -96,19 +96,18 @@ def populate_subjects(sender, **kwargs):
subject_code = row[1]
subject_name = row[2]
# Skip ROTC/NSTP Subjects
if ('NSTP' in subject_code or 'ROTC' in subject_code or 'CWTS' in subject_code or 'LTS' in subject_code):
print('NSTP/ROTC subject', subject_name, 'omitted...')
ignored_subject_codes = ['NSTP', 'ROTC', 'CWTS', 'LTS']
ignored_subject_names = [
'PRACTICUM', 'On the Job Training', 'CAPSTONE', 'Capstone']
# Skip ignored subjects
if any(ignored_code in subject_code for ignored_code in ignored_subject_codes):
print('Ignored subject', subject_name,
'with code', subject_code)
continue
# Skip Practicum Subjects
if ('PRACTICUM' in subject_name or 'On the Job Training' in subject_name):
print('OJT subject', subject_name, 'omitted...')
continue
# Skip Capstone Subjects
if ('CAPSTONE' in subject_name or 'Capstone' in subject_name):
print('Capstone subject', subject_name, 'omitted...')
if any(ignored_name in subject_name for ignored_name in ignored_subject_names):
print('Ignored subject', subject_name,
'with code', subject_code)
continue
course = Course.objects.filter(