Add helper function
This commit is contained in:
parent
b2e133542c
commit
3fd9aa1f31
|
|
@ -8,6 +8,7 @@ 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, SurveyBlock, ModuleRoomSlugBlock
|
ImageUrlBlock, AssignmentBlock, InfogramBlock, GeniallyBlock, SubtitleBlock, SurveyBlock, ModuleRoomSlugBlock
|
||||||
|
from books.utils import get_type_and_value
|
||||||
from core.wagtail_utils import StrictHierarchyPage
|
from core.wagtail_utils import StrictHierarchyPage
|
||||||
from surveys.models import Survey
|
from surveys.models import Survey
|
||||||
from users.models import SchoolClass
|
from users.models import SchoolClass
|
||||||
|
|
@ -88,11 +89,7 @@ class ContentBlock(StrictHierarchyPage):
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
for data in self.contents.stream_data:
|
for data in self.contents.stream_data:
|
||||||
if isinstance(data, tuple):
|
block_type, value = get_type_and_value(data)
|
||||||
block_type, value = (data[0], data[1])
|
|
||||||
else:
|
|
||||||
block_type = data['type']
|
|
||||||
value = data['value']
|
|
||||||
|
|
||||||
if block_type == 'survey':
|
if block_type == 'survey':
|
||||||
module = self.module
|
module = self.module
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,12 @@ from users.models import User, Role
|
||||||
|
|
||||||
def are_solutions_enabled_for(user: User, module: Module):
|
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()
|
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']
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue