Fix content blocks in `dummy_data` command
This commit is contained in:
parent
8c9dfaf98c
commit
75ecaedd29
|
|
@ -209,8 +209,8 @@ class ModuleTypeFactory(factory.django.DjangoModelFactory):
|
||||||
|
|
||||||
block_types = [
|
block_types = [
|
||||||
"text_block",
|
"text_block",
|
||||||
"basic_knowledge",
|
# "basic_knowledge",
|
||||||
"student_entry",
|
# "student_entry",
|
||||||
"image_url_block",
|
"image_url_block",
|
||||||
"solution",
|
"solution",
|
||||||
]
|
]
|
||||||
|
|
@ -224,7 +224,7 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
lambda x: random.choice(
|
lambda x: random.choice(
|
||||||
[
|
[
|
||||||
"normal",
|
"normal",
|
||||||
"instrument",
|
# "instrument",
|
||||||
"task",
|
"task",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
@ -233,7 +233,7 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
contents = wagtail_factories.StreamFieldFactory(
|
contents = wagtail_factories.StreamFieldFactory(
|
||||||
{
|
{
|
||||||
"text_block": factory.SubFactory(TextBlockFactory),
|
"text_block": factory.SubFactory(TextBlockFactory),
|
||||||
"basic_knowledge": factory.SubFactory(BasicKnowledgeBlockFactory),
|
# "basic_knowledge": factory.SubFactory(BasicKnowledgeBlockFactory),
|
||||||
"assignment": factory.SubFactory(AssignmentBlockFactory),
|
"assignment": factory.SubFactory(AssignmentBlockFactory),
|
||||||
"image_block": factory.SubFactory(
|
"image_block": factory.SubFactory(
|
||||||
wagtail_factories.ImageChooserBlockFactory
|
wagtail_factories.ImageChooserBlockFactory
|
||||||
|
|
@ -248,6 +248,7 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def stream_field_magic(cls, module, kwargs, stream_field_name):
|
def stream_field_magic(cls, module, kwargs, stream_field_name):
|
||||||
|
user = get_user_model().objects.first()
|
||||||
if stream_field_name in kwargs:
|
if stream_field_name in kwargs:
|
||||||
"""
|
"""
|
||||||
stream_field_name is most likely 'contents'
|
stream_field_name is most likely 'contents'
|
||||||
|
|
@ -259,7 +260,6 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
block_type = resource["type"]
|
block_type = resource["type"]
|
||||||
|
|
||||||
if block_type == "assignment":
|
if block_type == "assignment":
|
||||||
user = get_user_model().objects.first()
|
|
||||||
assignment = Assignment.objects.create(
|
assignment = Assignment.objects.create(
|
||||||
title=value["title"],
|
title=value["title"],
|
||||||
assignment=value["assignment"],
|
assignment=value["assignment"],
|
||||||
|
|
@ -268,7 +268,7 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
)
|
)
|
||||||
kwargs[
|
kwargs[
|
||||||
"{}__{}__{}__{}".format(
|
"{}__{}__{}__{}".format(
|
||||||
stream_field_name, idx, block_type, "assignment"
|
stream_field_name, idx, block_type, "assignment_id"
|
||||||
)
|
)
|
||||||
] = assignment
|
] = assignment
|
||||||
elif block_type == "survey":
|
elif block_type == "survey":
|
||||||
|
|
@ -338,9 +338,15 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
)
|
)
|
||||||
] = RichText(fake_paragraph())
|
] = RichText(fake_paragraph())
|
||||||
elif block_type == "assignment":
|
elif block_type == "assignment":
|
||||||
|
assignment = Assignment.objects.create(
|
||||||
|
title=fake_title(),
|
||||||
|
assignment=fake_paragraph(),
|
||||||
|
owner=user,
|
||||||
|
module=module,
|
||||||
|
)
|
||||||
kwargs[
|
kwargs[
|
||||||
"{}__{}__{}__{}".format(
|
"{}__{}__{}__{}".format(
|
||||||
stream_field_name, i, "assignment", "task_text"
|
stream_field_name, i, "assignment_id", assignment
|
||||||
)
|
)
|
||||||
] = RichText(fake_paragraph())
|
] = RichText(fake_paragraph())
|
||||||
elif block_type == "image_url_block":
|
elif block_type == "image_url_block":
|
||||||
|
|
@ -365,5 +371,5 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, module, **kwargs):
|
def create(cls, module, **kwargs):
|
||||||
# cls.stream_field_magic(module, kwargs, "contents")
|
cls.stream_field_magic(module, kwargs, "contents")
|
||||||
return cls._generate(CREATE_STRATEGY, kwargs)
|
return cls._generate(CREATE_STRATEGY, kwargs)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue