-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e116509
commit 1a7183d
Showing
19 changed files
with
482 additions
and
219 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import argparse | ||
import json | ||
import sys | ||
|
||
from django.core.management import BaseCommand | ||
from django.db import transaction | ||
|
||
from indigo_api.models import TaxonomyTopic | ||
|
||
|
||
class Command(BaseCommand): | ||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
"--root", type=str, help="Root of the taxonomy to import or export" | ||
) | ||
parser.add_argument( | ||
"--import", action="store_true", help="Import the taxonomy tree" | ||
) | ||
parser.add_argument( | ||
"--export", action="store_true", help="Export the taxonomy tree" | ||
) | ||
parser.add_argument( | ||
"infile", | ||
nargs="?", | ||
type=argparse.FileType("r"), | ||
default=sys.stdin, | ||
help="File to import from (JSON)", | ||
) | ||
parser.add_argument( | ||
"outfile", | ||
nargs="?", | ||
type=argparse.FileType("w"), | ||
default=sys.stdout, | ||
help="File to export to (JSON)", | ||
) | ||
|
||
def handle(self, *args, **kwargs): | ||
if kwargs["import"] and kwargs["export"]: | ||
raise ValueError("Specify only one of --import or --export") | ||
|
||
with transaction.atomic(): | ||
if kwargs["import"]: | ||
self.do_import(**kwargs) | ||
|
||
if kwargs["export"]: | ||
self.do_export(**kwargs) | ||
|
||
def do_import(self, **kwargs): | ||
root_node = None | ||
root = kwargs.get("root") | ||
if root: | ||
root_node = TaxonomyTopic.get_root_nodes().filter(name=root).first() | ||
if not root_node: | ||
root_node = TaxonomyTopic.add_root(name=root) | ||
data = json.load(kwargs["infile"]) | ||
TaxonomyTopic.load_bulk(data, parent=root_node) | ||
|
||
def do_export(self, **kwargs): | ||
root_node = None | ||
root = kwargs.get("root") | ||
if root: | ||
root_node = TaxonomyTopic.get_root_nodes().filter(name=root).first() | ||
if not root_node: | ||
raise ValueError("Root node not found: " + root) | ||
data = TaxonomyTopic.dump_bulk(root_node, keep_ids=False) | ||
json.dump(data, kwargs["outfile"]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<template> | ||
<la-table-of-contents-controller | ||
:items.prop="taxonomy_toc" | ||
collapse-all-btn-classes="btn btn-sm btn-secondary" | ||
expand-all-btn-classes="btn btn-sm btn-secondary" | ||
title-filter-clear-btn-classes="btn btn-sm btn-secondary" | ||
title-filter-input-classes="form-field" | ||
title-filter-placeholder="Filter by topic" | ||
:class="active" | ||
></la-table-of-contents-controller> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'TaxonomyTOC', | ||
data () { | ||
return { | ||
taxonomy_toc: JSON.parse(document.querySelector('#taxonomy_toc').textContent), | ||
}; | ||
}, | ||
mounted () { | ||
const params = new URLSearchParams(window.location.search); | ||
const toc = document.getElementsByTagName('la-table-of-contents-controller'); | ||
toc[0].addEventListener('itemRendered', (e) => { | ||
const tocItem = e.target; | ||
if (!tocItem) return; | ||
const anchor = tocItem.querySelector('.content__action__title'); | ||
const href = new URLSearchParams(anchor.getAttribute('href')); | ||
if (params.get('taxonomy_topic') === href.get('taxonomy_topic')) { | ||
anchor.classList.add('active'); | ||
} | ||
}); | ||
} | ||
}; | ||
</script> | ||
|
||
<style> | ||
.active { | ||
background-color: #2d7ad4; | ||
color: white; | ||
} | ||
</style> |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as DocumentTOCView } from './DocumentTOCView.vue'; | ||
export { default as LinterPopup } from './LinterPopup.vue'; | ||
export { default as TaxonomyTOC } from './TaxonomyTOC.vue'; |
Oops, something went wrong.