Skip to content

Commit a86d29f

Browse files
authored
feat!: Drop import_from_modulestore app (2/3 -- models) (#37240)
Part of: #37242
1 parent d2eba78 commit a86d29f

File tree

2 files changed

+66
-137
lines changed

2 files changed

+66
-137
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Generated by Django 4.2.23 on 2025-08-19 16:21
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('import_from_modulestore', '0001_initial'),
10+
]
11+
12+
operations = [
13+
migrations.AlterUniqueTogether(
14+
name='publishableentityimport',
15+
unique_together=None,
16+
),
17+
migrations.RemoveField(
18+
model_name='publishableentityimport',
19+
name='import_event',
20+
),
21+
migrations.RemoveField(
22+
model_name='publishableentityimport',
23+
name='resulting_change',
24+
),
25+
migrations.RemoveField(
26+
model_name='publishableentityimport',
27+
name='resulting_mapping',
28+
),
29+
migrations.AlterUniqueTogether(
30+
name='publishableentitymapping',
31+
unique_together=None,
32+
),
33+
migrations.RemoveField(
34+
model_name='publishableentitymapping',
35+
name='target_entity',
36+
),
37+
migrations.RemoveField(
38+
model_name='publishableentitymapping',
39+
name='target_package',
40+
),
41+
migrations.AlterUniqueTogether(
42+
name='stagedcontentforimport',
43+
unique_together=None,
44+
),
45+
migrations.RemoveField(
46+
model_name='stagedcontentforimport',
47+
name='import_event',
48+
),
49+
migrations.RemoveField(
50+
model_name='stagedcontentforimport',
51+
name='staged_content',
52+
),
53+
migrations.DeleteModel(
54+
name='Import',
55+
),
56+
migrations.DeleteModel(
57+
name='PublishableEntityImport',
58+
),
59+
migrations.DeleteModel(
60+
name='PublishableEntityMapping',
61+
),
62+
migrations.DeleteModel(
63+
name='StagedContentForImport',
64+
),
65+
]
Lines changed: 1 addition & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,3 @@
11
"""
2-
Models for the course to library import app.
2+
Models for the course to library import app (TO BE DELETED)
33
"""
4-
import uuid as uuid_tools
5-
6-
from django.contrib.auth import get_user_model
7-
from django.db import models
8-
from django.utils.translation import gettext_lazy as _
9-
10-
from model_utils.models import TimeStampedModel
11-
from opaque_keys.edx.django.models import (
12-
LearningContextKeyField,
13-
UsageKeyField,
14-
)
15-
from openedx_learning.api.authoring_models import LearningPackage, PublishableEntity
16-
17-
from .data import ImportStatus
18-
19-
User = get_user_model()
20-
21-
22-
class Import(TimeStampedModel):
23-
"""
24-
Represents the action of a user importing a modulestore-based course or legacy
25-
library into a learning-core based learning package (today, that is always a content library).
26-
"""
27-
28-
uuid = models.UUIDField(default=uuid_tools.uuid4, editable=False, unique=True)
29-
status = models.CharField(
30-
max_length=100,
31-
choices=ImportStatus.choices,
32-
default=ImportStatus.NOT_STARTED,
33-
db_index=True
34-
)
35-
user = models.ForeignKey(User, on_delete=models.CASCADE)
36-
37-
# Note: For now, this will always be a course key. In the future, it may be a legacy library key.
38-
source_key = LearningContextKeyField(help_text=_('The modulestore course'), max_length=255, db_index=True)
39-
target_change = models.ForeignKey(to='oel_publishing.DraftChangeLog', on_delete=models.SET_NULL, null=True)
40-
41-
class Meta:
42-
verbose_name = _('Import from modulestore')
43-
verbose_name_plural = _('Imports from modulestore')
44-
45-
def __str__(self):
46-
return f'{self.source_key}{self.target_change}'
47-
48-
def set_status(self, status: ImportStatus):
49-
"""
50-
Set import status.
51-
"""
52-
self.status = status
53-
self.save()
54-
if status in [ImportStatus.IMPORTED, ImportStatus.CANCELED]:
55-
self.clean_related_staged_content()
56-
57-
def clean_related_staged_content(self) -> None:
58-
"""
59-
Clean related staged content.
60-
"""
61-
for staged_content_for_import in self.staged_content_for_import.all():
62-
staged_content_for_import.staged_content.delete()
63-
64-
65-
class PublishableEntityMapping(TimeStampedModel):
66-
"""
67-
Represents a mapping between a source usage key and a target publishable entity.
68-
"""
69-
70-
source_usage_key = UsageKeyField(
71-
max_length=255,
72-
help_text=_('Original usage key/ID of the thing that has been imported.'),
73-
)
74-
target_package = models.ForeignKey(LearningPackage, on_delete=models.CASCADE)
75-
target_entity = models.ForeignKey(PublishableEntity, on_delete=models.CASCADE)
76-
77-
class Meta:
78-
unique_together = ('source_usage_key', 'target_package')
79-
80-
def __str__(self):
81-
return f'{self.source_usage_key}{self.target_entity}'
82-
83-
84-
class PublishableEntityImport(TimeStampedModel):
85-
"""
86-
Represents a publishableentity version that has been imported into a learning package (e.g. content library)
87-
88-
This is a many-to-many relationship between a container version and a course to library import.
89-
"""
90-
91-
import_event = models.ForeignKey(Import, on_delete=models.CASCADE)
92-
resulting_mapping = models.ForeignKey(PublishableEntityMapping, on_delete=models.SET_NULL, null=True, blank=True)
93-
resulting_change = models.OneToOneField(
94-
to='oel_publishing.DraftChangeLogRecord',
95-
# a changelog record can be pruned, which would set this to NULL, but not delete the
96-
# entire import record
97-
null=True,
98-
on_delete=models.SET_NULL,
99-
)
100-
101-
class Meta:
102-
unique_together = (
103-
('import_event', 'resulting_mapping'),
104-
)
105-
106-
def __str__(self):
107-
return f'{self.import_event}{self.resulting_mapping}'
108-
109-
110-
class StagedContentForImport(TimeStampedModel):
111-
"""
112-
Represents m2m relationship between an import and staged content created for that import.
113-
"""
114-
115-
import_event = models.ForeignKey(
116-
Import,
117-
on_delete=models.CASCADE,
118-
related_name='staged_content_for_import',
119-
)
120-
staged_content = models.OneToOneField(
121-
to='content_staging.StagedContent',
122-
on_delete=models.CASCADE,
123-
related_name='staged_content_for_import',
124-
)
125-
# Since StagedContent stores all the keys of the saved blocks, this field was added to optimize search.
126-
source_usage_key = UsageKeyField(
127-
max_length=255,
128-
help_text=_(
129-
'The original Usage key of the highest-level component that was saved in StagedContent.'
130-
),
131-
)
132-
133-
class Meta:
134-
unique_together = (
135-
('import_event', 'staged_content'),
136-
)
137-
138-
def __str__(self):
139-
return f'{self.import_event}{self.staged_content}'

0 commit comments

Comments
 (0)