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

Update list importer exporter & tests #38

Merged
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions arches_references/management/commands/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def import_controlled_lists(self, source):
wb = openpyxl.load_workbook(source)
with transaction.atomic():
for sheet in wb.sheetnames:
if sheet == "ControlledList":
if sheet == "List":
created_instances_pks.extend(
self.import_sheet_to_model(wb[sheet], List)
)
elif sheet == "ControlledListItem":
elif sheet == "ListItem":
created_instances_pks.extend(
self.import_sheet_to_model(wb[sheet], ListItem)
)
elif sheet == "ControlledListItemValue":
elif sheet == "ListItemValue":
created_instances_pks.extend(
self.import_sheet_to_model(wb[sheet], ListItemValue)
)
Expand Down Expand Up @@ -146,7 +146,7 @@ def import_sheet_to_model(self, sheet, model):
def export_controlled_lists(self, data_dest, file_name):
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "ControlledList"
ws.title = "List"
self.export_model_to_sheet(ws, List)
self.export_model_to_sheet(wb, ListItem)
self.export_model_to_sheet(wb, ListItemValue)
Expand All @@ -155,14 +155,14 @@ def export_controlled_lists(self, data_dest, file_name):
# data_dest = os.path.dirname(settings.SYSTEM_SETTINGS_LOCAL_PATH)
if data_dest != "" and data_dest != ".":
wb.save(os.path.join(data_dest, file_name))
self.stdout.write("Data exported successfully to controlled_lists.xlsx")
self.stdout.write(f"Data exported successfully to {file_name}")
else:
self.stdout.write(
"No destination directory specified. Please rerun this command with the '-d' parameter populated."
)

def export_model_to_sheet(self, wb, model):
# For the first sheet (ControlledList), use blank sheet that is initiallized with workbook
# For the first sheet (List), use blank sheet that is initiallized with workbook
# otherwise, append a new sheet
if isinstance(wb, openpyxl.worksheet.worksheet.Worksheet):
ws = wb
Expand Down
20 changes: 0 additions & 20 deletions arches_references/search_indexes/sample_index.py

This file was deleted.

1 change: 1 addition & 0 deletions arches_references/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"corsheaders",
"oauth2_provider",
"django_celery_results",
"arches_vue_utils",
# "silk",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import ListHeader from "@/arches_references/components/misc/ListHeader.vue";
import MainSplitter from "@/arches_references/components/MainSplitter.vue";
import type { Ref } from "vue";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type { Selectable } from "@/arches_references/types";
const router = useRouter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { dataIsNew, shouldUseContrast } from "@/arches_references/utils.ts";
import type { Ref } from "vue";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type {
ControlledListItem,
Value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { bestLabel } from "@/arches_references/utils.ts";
import LetterCircle from "@/arches_references/components/misc/LetterCircle.vue";
import type { Ref } from "vue";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type { ControlledListItem } from "@/arches_references/types";
const selectedLanguage = inject(selectedLanguageKey) as Ref<Language>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { bestLabel, dataIsList } from "@/arches_references/utils.ts";
import type { Ref } from "vue";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type {
ControlledList,
ControlledListItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { bestLabel, shouldUseContrast } from "@/arches_references/utils.ts";
import type { Ref } from "vue";
import type { TreeSelectionKeys } from "primevue/tree";
import type { TreeNode } from "primevue/treenode";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
const isMultiSelecting = defineModel<boolean>("isMultiSelecting", {
required: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import type { Ref } from "vue";
import type { TreeSelectionKeys } from "primevue/tree";
import type { TreeNode } from "primevue/treenode";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type {
ControlledList,
ControlledListItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { RouteLocationNormalizedLoadedGeneric } from "vue-router";
import type { TreePassThroughMethodOptions } from "primevue/tree";
import type { TreeExpandedKeys, TreeSelectionKeys } from "primevue/tree";
import type { TreeNode } from "primevue/treenode";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type {
ControlledList,
ControlledListItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import type { Ref } from "vue";
import type { TreeExpandedKeys, TreeSelectionKeys } from "primevue/tree";
import type { TreeNode } from "primevue/treenode";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type {
ControlledList,
ControlledListItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { shouldUseContrast } from "@/arches_references/utils.ts";
import type { Ref } from "vue";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
const { $gettext } = useGettext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import MoveRow from "@/arches_references/components/tree/MoveRow.vue";
import type { Ref } from "vue";
import type { TreeExpandedKeys, TreeSelectionKeys } from "primevue/tree";
import type { TreeNode } from "primevue/treenode";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type {
ControlledList,
ControlledListItem,
Expand Down
2 changes: 1 addition & 1 deletion arches_references/src/arches_references/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { InjectionKey, Ref } from "vue";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type {
ControlledList,
ControlledListItem,
Expand Down
2 changes: 1 addition & 1 deletion arches_references/src/arches_references/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import arches from "arches";

import type { TreeNode } from "primevue/treenode";
import type { Language } from "@/arches/types";
import type { Language } from "@/arches_vue_utils/types";
import type {
ControlledList,
ControlledListItem,
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ classifiers = [
requires-python = ">=3.10"
dependencies = [
"arches @ git+https://github.com/archesproject/arches.git@dev/8.0.x",
"arches-vue-utils @ git+https://github.com/archesproject/arches-vue-utils.git@main",
]
version = "0.0.1"

Expand Down
6 changes: 4 additions & 2 deletions tests/cli_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ def test_import_controlled_list(self):
source=input_file,
stdout=output,
)
list_pk = "e962bdaf-8243-4fbb-bd43-39bc1f54c168"
self.assertTrue(List.objects.filter(pk=list_pk).exists())

self.assertEqual(List.objects.all().count(), 2)
self.assertEqual(ListItem.objects.all().count(), 10)
self.assertEqual(ListItemValue.objects.all().count(), 21)

### TODO Add test for creating new language if language code not in db but found in import file

Expand Down
Binary file modified tests/fixtures/data/controlled_lists.xlsx
Binary file not shown.
Loading