Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import cda_title #4504

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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])