-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into import-tubes
- Loading branch information
Showing
14 changed files
with
191 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
clients/management/commands/import_nsi_harmfull_factors.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from django.core.management.base import BaseCommand | ||
from openpyxl import load_workbook | ||
|
||
from clients.models import HarmfulFactor | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('path', type=str) | ||
|
||
def handle(self, *args, **kwargs): | ||
""" | ||
:param path - xlsx файл со столбцами: | ||
Идентификатор | ||
Код | ||
Наименование | ||
""" | ||
|
||
fp = kwargs["path"] | ||
self.stdout.write("Path: " + fp) | ||
wb = load_workbook(filename=fp) | ||
ws = wb[wb.sheetnames[0]] | ||
starts = False | ||
harmfull_title, description = '', '' | ||
for row in ws.rows: | ||
cells = [str(x.value) for x in row] | ||
if not starts: | ||
if "ИД" in cells: | ||
nsi_id = cells.index("ИД") | ||
description = cells.index("Описание") | ||
harmfull_title = cells.index("Номер") | ||
starts = True | ||
else: | ||
harmful_factor = HarmfulFactor.objects.filter(title=cells[harmfull_title]).first() | ||
if harmful_factor: | ||
harmful_factor.nsi_id = cells[nsi_id] | ||
harmful_factor.save() | ||
self.stdout.write(f'Фактор {harmful_factor.title} обновлён, nsi_id={harmful_factor.nsi_id}') | ||
else: | ||
new_harmful_factor = HarmfulFactor(title=cells[harmfull_title], description=cells[description], nsi_id=cells[nsi_id]) | ||
new_harmful_factor.save() | ||
self.stdout.write(f'Фактор {cells[harmfull_title]} добавлен') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
external_system/management/commands/professions_workers_position_import.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.core.management.base import BaseCommand | ||
from openpyxl import load_workbook | ||
|
||
from external_system.models import ProfessionsWorkersPositionsRefbook | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument('path', type=str) | ||
|
||
def handle(self, *args, **kwargs): | ||
""" | ||
:param path - xlsx файл с ФСЛИ со столбцами: | ||
ID, | ||
NAME | ||
""" | ||
fp = kwargs["path"] | ||
self.stdout.write("Path: " + fp) | ||
wb = load_workbook(filename=fp) | ||
ws = wb[wb.sheetnames[0]] | ||
starts = False | ||
|
||
id_position, name_position = '', '' | ||
for row in ws.rows: | ||
cells = [str(x.value) for x in row] | ||
if not starts: | ||
if "ID" in cells: | ||
id_position = cells.index("ID") | ||
name_position = cells.index("NAME") | ||
starts = True | ||
else: | ||
r = ProfessionsWorkersPositionsRefbook.objects.filter(code=cells[id_position]) | ||
if not r.exists(): | ||
ProfessionsWorkersPositionsRefbook(code=cells[id_position], title=cells[name_position]).save() | ||
self.stdout.write('сохранено', cells[name_position]) | ||
elif r.exists(): | ||
r = r[0] | ||
updated = [] | ||
if r.title != cells[name_position]: | ||
r.title = cells[name_position] | ||
updated.append('title') | ||
if updated: | ||
r.save(update_fields=updated) | ||
self.stdout.write('обновлено', cells[name_position]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters