-
Notifications
You must be signed in to change notification settings - Fork 18
Taxonomy import templates [FC-0036] #89
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b9b390c
feat: ignore extra fields in import files
pomegranited 1041ea3
feat: adds CSV and JSON taxonomy import template files
pomegranited 1476d44
feat: adds view to download the template files
pomegranited 223f988
Merge branch 'main' into jill/taxonomy-templates
pomegranited ef78a3b
chore: bumps version
pomegranited File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,4 +1,4 @@ | ||
| """ | ||
| Open edX Learning ("Learning Core"). | ||
| """ | ||
| __version__ = "0.2.1" | ||
| __version__ = "0.2.2" |
This file contains hidden or 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 hidden or 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,30 @@ | ||
| id,value,parent_id,comments | ||
| WINDS,Wind instruments,,"This is an example Tag Import file, in CSV format." | ||
| PERCUSS,Percussion instruments,,"Only the 'id' and 'value' fields are required. They can be anything you like, but they must must be unique within the taxonomy. Existing tags matching 'id' will be updated on import." | ||
| ELECTRIC,Electronic instruments,,"Top-level tags have no 'parent_id', and you can have as many top-level tags as you wish." | ||
| STRINGS,String instruments,,"All other fields (like these 'comments') are ignored on import, and will not be included in subsequent tag exports." | ||
| BELLS,Idiophone,PERCUSS,"Providing a 'parent_id' creates a tag hierarchy." | ||
| DRUMS,Membranophone,PERCUSS,"The 'parent_id' must match an 'id' found earlier in the import file." | ||
| CAJÓN,Cajón,DRUMS,"Tag values may contain unicode characters." | ||
| PYLE,Pyle Stringed Jam Cajón,CAJÓN,"A tag hierarchy may contain as many as 3 levels. This tag is at level 4, and so it will not be shown to users." | ||
| THERAMIN,Theramin,ELECTRIC,"A tag hierarchy may contain uneven levels. Here, the Electronic branch has only 2 levels, while Percussion has 3." | ||
| CHORD,Chordophone,PERCUSS, | ||
| BRASS,Brass,WINDS, | ||
| WOODS,Woodwinds,WINDS, | ||
| FLUTE,Flute,WOODS, | ||
| PLUCK,Plucked strings,STRINGS, | ||
| MANDOLIN,Mandolin,PLUCK, | ||
| HARP,Harp,PLUCK, | ||
| BANJO,Banjo,PLUCK, | ||
| BOW,Bowed strings,STRINGS, | ||
| VIOLIN,Violin,BOW, | ||
| CELLO,Cello,BOW, | ||
| CLARINET,Clarinet,WOODS, | ||
| OBOE,Oboe,WOODS, | ||
| TRUMPET,Trumpet,BRASS, | ||
| TUBA,Tuba,BRASS, | ||
| SYNTH,Synthesizer,ELECTRIC, | ||
| CELESTA,Celesta,BELLS, | ||
| HI-HAT,Hi-hat,BELLS, | ||
| TABLA,Tabla,DRUMS, | ||
| PIANO,Piano,CHORD, |
158 changes: 158 additions & 0 deletions
158
openedx_tagging/core/tagging/import_export/template.json
This file contains hidden or 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,158 @@ | ||
| { | ||
| "tags": [ | ||
| { | ||
| "id": "WINDS", | ||
| "value": "Wind instruments", | ||
| "parent_id": "", | ||
| "comments": "This is an example Tag Import file, in JSON format." | ||
| }, | ||
| { | ||
| "id": "PERCUSS", | ||
| "value": "Percussion instruments", | ||
| "parent_id": "", | ||
| "comments": "Only the 'id' and 'value' fields are required. They can be anything you like, but they must must be unique within the taxonomy. Existing tags matching 'id' will be updated on import." | ||
| }, | ||
| { | ||
| "id": "ELECTRIC", | ||
| "value": "Electronic instruments", | ||
| "parent_id": "", | ||
| "comments": "Top-level tags have no 'parent_id', and you can have as many top-level tags as you wish." | ||
| }, | ||
| { | ||
| "id": "STRINGS", | ||
| "value": "String instruments", | ||
| "parent_id": "", | ||
| "comments": "All other fields (like these 'comments') are ignored on import, and will not be included in subsequent tag exports." | ||
| }, | ||
| { | ||
| "id": "BELLS", | ||
| "value": "Idiophone", | ||
| "parent_id": "PERCUSS", | ||
| "comments": "Providing a 'parent_id' creates a tag hierarchy." | ||
| }, | ||
| { | ||
| "id": "DRUMS", | ||
| "value": "Membranophone", | ||
| "parent_id": "PERCUSS", | ||
| "comments": "The 'parent_id' must match an 'id' found earlier in the import file." | ||
| }, | ||
| { | ||
| "id": "CAJÓN", | ||
| "value": "Cajón", | ||
| "parent_id": "DRUMS", | ||
| "comments": "Tag values may contain unicode characters." | ||
| }, | ||
| { | ||
| "id": "PYLE", | ||
| "value": "Pyle Stringed Jam Cajón", | ||
| "parent_id": "CAJÓN", | ||
| "comments": "A tag hierarchy may contain as many as 3 levels. This tag is at level 4, and so it will not be shown to users." | ||
| }, | ||
| { | ||
| "id": "THERAMIN", | ||
| "value": "Theramin", | ||
| "parent_id": "ELECTRIC", | ||
| "comments": "A tag hierarchy may contain uneven levels. Here, the Electronic branch has only 2 levels, while Percussion has 3." | ||
| }, | ||
| { | ||
| "id": "CHORD", | ||
| "value": "Chordophone", | ||
| "parent_id": "PERCUSS" | ||
| }, | ||
| { | ||
| "id": "BRASS", | ||
| "value": "Brass", | ||
| "parent_id": "WINDS" | ||
| }, | ||
| { | ||
| "id": "WOODS", | ||
| "value": "Woodwinds", | ||
| "parent_id": "WINDS" | ||
| }, | ||
| { | ||
| "id": "FLUTE", | ||
| "value": "Flute", | ||
| "parent_id": "WOODS" | ||
| }, | ||
| { | ||
| "id": "PLUCK", | ||
| "value": "Plucked strings", | ||
| "parent_id": "STRINGS" | ||
| }, | ||
| { | ||
| "id": "MANDOLIN", | ||
| "value": "Mandolin", | ||
| "parent_id": "PLUCK" | ||
| }, | ||
| { | ||
| "id": "HARP", | ||
| "value": "Harp", | ||
| "parent_id": "PLUCK" | ||
| }, | ||
| { | ||
| "id": "BANJO", | ||
| "value": "Banjo", | ||
| "parent_id": "PLUCK" | ||
| }, | ||
| { | ||
| "id": "BOW", | ||
| "value": "Bowed strings", | ||
| "parent_id": "STRINGS" | ||
| }, | ||
| { | ||
| "id": "VIOLIN", | ||
| "value": "Violin", | ||
| "parent_id": "BOW" | ||
| }, | ||
| { | ||
| "id": "CELLO", | ||
| "value": "Cello", | ||
| "parent_id": "BOW" | ||
| }, | ||
| { | ||
| "id": "CLARINET", | ||
| "value": "Clarinet", | ||
| "parent_id": "WOODS" | ||
| }, | ||
| { | ||
| "id": "OBOE", | ||
| "value": "Oboe", | ||
| "parent_id": "WOODS" | ||
| }, | ||
| { | ||
| "id": "TRUMPET", | ||
| "value": "Trumpet", | ||
| "parent_id": "BRASS" | ||
| }, | ||
| { | ||
| "id": "TUBA", | ||
| "value": "Tuba", | ||
| "parent_id": "BRASS" | ||
| }, | ||
| { | ||
| "id": "SYNTH", | ||
| "value": "Synthesizer", | ||
| "parent_id": "ELECTRIC" | ||
| }, | ||
| { | ||
| "id": "CELESTA", | ||
| "value": "Celesta", | ||
| "parent_id": "BELLS" | ||
| }, | ||
| { | ||
| "id": "HI-HAT", | ||
| "value": "Hi-hat", | ||
| "parent_id": "BELLS" | ||
| }, | ||
| { | ||
| "id": "TABLA", | ||
| "value": "Tabla", | ||
| "parent_id": "DRUMS" | ||
| }, | ||
| { | ||
| "id": "PIANO", | ||
| "value": "Piano", | ||
| "parent_id": "CHORD" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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 hidden or 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,51 @@ | ||
| """ | ||
| Taxonomy Import views | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
|
|
||
| from django.http import FileResponse, Http404 | ||
| from rest_framework.request import Request | ||
| from rest_framework.views import APIView | ||
|
|
||
|
|
||
| class TemplateView(APIView): | ||
| """ | ||
| View which serves the static Taxonomy Import template files. | ||
|
|
||
| **Example Requests** | ||
| GET /tagging/rest_api/v1/import/template.csv | ||
| GET /tagging/rest_api/v1/import/template.json | ||
|
|
||
| **Query Returns** | ||
| * 200 - Success | ||
| * 404 - Template file not found | ||
| * 405 - Method not allowed | ||
| """ | ||
| http_method_names = ['get'] | ||
|
|
||
| template_dir = os.path.join( | ||
| os.path.dirname(__file__), | ||
| "../../import_export/", | ||
| ) | ||
| allowed_ext_to_content_type = { | ||
| "csv": "text/csv", | ||
| "json": "application/json", | ||
| } | ||
|
|
||
| def get(self, request: Request, file_ext: str, *args, **kwargs) -> FileResponse: | ||
| """ | ||
| Downloads the requested file as an attachment, | ||
| or raises 404 if not found. | ||
| """ | ||
| content_type = self.allowed_ext_to_content_type.get(file_ext) | ||
| if not content_type: | ||
| raise Http404 | ||
|
|
||
| filename = f"template.{file_ext}" | ||
| content_disposition = f'attachment; filename="{filename}"' | ||
| fh = open(os.path.join(self.template_dir, filename), "rb") | ||
| response = FileResponse(fh, content_type=content_type) | ||
| response['Content-Disposition'] = content_disposition | ||
| return response |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
tag_data[opt_field]is falsy (i.e. 0), we are overriding withNone.I don't think this is a problem because our
optional_fieldsonly have the external_id, but we may have some issues using this parser for other things.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rpenido Yeah, I was preserving the previous behavior with that change, since the CSV parser will send us empty strings for
parent_id, when what we really want isNone.I think that if we ever need the parser to do something different, then there will be a clear use case, and the code and tests can be modified then.