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)
|
||||
class AssignmentAdmin(admin.ModelAdmin):
|
||||
pass
|
||||
list_display = ('title', 'module', 'deleted', 'owner', )
|
||||
|
||||
|
||||
@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
|
||||
import django.db.models.deletion
|
||||
import django_extensions.db.fields
|
||||
|
|
@ -10,6 +11,8 @@ class Migration(migrations.Migration):
|
|||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('books', '0002_contentblock_hidden_for'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
|
|
@ -62,4 +65,19 @@ class Migration(migrations.Migration):
|
|||
name='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_extensions.db.models import TimeStampedModel
|
||||
|
||||
from books.models import Module
|
||||
|
||||
|
||||
class Assignment(TimeStampedModel):
|
||||
title = models.CharField(max_length=255)
|
||||
|
|
@ -9,6 +11,7 @@ class Assignment(TimeStampedModel):
|
|||
deleted = models.BooleanField(default=False)
|
||||
owner = models.ForeignKey(get_user_model(),
|
||||
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):
|
||||
return self.title
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ class AssignmentBlockFactory(wagtail_factories.StructBlockFactory):
|
|||
class Meta:
|
||||
model = AssignmentBlock
|
||||
|
||||
|
||||
class VideoBlockFactory(wagtail_factories.StructBlockFactory):
|
||||
url = factory.LazyAttribute(lambda x: 'https://www.youtube.com/watch?v=lO9d-AJai8Q')
|
||||
|
||||
|
|
@ -105,18 +106,8 @@ class ContentBlockFactory(BasePageFactory):
|
|||
'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
|
||||
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:
|
||||
for idx, resource in enumerate(kwargs[stream_field_name]):
|
||||
value = resource['value']
|
||||
|
|
@ -127,7 +118,8 @@ class ContentBlockFactory(BasePageFactory):
|
|||
assignment = Assignment.objects.create(
|
||||
title=value['title'],
|
||||
assignment=value['assignment'],
|
||||
owner=user
|
||||
owner=user,
|
||||
module=module
|
||||
)
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, idx, block_type, 'assignment_id')] = assignment.id
|
||||
|
||||
|
|
@ -158,10 +150,6 @@ class ContentBlockFactory(BasePageFactory):
|
|||
kwargs[
|
||||
'{}__{}__{}__{}'.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]
|
||||
else:
|
||||
for i in range(0, random.randint(3, 7)):
|
||||
|
|
@ -172,7 +160,6 @@ class ContentBlockFactory(BasePageFactory):
|
|||
elif block_type == 'basic_knowledge':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'basic_knowledge', 'description')] = RichText(
|
||||
fake_paragraph())
|
||||
# kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'basic_knowledge', 'description')] = ..url..
|
||||
elif block_type == 'assignment':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'assignment', 'task_text')] = RichText(
|
||||
fake_paragraph())
|
||||
|
|
@ -181,11 +168,12 @@ class ContentBlockFactory(BasePageFactory):
|
|||
'{}__{}__{}__{}'.format(stream_field_name, i, 'image_url_block', 'title')] = fake_paragraph()
|
||||
kwargs[
|
||||
'{}__{}__{}__{}'.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':
|
||||
kwargs['{}__{}__{}__{}'.format(stream_field_name, i, 'task', 'text')] = RichText(fake_paragraph())
|
||||
|
||||
@classmethod
|
||||
def create(cls, **kwargs):
|
||||
cls.stream_field_magic(kwargs, 'contents')
|
||||
def create(cls, module, **kwargs):
|
||||
cls.stream_field_magic(module, kwargs, 'contents')
|
||||
return cls._generate(CREATE_STRATEGY, kwargs)
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class ModuleNode(DjangoObjectType):
|
|||
class Meta:
|
||||
model = Module
|
||||
only_fields = [
|
||||
'slug', 'title', 'meta_title', 'teaser', 'intro', 'objective_groups'
|
||||
'slug', 'title', 'meta_title', 'teaser', 'intro', 'objective_groups', 'assignments'
|
||||
]
|
||||
filter_fields = {
|
||||
'slug': ['exact', 'icontains', 'in'],
|
||||
|
|
@ -51,14 +51,14 @@ class ModuleNode(DjangoObjectType):
|
|||
}
|
||||
interfaces = (relay.Node,)
|
||||
|
||||
def resolve_pk(self, *args, **kwargs):
|
||||
def resolve_pk(self, info, **kwargs):
|
||||
return self.id
|
||||
|
||||
def resolve_hero_image(self, *args, **kwargs):
|
||||
def resolve_hero_image(self, info, **kwargs):
|
||||
if self.hero_image:
|
||||
return self.hero_image.file.url
|
||||
|
||||
def resolve_chapters(self, *args, **kwargs):
|
||||
def resolve_chapters(self, info, **kwargs):
|
||||
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):
|
||||
# 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
|
||||
management.call_command('dummy_rooms', verbosity=0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue