-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat: add language auto-tagging #32907
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 53 commits into
openedx:master
from
open-craft:rpenido/fal-3460-content-auto-tagging-by-system-taxonomies
Sep 1, 2023
Merged
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
47af3bf
chore: update requirements
rpenido 4ed15f5
feat: Add retrieve object_tags REST API (#577)
yusuf-musleh 2bc5070
feat: add content auto-tagging (language)
rpenido 0f62355
chore: add __init__.py
rpenido 04b6282
Merge branch 'master' into rpenido/fal-3460-content-auto-tagging-by-s…
rpenido b06e2bb
style: fix pep8
rpenido d6bc300
style: fix pylint
rpenido 9017818
style: fix pep8
rpenido ee179b1
test: fix query count and comments
rpenido 858f263
test: fix query count
rpenido ea2e149
fix: add try..except
rpenido fe05c57
fix: fix exit condition to avoid error
rpenido 5bddde6
test: fix query count
rpenido e0d816a
Merge branch 'master' into rpenido/fal-3460-content-auto-tagging-by-s…
rpenido 56300b7
refactor: change fixture to migration
rpenido 901f4d3
test: fix setup
rpenido 09dea58
chore: trigger CD/CI
rpenido 5e7b097
test: trying to fix race condition
rpenido a08f08a
test: fix query count
rpenido 08cd8b5
style: fixed pylint
rpenido 778552a
docs: fix docstring from review
rpenido 975edfd
test: remove override_settings
rpenido 70650e9
refactor: add typings
rpenido 75f4b70
style: add typings
rpenido e6dbd52
fix: import annotations
rpenido 7097dd4
test: refactor tests
rpenido 2a6bcaf
refactor: fix tests and cleaning code
rpenido fabb4aa
revert: revert changes in api
rpenido 7adcd8b
refactor: cleaning code
rpenido 9f5f538
fix: pylint
rpenido c9e77e3
fix: patch tasks.modulestore and change replicaSet config
rpenido 7213778
fix: pylint
rpenido b66a51b
test: change scope
rpenido 28c6b88
fix: import
rpenido 3021492
test: add replicaset config for lms
rpenido 14db0ef
refactor: cleaning code
rpenido 5f452b4
test: fix query count
rpenido 5421f87
test: fix query count
rpenido f711c61
fix: remove Org Taxonomy in migration
rpenido 6df7303
style: add empty space
rpenido ce23eb1
refactor: rename _update_tags to _set_initial_language_tag
rpenido eb9f2c0
refactor: fix types
rpenido a99b725
fix: remove ContentOrganizationTaxonomy
rpenido f174ece
feat: use default language if course.language not found
rpenido 2ccdeb5
Revert "test: add replicaset config for lms"
rpenido 1c27f65
feat: add CONTENT_TAGGING_AUTO WaffleSwitch
rpenido 5200966
revert: revert changes in test_mixed_modulestore
rpenido 2612fe9
style: remove unused import
rpenido 5fc811d
test: add invalid tags tests
rpenido 154a4ae
refactor: change WaffleSwitch to CourseWaffleFlag
rpenido 6efc2c2
Merge branch 'master' into rpenido/fal-3460-content-auto-tagging-by-s…
rpenido 1a1b634
test: fix query count
rpenido 68c911a
Merge branch 'master' into rpenido/fal-3460-content-auto-tagging-by-s…
rpenido 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
22 changes: 0 additions & 22 deletions
22
openedx/features/content_tagging/fixtures/system_defined.yaml
This file was deleted.
Oops, something went wrong.
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,76 @@ | ||
""" | ||
Automatic tagging of content | ||
""" | ||
|
||
import logging | ||
|
||
from django.dispatch import receiver | ||
from openedx_events.content_authoring.data import CourseData, XBlockData | ||
from openedx_events.content_authoring.signals import COURSE_CREATED, XBLOCK_CREATED, XBLOCK_DELETED, XBLOCK_UPDATED | ||
|
||
from .tasks import delete_course_tags | ||
from .tasks import ( | ||
delete_xblock_tags, | ||
update_course_tags, | ||
update_xblock_tags | ||
) | ||
from .toggles import CONTENT_TAGGING_AUTO | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@receiver(COURSE_CREATED) | ||
def auto_tag_course(**kwargs): | ||
""" | ||
Automatically tag course based on their metadata | ||
""" | ||
course_data = kwargs.get("course", None) | ||
if not course_data or not isinstance(course_data, CourseData): | ||
log.error("Received null or incorrect data for event") | ||
return | ||
|
||
if not CONTENT_TAGGING_AUTO.is_enabled(course_data.course_key): | ||
return | ||
|
||
update_course_tags.delay(str(course_data.course_key)) | ||
|
||
|
||
@receiver(XBLOCK_CREATED) | ||
@receiver(XBLOCK_UPDATED) | ||
def auto_tag_xblock(**kwargs): | ||
""" | ||
Automatically tag XBlock based on their metadata | ||
""" | ||
xblock_info = kwargs.get("xblock_info", None) | ||
if not xblock_info or not isinstance(xblock_info, XBlockData): | ||
log.error("Received null or incorrect data for event") | ||
return | ||
|
||
if not CONTENT_TAGGING_AUTO.is_enabled(xblock_info.usage_key.course_key): | ||
return | ||
|
||
if xblock_info.block_type == "course": | ||
# Course update is handled by XBlock of course type | ||
update_course_tags.delay(str(xblock_info.usage_key.course_key)) | ||
|
||
update_xblock_tags.delay(str(xblock_info.usage_key)) | ||
|
||
|
||
@receiver(XBLOCK_DELETED) | ||
def delete_tag_xblock(**kwargs): | ||
""" | ||
Automatically delete XBlock auto tags. | ||
""" | ||
xblock_info = kwargs.get("xblock_info", None) | ||
if not xblock_info or not isinstance(xblock_info, XBlockData): | ||
log.error("Received null or incorrect data for event") | ||
return | ||
|
||
if not CONTENT_TAGGING_AUTO.is_enabled(xblock_info.usage_key.course_key): | ||
return | ||
|
||
if xblock_info.block_type == "course": | ||
# Course deletion is handled by XBlock of course type | ||
delete_course_tags.delay(str(xblock_info.usage_key.course_key)) | ||
|
||
delete_xblock_tags.delay(str(xblock_info.usage_key)) |
41 changes: 33 additions & 8 deletions
41
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
49 changes: 49 additions & 0 deletions
49
openedx/features/content_tagging/migrations/0004_system_defined_org.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,49 @@ | ||
from django.db import migrations | ||
|
||
|
||
def load_system_defined_org_taxonomies(apps, _schema_editor): | ||
""" | ||
Associates the system defined taxonomy Language (id=-1) to all orgs and | ||
removes the ContentOrganizationTaxonomy (id=-3) from the database | ||
""" | ||
TaxonomyOrg = apps.get_model("content_tagging", "TaxonomyOrg") | ||
TaxonomyOrg.objects.create(id=-1, taxonomy_id=-1, org=None) | ||
|
||
Taxonomy = apps.get_model("oel_tagging", "Taxonomy") | ||
Taxonomy.objects.get(id=-3).delete() | ||
|
||
|
||
|
||
|
||
def revert_system_defined_org_taxonomies(apps, _schema_editor): | ||
""" | ||
Deletes association of system defined taxonomy Language (id=-1) to all orgs and | ||
creates the ContentOrganizationTaxonomy (id=-3) in the database | ||
""" | ||
TaxonomyOrg = apps.get_model("content_tagging", "TaxonomyOrg") | ||
TaxonomyOrg.objects.get(id=-1).delete() | ||
|
||
Taxonomy = apps.get_model("oel_tagging", "Taxonomy") | ||
org_taxonomy = Taxonomy( | ||
pk=-3, | ||
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, | ||
) | ||
ContentOrganizationTaxonomy = apps.get_model("content_tagging", "ContentOrganizationTaxonomy") | ||
org_taxonomy.taxonomy_class = ContentOrganizationTaxonomy | ||
org_taxonomy.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("content_tagging", "0003_system_defined_fixture"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(load_system_defined_org_taxonomies, revert_system_defined_org_taxonomies), | ||
] |
19 changes: 19 additions & 0 deletions
19
openedx/features/content_tagging/migrations/0005_auto_20230830_1517.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,19 @@ | ||
# Generated by Django 3.2.20 on 2023-08-30 15:17 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('content_tagging', '0004_system_defined_org'), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name='ContentOrganizationTaxonomy', | ||
), | ||
migrations.DeleteModel( | ||
name='OrganizationModelObjectTag', | ||
), | ||
] |
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 |
---|---|---|
|
@@ -9,5 +9,4 @@ | |
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
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.