update importers
diff --git a/plstackapi/importer/plclassic/slice_importer.py b/plstackapi/importer/plclassic/slice_importer.py
index 02247f1..4f7504d 100644
--- a/plstackapi/importer/plclassic/slice_importer.py
+++ b/plstackapi/importer/plclassic/slice_importer.py
@@ -1,25 +1,41 @@
-from PLC.Slices import Slices
-from models import Slice
+from plstackapi.core.models import Slice
class SliceImporter:
- def __init__(self, importer):
- self.importer = importer
- self.slices = {}
+ def __init__(self, api):
+ self.api = api
+ self.remote_slices = {}
+ self.local_slices = {}
- def run(self):
- slices = Slices(self.importer.api)
+ def run(self, remote_sites={}, local_sites={}):
+ if not remote_sites:
+ sites = self.api.GetSites()
+ for site in sites:
+ remote_sites[site['site_id']] = site
+
+ if not local_sites:
+ from models import Site
+ sites = Site.objects.all()
+ for site in sites:
+ local_sites[site.login_base] = site
+
db_slices = Slice.objects.all()
- slice_names = [s['name'] for s in db_slices]
+ for db_slice in db_slices:
+ self.local_slices[db_slice.name] = db_slice
+
+ slices = api.GetSlices()
for slice in slices:
- if slice['name'] not in slice_names:
+ self.remote_slice[slice['slice_id']] = slice
+ if slice['name'] not in self.local_slices:
+ site = local_sites[remote_sites[slice['site_id']]['login_base']]
new_slices = Slice(name=slice['name'],
instantiation=slice['instantiation'],
omf_friendly = False,
description = slice['description'],
- slice_url = slice['url'])
- new_slice.save();
- self.slices[slice['slice_id']] = slice
+ slice_url = slice['url'],
+ site = site)
+ new_slice.save()
+ self.local_slices[new_slice.name] = new_slice