Add survey block to content block in back- and frontend

This commit is contained in:
Ramon Wenger 2019-07-24 14:23:14 +02:00
parent a34313932f
commit c81bcbd26b
8 changed files with 52 additions and 2 deletions

View File

@ -44,6 +44,7 @@
import SubtitleBlock from '@/components/content-blocks/SubtitleBlock';
import ContentListBlock from '@/components/content-blocks/ContentListBlock';
import Assignment from '@/components/content-blocks/assignment/Assignment';
import Survey from '@/components/content-blocks/SurveyBlock';
import Solution from '@/components/content-blocks/Solution';
import AddContentBlockButton from '@/components/AddContentBlockButton';
import VisibilityAction from '@/components/visibility/VisibilityAction';
@ -76,6 +77,7 @@
'genially_block': GeniallyBlock,
'subtitle': SubtitleBlock,
'content_list': ContentListBlock,
Survey,
Solution,
Assignment,
Task,

View File

@ -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>

View File

@ -43,7 +43,7 @@
</div>
</template>
<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>
</template>
</div>

View File

@ -90,6 +90,7 @@ const routes = [
{
path: '/survey/:id',
component: surveyPage,
name: 'survey',
props: true
},
{path: '/styleguide', component: styleGuidePage},

View File

@ -10,6 +10,7 @@ from wagtail.images.models import Image
from assignments.models import Assignment
from basicknowledge.models import BasicKnowledge
from surveys.models import Survey
logger = logging.getLogger(__name__)
@ -49,6 +50,18 @@ def augment_fields(stream_data):
data['value'] = value
except Assignment.DoesNotExist:
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':
_value = data['value']
basic_knowledge = BasicKnowledge.objects.get(pk=_value['basic_knowledge'])

View File

@ -2,10 +2,12 @@ from wagtail.core import blocks
from wagtail.snippets.blocks import SnippetChooserBlock
from assignments.models import Assignment
from surveys.models import Survey
DEFAULT_RICH_TEXT_FEATURES = ['ul']
INSTRUMENTS_RICH_TEXT_FEATURES = ['bold', 'ul']
# link_block
class LinkBlock(blocks.StructBlock):
class Meta:
@ -49,6 +51,14 @@ class AssignmentBlock(blocks.StructBlock):
assignment_id = SnippetChooserBlock(Assignment)
# 'survey'
class SurveyBlock(blocks.StructBlock):
class Meta:
icon = 'form'
survey_id = SnippetChooserBlock(Survey)
# 'video_block'
class VideoBlock(blocks.StructBlock):
class Meta:

View File

@ -7,7 +7,7 @@ from wagtail.core.fields import StreamField
from wagtail.images.blocks import ImageChooserBlock
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 users.models import SchoolClass
@ -39,6 +39,7 @@ class ContentBlock(StrictHierarchyPage):
('text_block', TextBlock()),
('basic_knowledge', BasicKnowledgeBlock()),
('assignment', AssignmentBlock()),
('survey', SurveyBlock()),
('image_block', ImageChooserBlock()),
('image_url_block', ImageUrlBlock()),
('link_block', LinkBlock()),

View File

@ -1,8 +1,10 @@
from django.contrib.auth import get_user_model
from django.db import models
from django.contrib.postgres.fields import JSONField
from wagtail.snippets.models import register_snippet
@register_snippet
class Survey(models.Model):
title = models.CharField(max_length=255)
data = JSONField()