mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-24 17:02:18 +00:00
finshed inport old db untested
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -26,6 +26,7 @@ var/
|
|||||||
.installed.cfg
|
.installed.cfg
|
||||||
*.egg
|
*.egg
|
||||||
node_modules/
|
node_modules/
|
||||||
|
data/
|
||||||
|
|
||||||
# Continer extras
|
# Continer extras
|
||||||
.vagrant
|
.vagrant
|
||||||
|
|||||||
@@ -5,22 +5,21 @@ from django.core.management.base import BaseCommand
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from training import models
|
from training import models
|
||||||
|
#from RIGS import models.Profile
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
epoch = datetime.date(1970, 1, 1)
|
epoch = datetime.date(1970, 1, 1)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
self.import_Trainee()
|
|
||||||
self.import_TrainingCatagory()
|
self.import_TrainingCatagory()
|
||||||
self.import_TrainingItem()
|
self.import_TrainingItem()
|
||||||
self.import_TrainingItemQualification()
|
self.import_TrainingItemQualification()
|
||||||
self.import_TrainingLevel()
|
self.import_TrainingLevel()
|
||||||
self.import_TrainingLevelRequirement()
|
|
||||||
self.import_TrainingLevelQualification()
|
self.import_TrainingLevelQualification()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def xml_path(file):
|
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
|
@staticmethod
|
||||||
def parse_xml(file):
|
def parse_xml(file):
|
||||||
@@ -28,24 +27,6 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
return tree.getroot()
|
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):
|
def import_TrainingCatagory(self):
|
||||||
tally = [0, 0]
|
tally = [0, 0]
|
||||||
|
|
||||||
@@ -68,15 +49,17 @@ class Command(BaseCommand):
|
|||||||
def import_TrainingItem(self):
|
def import_TrainingItem(self):
|
||||||
tally = [0, 0]
|
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:
|
for child in root:
|
||||||
|
if child.find('active').text == '0': active = False
|
||||||
|
else: active = True
|
||||||
obj, created = models.TrainingItem.objects.update_or_create(
|
obj, created = models.TrainingItem.objects.update_or_create(
|
||||||
pk = int(child.find('ID').text),
|
pk = int(child.find('ID').text),
|
||||||
reference_number = int(child.find('Item_x0020_Number').text),
|
reference_number = int(child.find('Item_x0020_Number').text),
|
||||||
name = child.find('Item_x0020_Name').text,
|
name = child.find('Item_x0020_Name').text,
|
||||||
category = int(child.find('Category_x0020_ID').text)
|
category = models.TrainingCategory.objects.get(pk=int(child.find('Category_x0020_ID').text)),
|
||||||
#active?
|
active = active
|
||||||
)
|
)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
@@ -99,7 +82,7 @@ class Command(BaseCommand):
|
|||||||
trainee = int(child.find('Member_ID').text),
|
trainee = int(child.find('Member_ID').text),
|
||||||
depth = 0,
|
depth = 0,
|
||||||
date = child.find('Traning_Started_Date').text,
|
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
|
notes = child.find('Training_Started_Notes').text
|
||||||
)
|
)
|
||||||
if child.find('Traning_Complete_Date').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]))
|
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):
|
def import_TrainingLevelQualification(self):
|
||||||
tally = [0, 0]
|
tally = [0, 0]
|
||||||
|
|
||||||
|
|||||||
18
training/migrations/0008_trainingitem_active.py
Normal file
18
training/migrations/0008_trainingitem_active.py
Normal file
@@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -58,6 +58,7 @@ class TrainingItem(models.Model):
|
|||||||
reference_number = models.CharField(max_length=3)
|
reference_number = models.CharField(max_length=3)
|
||||||
category = models.ForeignKey('TrainingCategory', related_name='items', on_delete=models.RESTRICT)
|
category = models.ForeignKey('TrainingCategory', related_name='items', on_delete=models.RESTRICT)
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
active = models.BooleanField(default = True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def number(self):
|
def number(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user