Skip to content

Commit

Permalink
import cda_title
Browse files Browse the repository at this point in the history
  • Loading branch information
urchinpro committed Dec 1, 2024
1 parent c6b1780 commit f935615
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions external_system/management/commands/cda_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.core.management.base import BaseCommand
from openpyxl import load_workbook

from external_system.models import ProfessionsWorkersPositionsRefbook, CdaFields


class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('path', type=str)

def handle(self, *args, **kwargs):
"""
:param path - xlsx файл с CDA-titles столбцами:
NAME
"""
fp = kwargs["path"]
wb = load_workbook(filename=fp)
ws = wb[wb.sheetnames[0]]
starts = False

title, doc_refferal, extract = '', '', ''
for row in ws.rows:
is_doc_refferal = False
is_extract = False
cells = [str(x.value) for x in row]
if not starts:
if "NAME" in cells:
title = cells.index("NAME")
doc_refferal = cells.index("doc_refferal")
extract = cells.index("extract")
starts = True
else:
cda = CdaFields.objects.filter(title=cells[title])
if not cda.exists():
if doc_refferal == 1:
is_doc_refferal = True
if extract == 1:
is_extract = True
CdaFields(title=cells[title], is_doc_refferal=is_doc_refferal, is_extract=is_extract).save()
self.stdout.write('сохранено', cells[title])

0 comments on commit f935615

Please sign in to comment.