Add module to assignment
This commit is contained in:
parent
ddeb6e16a6
commit
b9bb41e8cc
|
|
@ -6,7 +6,7 @@ from assignments.models import Assignment, StudentSubmission
|
||||||
|
|
||||||
@admin.register(Assignment)
|
@admin.register(Assignment)
|
||||||
class AssignmentAdmin(admin.ModelAdmin):
|
class AssignmentAdmin(admin.ModelAdmin):
|
||||||
pass
|
list_display = ('title', 'module', 'deleted', 'owner', )
|
||||||
|
|
||||||
|
|
||||||
@admin.register(StudentSubmission)
|
@admin.register(StudentSubmission)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
# Generated by Django 2.0.6 on 2018-10-04 07:39
|
# Generated by Django 2.0.6 on 2018-10-04 12:28
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
import django_extensions.db.fields
|
import django_extensions.db.fields
|
||||||
|
|
@ -10,6 +11,8 @@ class Migration(migrations.Migration):
|
||||||
initial = True
|
initial = True
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('books', '0002_contentblock_hidden_for'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
|
|
@ -62,4 +65,19 @@ class Migration(migrations.Migration):
|
||||||
name='assignment',
|
name='assignment',
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='submissions', to='assignments.Assignment'),
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='submissions', to='assignments.Assignment'),
|
||||||
),
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='studentsubmission',
|
||||||
|
name='student',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='assignment',
|
||||||
|
name='module',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='assignments', to='books.Module'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='assignment',
|
||||||
|
name='owner',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
# Generated by Django 2.0.6 on 2018-10-04 07:39
|
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.db import migrations, models
|
|
||||||
import django.db.models.deletion
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
initial = True
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('assignments', '0001_initial'),
|
|
||||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='studentsubmission',
|
|
||||||
name='student',
|
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
|
||||||
),
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='assignment',
|
|
||||||
name='owner',
|
|
||||||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -2,6 +2,8 @@ from django.contrib.auth import get_user_model
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django_extensions.db.models import TimeStampedModel
|
from django_extensions.db.models import TimeStampedModel
|
||||||
|
|
||||||
|
from books.models import Module
|
||||||
|
|
||||||
|
|
||||||
class Assignment(TimeStampedModel):
|
class Assignment(TimeStampedModel):
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
|
|
@ -9,6 +11,7 @@ class Assignment(TimeStampedModel):
|
||||||
deleted = models.BooleanField(default=False)
|
deleted = models.BooleanField(default=False)
|
||||||
owner = models.ForeignKey(get_user_model(),
|
owner = models.ForeignKey(get_user_model(),
|
||||||
on_delete=models.PROTECT) # probably don't want to delete all assignments if a user gets deleted
|
on_delete=models.PROTECT) # probably don't want to delete all assignments if a user gets deleted
|
||||||
|
module = models.ForeignKey(Module, related_name='assignments', on_delete=models.CASCADE)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ class AssignmentBlockFactory(wagtail_factories.StructBlockFactory):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AssignmentBlock
|
model = AssignmentBlock
|
||||||
|
|
||||||
|
|
||||||
class VideoBlockFactory(wagtail_factories.StructBlockFactory):
|
class VideoBlockFactory(wagtail_factories.StructBlockFactory):
|
||||||
url = factory.LazyAttribute(lambda x: 'https://www.youtube.com/watch?v=lO9d-AJai8Q')
|
url = factory.LazyAttribute(lambda x: 'https://www.youtube.com/watch?v=lO9d-AJai8Q')
|
||||||
|
|
||||||
|
|
@ -105,18 +106,8 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
'task': TextBlockFactory
|
'task': TextBlockFactory
|
||||||
})
|
})
|
||||||
|
|
||||||
# maybe this is a better way to create a strem field
|
|
||||||
#
|
|
||||||
|
|
||||||
# contents = graphene.JSONString()
|
|
||||||
#
|
|
||||||
# contents_param = kwargs['contents']
|
|
||||||
# new_content_block = ContentBlock(type=type_param, title=title)
|
|
||||||
# what_is_this = new_content_block.contents.stream_block.to_python(contents_param)
|
|
||||||
# new_content_block.contents = what_is_this
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def stream_field_magic(cls, kwargs, stream_field_name):
|
def stream_field_magic(cls, module, kwargs, stream_field_name):
|
||||||
if stream_field_name in kwargs:
|
if stream_field_name in kwargs:
|
||||||
for idx, resource in enumerate(kwargs[stream_field_name]):
|
for idx, resource in enumerate(kwargs[stream_field_name]):
|
||||||
value = resource['value']
|
value = resource['value']
|
||||||
|
|
@ -127,7 +118,8 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
assignment = Assignment.objects.create(
|
assignment = Assignment.objects.create(
|
||||||
title=value['title'],
|
title=value['title'],
|
||||||
assignment=value['assignment'],
|
assignment=value['assignment'],
|
||||||
owner=user
|
owner=user,
|
||||||
|
module=module
|
||||||
)
|
)
|
||||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, 'assignment_id')] = assignment.id
|
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, 'assignment_id')] = assignment.id
|
||||||
|
|
||||||
|
|
@ -158,10 +150,6 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
kwargs[
|
kwargs[
|
||||||
'{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = value[field]
|
'{}__{}__{}__{}'.format(stream_field_name, idx, block_type, field)] = value[field]
|
||||||
|
|
||||||
# image file
|
|
||||||
#
|
|
||||||
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'image_block', )] = fake_paragraph()
|
|
||||||
|
|
||||||
del kwargs[stream_field_name]
|
del kwargs[stream_field_name]
|
||||||
else:
|
else:
|
||||||
for i in range(0, random.randint(3, 7)):
|
for i in range(0, random.randint(3, 7)):
|
||||||
|
|
@ -172,7 +160,6 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
elif block_type == 'basic_knowledge':
|
elif block_type == 'basic_knowledge':
|
||||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'basic_knowledge', 'description')] = RichText(
|
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'basic_knowledge', 'description')] = RichText(
|
||||||
fake_paragraph())
|
fake_paragraph())
|
||||||
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'basic_knowledge', 'description')] = ..url..
|
|
||||||
elif block_type == 'assignment':
|
elif block_type == 'assignment':
|
||||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'assignment', 'task_text')] = RichText(
|
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'assignment', 'task_text')] = RichText(
|
||||||
fake_paragraph())
|
fake_paragraph())
|
||||||
|
|
@ -181,11 +168,12 @@ class ContentBlockFactory(BasePageFactory):
|
||||||
'{}__{}__{}__{}'.format(stream_field_name, i, 'image_url_block', 'title')] = fake_paragraph()
|
'{}__{}__{}__{}'.format(stream_field_name, i, 'image_url_block', 'title')] = fake_paragraph()
|
||||||
kwargs[
|
kwargs[
|
||||||
'{}__{}__{}__{}'.format(stream_field_name, i, 'image_url_block',
|
'{}__{}__{}__{}'.format(stream_field_name, i, 'image_url_block',
|
||||||
'url')] = 'https://picsum.photos/400/?random={}'.format(''.join(random.choice('abcdefghiklmn') for _ in range(6)))
|
'url')] = 'https://picsum.photos/400/?random={}'.format(
|
||||||
|
''.join(random.choice('abcdefghiklmn') for _ in range(6)))
|
||||||
elif block_type == 'task':
|
elif block_type == 'task':
|
||||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'task', 'text')] = RichText(fake_paragraph())
|
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'task', 'text')] = RichText(fake_paragraph())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, **kwargs):
|
def create(cls, module, **kwargs):
|
||||||
cls.stream_field_magic(kwargs, 'contents')
|
cls.stream_field_magic(module, kwargs, 'contents')
|
||||||
return cls._generate(CREATE_STRATEGY, kwargs)
|
return cls._generate(CREATE_STRATEGY, kwargs)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ class ModuleNode(DjangoObjectType):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Module
|
model = Module
|
||||||
only_fields = [
|
only_fields = [
|
||||||
'slug', 'title', 'meta_title', 'teaser', 'intro', 'objective_groups'
|
'slug', 'title', 'meta_title', 'teaser', 'intro', 'objective_groups', 'assignments'
|
||||||
]
|
]
|
||||||
filter_fields = {
|
filter_fields = {
|
||||||
'slug': ['exact', 'icontains', 'in'],
|
'slug': ['exact', 'icontains', 'in'],
|
||||||
|
|
@ -51,14 +51,14 @@ class ModuleNode(DjangoObjectType):
|
||||||
}
|
}
|
||||||
interfaces = (relay.Node,)
|
interfaces = (relay.Node,)
|
||||||
|
|
||||||
def resolve_pk(self, *args, **kwargs):
|
def resolve_pk(self, info, **kwargs):
|
||||||
return self.id
|
return self.id
|
||||||
|
|
||||||
def resolve_hero_image(self, *args, **kwargs):
|
def resolve_hero_image(self, info, **kwargs):
|
||||||
if self.hero_image:
|
if self.hero_image:
|
||||||
return self.hero_image.file.url
|
return self.hero_image.file.url
|
||||||
|
|
||||||
def resolve_chapters(self, *args, **kwargs):
|
def resolve_chapters(self, info, **kwargs):
|
||||||
return Chapter.get_by_parent(self)
|
return Chapter.get_by_parent(self)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -741,7 +741,7 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
for content_block_idx, content_block_data in enumerate(content_blocks_data):
|
for content_block_idx, content_block_data in enumerate(content_blocks_data):
|
||||||
# ContentBlockFactory.create(parent=chapter, **self.filter_data(content_block_data, 'contents'))
|
# ContentBlockFactory.create(parent=chapter, **self.filter_data(content_block_data, 'contents'))
|
||||||
ContentBlockFactory.create(parent=chapter, **content_block_data)
|
ContentBlockFactory.create(parent=chapter, module=module, **content_block_data)
|
||||||
|
|
||||||
# now create all usergroups and rooms
|
# now create all usergroups and rooms
|
||||||
management.call_command('dummy_rooms', verbosity=0)
|
management.call_command('dummy_rooms', verbosity=0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue