-
Notifications
You must be signed in to change notification settings - Fork 4.3k
System defined taxonomies #32869
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
bradenmacdonald
merged 14 commits into
openedx:master
from
open-craft:chris/smart-system-defined-taxonomies
Aug 2, 2023
Merged
System defined taxonomies #32869
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c9d90f2
feat: System defined taxonomies
ChrisChV 3cf4fff
style: models.py moved to models/base.py
ChrisChV a6f67cb
feat: New Content System defined models
ChrisChV f98325f
style: Lint and migration
ChrisChV 9ceac72
fix: Fix migration error
ChrisChV 778bf06
chore: Rebase and compile requirements
ChrisChV 8619120
refactor: adds ContentTaxonomyMixin for use when creating content sys…
pomegranited 8c6926a
fix: Tests
ChrisChV 1061e42
test: System defined model validations
ChrisChV c96b78f
fix: Move language taxonomy creation to openedx-learning
ChrisChV 4e8af72
style: Rename of OrganizationSystemDefinedTaxonomy
ChrisChV 51f2fc5
style: nits
ChrisChV 9bf3698
chore: Update openedx-learning dependency
ChrisChV 25dbf94
Merge branch 'master' into chris/smart-system-defined-taxonomies
ChrisChV 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
22 changes: 22 additions & 0 deletions
22
openedx/features/content_tagging/fixtures/system_defined.yaml
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,22 @@ | ||
| - model: oel_tagging.taxonomy | ||
| pk: -2 | ||
| fields: | ||
| name: Organizations | ||
| description: Allows tags for any organization ID created on the instance. | ||
| enabled: true | ||
| required: true | ||
| allow_multiple: false | ||
| allow_free_text: false | ||
| visible_to_authors: false | ||
| _taxonomy_class: openedx.features.content_tagging.models.ContentAuthorTaxonomy | ||
| - model: oel_tagging.taxonomy | ||
| pk: -3 | ||
| fields: | ||
| name: Content Authors | ||
| description: Allows tags for any user ID created on the instance. | ||
| enabled: true | ||
| required: true | ||
| allow_multiple: false | ||
| allow_free_text: false | ||
| visible_to_authors: false | ||
| _taxonomy_class: openedx.features.content_tagging.models.ContentOrganizationTaxonomy | ||
59 changes: 59 additions & 0 deletions
59
openedx/features/content_tagging/migrations/0002_system_defined_taxonomies.py
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,59 @@ | ||
| # Generated by Django 3.2.20 on 2023-07-31 21:07 | ||
|
|
||
| from django.db import migrations | ||
| import openedx.features.content_tagging.models.base | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('oel_tagging', '0005_language_taxonomy'), | ||
| ('content_tagging', '0001_initial'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name='ContentAuthorTaxonomy', | ||
| fields=[ | ||
| ], | ||
| options={ | ||
| 'proxy': True, | ||
| 'indexes': [], | ||
| 'constraints': [], | ||
| }, | ||
| bases=(openedx.features.content_tagging.models.base.ContentTaxonomyMixin, 'oel_tagging.usersystemdefinedtaxonomy'), | ||
| ), | ||
| migrations.CreateModel( | ||
| name='ContentLanguageTaxonomy', | ||
| fields=[ | ||
| ], | ||
| options={ | ||
| 'proxy': True, | ||
| 'indexes': [], | ||
| 'constraints': [], | ||
| }, | ||
| bases=(openedx.features.content_tagging.models.base.ContentTaxonomyMixin, 'oel_tagging.languagetaxonomy'), | ||
| ), | ||
| migrations.CreateModel( | ||
| name='ContentOrganizationTaxonomy', | ||
| fields=[ | ||
| ], | ||
| options={ | ||
| 'proxy': True, | ||
| 'indexes': [], | ||
| 'constraints': [], | ||
| }, | ||
| bases=(openedx.features.content_tagging.models.base.ContentTaxonomyMixin, 'oel_tagging.modelsystemdefinedtaxonomy'), | ||
| ), | ||
| migrations.CreateModel( | ||
| name='OrganizationModelObjectTag', | ||
| fields=[ | ||
| ], | ||
| options={ | ||
| 'proxy': True, | ||
| 'indexes': [], | ||
| 'constraints': [], | ||
| }, | ||
| bases=('oel_tagging.modelobjecttag',), | ||
| ), | ||
| ] |
39 changes: 39 additions & 0 deletions
39
openedx/features/content_tagging/migrations/0003_system_defined_fixture.py
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,39 @@ | ||
| # Generated by Django 3.2.20 on 2023-07-11 22:57 | ||
|
|
||
| from django.db import migrations | ||
| from django.core.management import call_command | ||
| from openedx.features.content_tagging.models import ContentLanguageTaxonomy | ||
|
|
||
|
|
||
| def load_system_defined_taxonomies(apps, schema_editor): | ||
| """ | ||
| Creates system defined taxonomies | ||
| """ | ||
|
|
||
| # Create system defined taxonomy instances | ||
| call_command('loaddata', '--app=content_tagging', 'system_defined.yaml') | ||
|
|
||
| # Adding taxonomy class to the language taxonomy | ||
| Taxonomy = apps.get_model('oel_tagging', 'Taxonomy') | ||
| language_taxonomy = Taxonomy.objects.get(id=-1) | ||
| language_taxonomy.taxonomy_class = ContentLanguageTaxonomy | ||
|
|
||
|
|
||
| def revert_system_defined_taxonomies(apps, schema_editor): | ||
| """ | ||
| Deletes all system defined taxonomies | ||
| """ | ||
| Taxonomy = apps.get_model('oel_tagging', 'Taxonomy') | ||
| Taxonomy.objects.get(id=-2).delete() | ||
| Taxonomy.objects.get(id=-3).delete() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ('content_tagging', '0002_system_defined_taxonomies'), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(load_system_defined_taxonomies, revert_system_defined_taxonomies), | ||
| ] |
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,13 @@ | ||
| """ | ||
| Content Tagging and System defined models | ||
| """ | ||
| from .base import ( | ||
| TaxonomyOrg, | ||
| ContentObjectTag, | ||
| ContentTaxonomy, | ||
| ) | ||
| from .system_defined import ( | ||
| ContentLanguageTaxonomy, | ||
| ContentAuthorTaxonomy, | ||
| ContentOrganizationTaxonomy, | ||
| ) |
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,75 @@ | ||
| """ | ||
| System defined models | ||
| """ | ||
| from typing import Type | ||
|
|
||
| from openedx_tagging.core.tagging.models import ( | ||
| ModelSystemDefinedTaxonomy, | ||
| ModelObjectTag, | ||
| UserSystemDefinedTaxonomy, | ||
| LanguageTaxonomy, | ||
| ) | ||
|
|
||
| from organizations.models import Organization | ||
| from .base import ContentTaxonomyMixin | ||
|
|
||
|
|
||
| class OrganizationModelObjectTag(ModelObjectTag): | ||
| """ | ||
| ObjectTags for the OrganizationSystemDefinedTaxonomy. | ||
| """ | ||
|
|
||
| class Meta: | ||
| proxy = True | ||
|
|
||
| @property | ||
| def tag_class_model(self) -> Type: | ||
| """ | ||
| Associate the organization model | ||
| """ | ||
| return Organization | ||
|
|
||
| @property | ||
| def tag_class_value(self) -> str: | ||
| """ | ||
| Returns the organization name to use it on Tag.value when creating Tags for this taxonomy. | ||
| """ | ||
| return "name" | ||
|
|
||
|
|
||
| class ContentOrganizationTaxonomy(ContentTaxonomyMixin, ModelSystemDefinedTaxonomy): | ||
| """ | ||
| Organization system-defined taxonomy that accepts ContentTags | ||
|
|
||
| Side note: The organization of an object is already encoded in its usage ID, | ||
| but a Taxonomy with Organization as Tags is being used so that the objects can be | ||
| indexed and can be filtered in the same tagging system, without any special casing. | ||
| """ | ||
|
|
||
| class Meta: | ||
| proxy = True | ||
|
|
||
| @property | ||
| def object_tag_class(self) -> Type: | ||
| """ | ||
| Returns OrganizationModelObjectTag as ObjectTag subclass associated with this taxonomy. | ||
| """ | ||
| return OrganizationModelObjectTag | ||
|
|
||
|
|
||
| class ContentLanguageTaxonomy(ContentTaxonomyMixin, LanguageTaxonomy): | ||
| """ | ||
| Language system-defined taxonomy that accepts ContentTags | ||
| """ | ||
|
|
||
| class Meta: | ||
| proxy = True | ||
|
|
||
|
|
||
| class ContentAuthorTaxonomy(ContentTaxonomyMixin, UserSystemDefinedTaxonomy): | ||
| """ | ||
| Author system-defined taxonomy that accepts ContentTags | ||
| """ | ||
|
|
||
| class Meta: | ||
| proxy = True |
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,71 @@ | ||
| """ | ||
| Test for Content models | ||
| """ | ||
| import ddt | ||
| from django.test.testcases import TestCase | ||
|
|
||
| from openedx_tagging.core.tagging.models import ( | ||
| ObjectTag, | ||
| Tag, | ||
| ) | ||
| from openedx_tagging.core.tagging.api import create_taxonomy | ||
| from ..models import ( | ||
| ContentLanguageTaxonomy, | ||
| ContentAuthorTaxonomy, | ||
| ContentOrganizationTaxonomy, | ||
| ) | ||
|
|
||
|
|
||
| @ddt.ddt | ||
| class TestSystemDefinedModels(TestCase): | ||
| """ | ||
| Test for System defined models | ||
| """ | ||
|
|
||
| @ddt.data( | ||
| (ContentLanguageTaxonomy, "taxonomy"), # Invalid object key | ||
| (ContentLanguageTaxonomy, "tag"), # Invalid external_id, invalid language | ||
| (ContentLanguageTaxonomy, "object"), # Invalid object key | ||
| (ContentAuthorTaxonomy, "taxonomy"), # Invalid object key | ||
| (ContentAuthorTaxonomy, "tag"), # Invalid external_id, User don't exits | ||
| (ContentAuthorTaxonomy, "object"), # Invalid object key | ||
| (ContentOrganizationTaxonomy, "taxonomy"), # Invalid object key | ||
| (ContentOrganizationTaxonomy, "tag"), # Invalid external_id, Organization don't exits | ||
| (ContentOrganizationTaxonomy, "object"), # Invalid object key | ||
| ) | ||
| @ddt.unpack | ||
| def test_validations( | ||
| self, | ||
| taxonomy_cls, | ||
| check, | ||
| ): | ||
| """ | ||
| Test that the respective validations are being called | ||
| """ | ||
| taxonomy = create_taxonomy( | ||
| name='Test taxonomy', | ||
| taxonomy_class=taxonomy_cls, | ||
| ) | ||
|
|
||
| tag = Tag( | ||
| value="value", | ||
| external_id="external_id", | ||
| taxonomy=taxonomy, | ||
| ) | ||
| tag.save() | ||
|
|
||
| object_tag = ObjectTag( | ||
| object_id='object_id', | ||
| taxonomy=taxonomy, | ||
| tag=tag, | ||
| ) | ||
|
|
||
| check_taxonomy = check == 'taxonomy' | ||
| check_object = check == 'object' | ||
| check_tag = check == 'tag' | ||
| assert not taxonomy.validate_object_tag( | ||
| object_tag=object_tag, | ||
| check_taxonomy=check_taxonomy, | ||
| check_object=check_object, | ||
| check_tag=check_tag, | ||
| ) |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.