From e78decdf92db1db2827664720ae7566422716069 Mon Sep 17 00:00:00 2001 From: josephjboyden Date: Wed, 27 Oct 2021 14:04:01 +0100 Subject: [PATCH] finshed inport old db untested --- .gitignore | 1 + training/management/commands/import_old_db.py | 50 +++---------------- .../migrations/0008_trainingitem_active.py | 18 +++++++ training/models.py | 1 + 4 files changed, 28 insertions(+), 42 deletions(-) create mode 100644 training/migrations/0008_trainingitem_active.py diff --git a/.gitignore b/.gitignore index 79eef597..bea7e3b9 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ var/ .installed.cfg *.egg node_modules/ +data/ # Continer extras .vagrant diff --git a/training/management/commands/import_old_db.py b/training/management/commands/import_old_db.py index e4f1f779..44d58eb7 100644 --- a/training/management/commands/import_old_db.py +++ b/training/management/commands/import_old_db.py @@ -5,22 +5,21 @@ from django.core.management.base import BaseCommand from django.conf import settings from training import models +#from RIGS import models.Profile class Command(BaseCommand): epoch = datetime.date(1970, 1, 1) def handle(self, *args, **options): - self.import_Trainee() self.import_TrainingCatagory() self.import_TrainingItem() self.import_TrainingItemQualification() self.import_TrainingLevel() - self.import_TrainingLevelRequirement() self.import_TrainingLevelQualification() @staticmethod def xml_path(file): - return os.path.join(settings.BASE_DIR, 'data/DB_Dump/{}'.format(file)) + return os.path.join(settings.BASE_DIR, 'data/{}'.format(file)) @staticmethod def parse_xml(file): @@ -28,24 +27,6 @@ class Command(BaseCommand): return tree.getroot() - def import_Trainee(self): - tally = [0, 0] - - root = self.parse_xml(self.xml_path('Members.xml')) - - for child in root: - obj, created = models.Trainee.objects.update_or_create( - pk=int(child.find('ID').text) - name = child.find('Member_x0020_Name').text - ) - - if created: - tally[1] += 1 - else: - tally[0] += 1 - - print('Trainees - Updated: {}, Created: {}'.format(tally[0], tally[1])) - def import_TrainingCatagory(self): tally = [0, 0] @@ -68,15 +49,17 @@ class Command(BaseCommand): def import_TrainingItem(self): tally = [0, 0] - root = self.parse_xml(self.xml_path('Training Items.xml')) + root = self.parse_xml(self.xml_path('Training Items.xml')) for child in root: + if child.find('active').text == '0': active = False + else: active = True obj, created = models.TrainingItem.objects.update_or_create( pk = int(child.find('ID').text), reference_number = int(child.find('Item_x0020_Number').text), name = child.find('Item_x0020_Name').text, - category = int(child.find('Category_x0020_ID').text) - #active? + category = models.TrainingCategory.objects.get(pk=int(child.find('Category_x0020_ID').text)), + active = active ) if created: @@ -99,7 +82,7 @@ class Command(BaseCommand): trainee = int(child.find('Member_ID').text), depth = 0, date = child.find('Traning_Started_Date').text, - supervisor = int(child.find('Training_Started_Assessor_ID'),text), + supervisor = int(child.find('Training_Started_Assessor_ID').text), notes = child.find('Training_Started_Notes').text ) if child.find('Traning_Complete_Date').text != '': @@ -158,23 +141,6 @@ class Command(BaseCommand): print('Training Levels - Updated: {}, Created: {}'.format(tally[0], tally[1])) - def import_TrainingLevelRequirement(self): #? - tally = [0, 0] - - root = self.parse_xml(self.xml_path('')) - - for child in root: - obj, created = models.TrainingLevelRequirement.objects.update_or_create( - pk=int(child.find('ID').text) - ) - - if created: - tally[1] += 1 - else: - tally[0] += 1 - - print('Training Level Requirements - Updated: {}, Created: {}'.format(tally[0], tally[1])) - def import_TrainingLevelQualification(self): tally = [0, 0] diff --git a/training/migrations/0008_trainingitem_active.py b/training/migrations/0008_trainingitem_active.py new file mode 100644 index 00000000..f58ad9e7 --- /dev/null +++ b/training/migrations/0008_trainingitem_active.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.13 on 2021-10-27 12:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('training', '0007_auto_20210908_2043'), + ] + + operations = [ + migrations.AddField( + model_name='trainingitem', + name='active', + field=models.BooleanField(default=True), + ), + ] diff --git a/training/models.py b/training/models.py index 8327f00c..948a3a5e 100644 --- a/training/models.py +++ b/training/models.py @@ -58,6 +58,7 @@ class TrainingItem(models.Model): reference_number = models.CharField(max_length=3) category = models.ForeignKey('TrainingCategory', related_name='items', on_delete=models.RESTRICT) name = models.CharField(max_length=50) + active = models.BooleanField(default = True) @property def number(self):