Add helper function

This commit is contained in:
Ramon Wenger 2019-09-11 11:41:34 +02:00
parent b2e133542c
commit 3fd9aa1f31
2 changed files with 11 additions and 6 deletions

View File

@ -8,6 +8,7 @@ from wagtail.images.blocks import ImageChooserBlock
from books.blocks import TextBlock, BasicKnowledgeBlock, LinkBlock, VideoBlock, DocumentBlock, \
ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock, ModuleRoomSlugBlock
from books.utils import get_type_and_value
from core.wagtail_utils import StrictHierarchyPage
from surveys.models import Survey
from users.models import SchoolClass
@ -88,11 +89,7 @@ class ContentBlock(StrictHierarchyPage):
def save(self, *args, **kwargs):
for data in self.contents.stream_data:
if isinstance(data, tuple):
block_type, value = (data[0], data[1])
else:
block_type = data['type']
value = data['value']
block_type, value = get_type_and_value(data)
if block_type == 'survey':
module = self.module

View File

@ -4,4 +4,12 @@ from users.models import User, Role
def are_solutions_enabled_for(user: User, module: Module):
teacher = user.users_in_same_school_class().filter(user_roles__role=Role.objects.get_default_teacher_role()).first()
return 'users.can_manage_school_class_content' in user.get_role_permissions() or user.is_superuser or (teacher is not None and module.solutions_enabled_by.filter(pk=teacher.pk).exists())
return 'users.can_manage_school_class_content' in user.get_role_permissions() or user.is_superuser or (
teacher is not None and module.solutions_enabled_by.filter(pk=teacher.pk).exists())
def get_type_and_value(data):
if isinstance(data, tuple):
return data[0], data[1]
else:
return data['type'], data['value']