mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-18 05:52:15 +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
|
||||
*.egg
|
||||
node_modules/
|
||||
data/
|
||||
|
||||
# Continer extras
|
||||
.vagrant
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
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)
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user