diff --git a/stude/accounts/serializers.py b/stude/accounts/serializers.py index 2341c11..f9349e2 100644 --- a/stude/accounts/serializers.py +++ b/stude/accounts/serializers.py @@ -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() diff --git a/stude/subjects/models.py b/stude/subjects/models.py index 71ed920..d10b11c 100644 --- a/stude/subjects/models.py +++ b/stude/subjects/models.py @@ -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(