forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add language auto-tagging with feature flag (openedx#32907)
- Loading branch information
Showing
15 changed files
with
636 additions
and
102 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
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 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 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 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 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 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 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
Oops, something went wrong.