Add survey block to content block in back- and frontend
This commit is contained in:
parent
a34313932f
commit
c81bcbd26b
|
|
@ -44,6 +44,7 @@
|
||||||
import SubtitleBlock from '@/components/content-blocks/SubtitleBlock';
|
import SubtitleBlock from '@/components/content-blocks/SubtitleBlock';
|
||||||
import ContentListBlock from '@/components/content-blocks/ContentListBlock';
|
import ContentListBlock from '@/components/content-blocks/ContentListBlock';
|
||||||
import Assignment from '@/components/content-blocks/assignment/Assignment';
|
import Assignment from '@/components/content-blocks/assignment/Assignment';
|
||||||
|
import Survey from '@/components/content-blocks/SurveyBlock';
|
||||||
import Solution from '@/components/content-blocks/Solution';
|
import Solution from '@/components/content-blocks/Solution';
|
||||||
import AddContentBlockButton from '@/components/AddContentBlockButton';
|
import AddContentBlockButton from '@/components/AddContentBlockButton';
|
||||||
import VisibilityAction from '@/components/visibility/VisibilityAction';
|
import VisibilityAction from '@/components/visibility/VisibilityAction';
|
||||||
|
|
@ -76,6 +77,7 @@
|
||||||
'genially_block': GeniallyBlock,
|
'genially_block': GeniallyBlock,
|
||||||
'subtitle': SubtitleBlock,
|
'subtitle': SubtitleBlock,
|
||||||
'content_list': ContentListBlock,
|
'content_list': ContentListBlock,
|
||||||
|
Survey,
|
||||||
Solution,
|
Solution,
|
||||||
Assignment,
|
Assignment,
|
||||||
Task,
|
Task,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
<template>
|
||||||
|
<div class="survey-block">
|
||||||
|
<router-link class="button button--primary"
|
||||||
|
:to="{name: 'survey', params: {id:value.id}}">Übung anzeigen
|
||||||
|
</router-link>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: ['value'],
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
@import "@/styles/_variables.scss";
|
||||||
|
|
||||||
|
.survey-block {
|
||||||
|
margin-bottom: $large-spacing;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="!isStudent">
|
<template v-if="!isStudent">
|
||||||
<router-link class="button" :to="{name: 'submissions', params: { id: assignment.id }}">Zu den Ergebnissen
|
<router-link class="button button--primary" :to="{name: 'submissions', params: { id: assignment.id }}">Zu den Ergebnissen
|
||||||
</router-link>
|
</router-link>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,7 @@ const routes = [
|
||||||
{
|
{
|
||||||
path: '/survey/:id',
|
path: '/survey/:id',
|
||||||
component: surveyPage,
|
component: surveyPage,
|
||||||
|
name: 'survey',
|
||||||
props: true
|
props: true
|
||||||
},
|
},
|
||||||
{path: '/styleguide', component: styleGuidePage},
|
{path: '/styleguide', component: styleGuidePage},
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ from wagtail.images.models import Image
|
||||||
|
|
||||||
from assignments.models import Assignment
|
from assignments.models import Assignment
|
||||||
from basicknowledge.models import BasicKnowledge
|
from basicknowledge.models import BasicKnowledge
|
||||||
|
from surveys.models import Survey
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -49,6 +50,18 @@ def augment_fields(stream_data):
|
||||||
data['value'] = value
|
data['value'] = value
|
||||||
except Assignment.DoesNotExist:
|
except Assignment.DoesNotExist:
|
||||||
logger.error('Assignment {} does not exist'.format(assignment_id))
|
logger.error('Assignment {} does not exist'.format(assignment_id))
|
||||||
|
if _type == 'survey':
|
||||||
|
_value = data['value']
|
||||||
|
survey_id = _value['survey_id']
|
||||||
|
try:
|
||||||
|
survey = Survey.objects.get(pk=survey_id)
|
||||||
|
value = {
|
||||||
|
'title': survey.title,
|
||||||
|
'id': to_global_id('SurveyNode', survey.pk)
|
||||||
|
}
|
||||||
|
data['value'] = value
|
||||||
|
except Survey.DoesNotExist:
|
||||||
|
logger.error('Survey {} does not exist'.format(survey_id))
|
||||||
if _type == 'basic_knowledge' or _type == 'instrument':
|
if _type == 'basic_knowledge' or _type == 'instrument':
|
||||||
_value = data['value']
|
_value = data['value']
|
||||||
basic_knowledge = BasicKnowledge.objects.get(pk=_value['basic_knowledge'])
|
basic_knowledge = BasicKnowledge.objects.get(pk=_value['basic_knowledge'])
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,12 @@ from wagtail.core import blocks
|
||||||
from wagtail.snippets.blocks import SnippetChooserBlock
|
from wagtail.snippets.blocks import SnippetChooserBlock
|
||||||
|
|
||||||
from assignments.models import Assignment
|
from assignments.models import Assignment
|
||||||
|
from surveys.models import Survey
|
||||||
|
|
||||||
DEFAULT_RICH_TEXT_FEATURES = ['ul']
|
DEFAULT_RICH_TEXT_FEATURES = ['ul']
|
||||||
INSTRUMENTS_RICH_TEXT_FEATURES = ['bold', 'ul']
|
INSTRUMENTS_RICH_TEXT_FEATURES = ['bold', 'ul']
|
||||||
|
|
||||||
|
|
||||||
# link_block
|
# link_block
|
||||||
class LinkBlock(blocks.StructBlock):
|
class LinkBlock(blocks.StructBlock):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
@ -49,6 +51,14 @@ class AssignmentBlock(blocks.StructBlock):
|
||||||
assignment_id = SnippetChooserBlock(Assignment)
|
assignment_id = SnippetChooserBlock(Assignment)
|
||||||
|
|
||||||
|
|
||||||
|
# 'survey'
|
||||||
|
class SurveyBlock(blocks.StructBlock):
|
||||||
|
class Meta:
|
||||||
|
icon = 'form'
|
||||||
|
|
||||||
|
survey_id = SnippetChooserBlock(Survey)
|
||||||
|
|
||||||
|
|
||||||
# 'video_block'
|
# 'video_block'
|
||||||
class VideoBlock(blocks.StructBlock):
|
class VideoBlock(blocks.StructBlock):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ from wagtail.core.fields import StreamField
|
||||||
from wagtail.images.blocks import ImageChooserBlock
|
from wagtail.images.blocks import ImageChooserBlock
|
||||||
|
|
||||||
from books.blocks import TextBlock, BasicKnowledgeBlock, LinkBlock, VideoBlock, DocumentBlock, \
|
from books.blocks import TextBlock, BasicKnowledgeBlock, LinkBlock, VideoBlock, DocumentBlock, \
|
||||||
ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock
|
ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock
|
||||||
from core.wagtail_utils import StrictHierarchyPage
|
from core.wagtail_utils import StrictHierarchyPage
|
||||||
from users.models import SchoolClass
|
from users.models import SchoolClass
|
||||||
|
|
||||||
|
|
@ -39,6 +39,7 @@ class ContentBlock(StrictHierarchyPage):
|
||||||
('text_block', TextBlock()),
|
('text_block', TextBlock()),
|
||||||
('basic_knowledge', BasicKnowledgeBlock()),
|
('basic_knowledge', BasicKnowledgeBlock()),
|
||||||
('assignment', AssignmentBlock()),
|
('assignment', AssignmentBlock()),
|
||||||
|
('survey', SurveyBlock()),
|
||||||
('image_block', ImageChooserBlock()),
|
('image_block', ImageChooserBlock()),
|
||||||
('image_url_block', ImageUrlBlock()),
|
('image_url_block', ImageUrlBlock()),
|
||||||
('link_block', LinkBlock()),
|
('link_block', LinkBlock()),
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,10 @@
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.postgres.fields import JSONField
|
from django.contrib.postgres.fields import JSONField
|
||||||
|
from wagtail.snippets.models import register_snippet
|
||||||
|
|
||||||
|
|
||||||
|
@register_snippet
|
||||||
class Survey(models.Model):
|
class Survey(models.Model):
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
data = JSONField()
|
data = JSONField()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue