diff --git a/training/management/commands/import_old_db.py b/training/management/commands/import_old_db.py index bcaef245..7feb64cf 100644 --- a/training/management/commands/import_old_db.py +++ b/training/management/commands/import_old_db.py @@ -225,17 +225,16 @@ class Command(BaseCommand): for child in root: try: - if child.find('Training_x0020_Level_x0020_ID') is None: - print('Training Level Qualification #{} does not qualify in any level. How?'.format(child.find('ID').text)) + trainee = Profile.objects.get(pk=self.id_map[child.find('Member_x0020_ID').text]) if child.find('Member_x0020_ID') is not None else False + level = models.TrainingLevel.objects.get(pk=int(child.find('Training_x0020_Level_x0020_ID').text)) if child.find('Training_x0020_Level_x0020_ID') is not None else False + + if trainee and level: + obj, created = models.TrainingLevelQualification.objects.update_or_create(pk=int(child.find('ID').text), + trainee=trainee, + level=level) + else: + print('Training Level Qualification #{} failed to import. Trainee: {} and Level: {}'.format(child.find('ID').text, trainee, level)) continue - if child.find('Member_x0020_ID') is None: - print('Training Level Qualification #{} does not qualify anyone. How?!'.format(child.find('ID').text)) - continue - obj, created = models.TrainingLevelQualification.objects.update_or_create( - pk=int(child.find('ID').text), - trainee=Profile.objects.get(pk=self.id_map[child.find('Member_x0020_ID').text]), - level=models.TrainingLevel.objects.get(pk=int(child.find('Training_x0020_Level_x0020_ID').text)) - ) if child.find('Date_x0020_Level_x0020_Awarded') is not None: obj.confirmed_on = make_aware(datetime.datetime.strptime(child.find('Date_x0020_Level_x0020_Awarded').text.split('T')[0], "%Y-%m-%d")) diff --git a/training/migrations/0002_alter_traininglevel_options.py b/training/migrations/0002_alter_traininglevel_options.py new file mode 100644 index 00000000..75c5266e --- /dev/null +++ b/training/migrations/0002_alter_traininglevel_options.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.11 on 2022-01-05 12:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('training', '0001_initial'), + ] + + operations = [ + migrations.AlterModelOptions( + name='traininglevel', + options={'ordering': ['department', 'level']}, + ), + ] diff --git a/training/models.py b/training/models.py index 30ae4828..64f14529 100644 --- a/training/models.py +++ b/training/models.py @@ -152,6 +152,9 @@ class TrainingLevel(models.Model, RevisionMixin): prerequisite_levels = models.ManyToManyField('self', related_name='prerequisites', symmetrical=False, blank=True) icon = models.CharField(null=True, blank=True, max_length=20) + class Meta: + ordering = ["department", "level"] + @property def department_colour(self): if self.department == self.SOUND: diff --git a/training/templates/level_list.html b/training/templates/level_list.html index 824df330..e316aed9 100644 --- a/training/templates/level_list.html +++ b/training/templates/level_list.html @@ -4,6 +4,7 @@ {% load get_supervisor from tags %} {% block content %} +{% if request.user.is_staff %}
Please Note: