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

Загрузка файлов - рефакторинг #4056

Merged
merged 9 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 1 addition & 2 deletions api/parse_file/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ def upload_file(request):
selected_form = request_data.get("selectedForm")
entity_id = request_data.get("entityId")
other_need_data = request_data.get("otherNeedData")
data = {"file": file, "selectedForm": selected_form, "entity_id": entity_id, "other_need_data": other_need_data}
data = {"file": file, "selected_form": selected_form, "entity_id": entity_id, "other_need_data": other_need_data}
function = import_string(selected_form)
result = function(
request_data={
Expand All @@ -921,7 +921,6 @@ def upload_file(request):
}
)
except Exception as e:
# todo - Выводить структуру файла которая нужна, если передано не-то
exception_string = f"{e}"
stdout.write(exception_string)
return JsonResponse({"ok": False, "result": [], "message": exception_string})
Expand Down
45 changes: 20 additions & 25 deletions l2-frontend/src/components/types-and-forms-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,29 @@ export default function typesAndForms() {
'api.laboratory.forms100.form_01': { id: 'api.laboratory.forms100.form_01', label: 'Загрузка PDF результата из QMS' },
},
});
// todo - UploadResult + forms - получать только выбранные isResult функции (протестировать)
const getForms = (type: string, forms: string[] = null, onlyResult = false, allowedForms: string[] = null): formsFile[] => {
/* onlyResult - Выдаст только формы находящиеся в isResultForm, allowedForms - выдаст только те функции которые разрешены */
const addForms = (type: string, forms = null, allowedForms: string[] = null) => {
const result: formsFile[] = [];
for (const form of forms) {
if (allowedForms.includes(form) && fileForms.value[type][form]) {
result.push(fileForms.value[type][form]);
}
}
return result;
};

const getForms = (type: string, forms: string[] = null, onlyResult = false, allowedForms: string[] = null): formsFile[] => {
let result: formsFile[] = [];
if (!allowedForms) {
return result;
return [];
}
if (forms && forms.length > 0) { // Если переданы формы
for (const form of forms) {
if (!onlyResult && fileForms.value[type][form] && allowedForms.includes(form)) {
result.push(fileForms.value[type][form]);
} else if (onlyResult && isResultForm.value.includes(form) && allowedForms.includes(form)) {
result.push(fileForms.value[type][form]);
}
}
} else if (!forms && onlyResult) { // если нет форм, но, есть "только результат"
for (const form of isResultForm.value) {
if (fileForms.value[type][form] && allowedForms.includes(form)) {
result.push(fileForms.value[type][form]);
}
}
} else { // Если нет форм и "только результат" - выдать всё разрешенное
const tmpResult = Object.values(fileForms.value[type]);
for (const form of tmpResult) {
if (allowedForms.includes(String(form))) {
result.push(fileForms.value[type][form]);
}
}
if (forms) {
result = addForms(type, forms, allowedForms);
} else if (onlyResult) {
result = addForms(type, isResultForm.value, allowedForms);
} else {
const tmp: formsFile[] = Object.values(fileForms.value[type]);
const tmpResult = tmp.map(obj => obj.id);
result = addForms(type, tmpResult, allowedForms);
}
return result;
};
Expand Down
Loading