Ejemplo n.º 1
0
class RevealSubmitBlockSerializer(SubmitBlockSerializer):
    response = SettingsStreamFieldSerializer()
    action = SettingsStreamFieldSerializer()

    class Meta:
        fields = [
            'name',
            'text',
            'response',
            'action',
        ]
Ejemplo n.º 2
0
class LinkCategorySerializer(serializers.Serializer):
    block_name = 'linkcategory'

    name = serializers.CharField(max_length=50)
    icon = serializers.CharField()
    stream = SettingsStreamFieldSerializer()

    @staticmethod
    def block_definition(local_blocks):
        return LinkCategorySerializer.block_name, blocks.StructBlock(
            local_blocks=[
                ('name',
                 blocks.TextBlock(max_length=50,
                                  required=True,
                                  help_text=_('Name of the category'))),
                ('stream',
                 StreamBlock(local_blocks,
                             label=_('A nested content of a category'))),
                ('icon',
                 blocks.ChoiceBlock(choices=[('none', _('None'))] + icons,
                                    default=['none'],
                                    label=_('The icon'))),
            ])

    class Meta:
        fields = ['name', 'stream', 'icon']
Ejemplo n.º 3
0
    def post(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data, *args, **kwargs)
        serializer.is_valid(raise_exception=True)
        data = serializer.validated_data
        form: FormBuilder = self.queryset.get(name=data['name'])
        action = form.find_action(action=data['action'])
        permission_classes = security_choices[
            form.security]['permission_classes']
        if any([
                not perm().has_permission(request, self)
                for perm in permission_classes
        ]):
            raise PermissionDenied()
        context = {'request': request, 'form': form, 'data': data['data']}
        context['validated_data'] = validate_form_data(**context)

        def match_action(other):
            return action['id'] == other['id']

        fields = SettingsStreamFieldSerializer(
            serializers={
                'form_submit': RevealSubmitBlockSerializer
            }).to_representation(form.stream)
        actions = list(filter(match_action, fields))
        assert len(actions) == 1, (
            'More actions with same id found. Should not happen')
        result = handle(actions[0], **context)
        return HttpResponse(json.dumps({'stream': result}))
Ejemplo n.º 4
0
class CustomMenuSerializer(serializers.ModelSerializer):
    stream = SettingsStreamFieldSerializer()

    class Meta:
        model = CustomMenu
        fields = [
            'name',
            'stream',
        ]
Ejemplo n.º 5
0
class ContainerSerializer(serializers.Serializer):
    block_name = 'container'
    stream = SettingsStreamFieldSerializer()

    @staticmethod
    def block_definition(local_blocks):
        return ContainerSerializer.block_name, ContainerBlock(local_blocks=local_blocks, icon='doc-full', label=_('Column'))

    class Meta:
        fields = ('stream',)
Ejemplo n.º 6
0
class GetFormBuilderSerializer(serializers.ModelSerializer):
    block_name = 'form'
    stream = SettingsStreamFieldSerializer()

    @staticmethod
    def block_definition():
        return GetFormBuilderSerializer.block_name, SnippetChooserBlock(target_model='generic_forms.FormBuilder', label=_('form'), icon='form')

    class Meta:
        model = FormBuilder
        fields = ['name', 'display_name', 'description', 'security', 'stream']
Ejemplo n.º 7
0
class GroupBlockSerializer(serializers.Serializer):
    block_name = 'form_group'
    name = serializers.CharField(max_length=80)
    row = serializers.BooleanField()
    required = serializers.ChoiceField(choices=visibility_choices)
    stream = SettingsStreamFieldSerializer()
    class Meta:
        fields = ('name', 'row', 'required', 'stream',)

    @staticmethod
    def block_definition():
        return GroupBlockSerializer.block_name, GroupBlock(stream_blocks=[
            InputBlockSerializer.block_definition()
        ])

    def validate(self, attrs):
        pass
Ejemplo n.º 8
0
class OpenDialogSerializer(serializers.Serializer):
    type = 'form_open_dialog'
    title = serializers.CharField(max_length=40)
    text = SettingsStreamFieldSerializer()

    @staticmethod
    def block_definition() -> tuple:
        return OpenDialogSerializer.type, blocks.StructBlock(local_blocks=[(
            'title',
            blocks.TextBlock(
                required=True, help_text=_('title'), max_length=40)
        ), ('text',
            blocks.StreamBlock([RichTextSerializer.block_definition()]))])

    class Meta:
        fields = [
            'title',
            'text',
        ]
Ejemplo n.º 9
0
 def create_extra(self, instance):
     ret = {}
     if 'stream' in self.child_extra:
         ret['stream'] = SettingsStreamFieldSerializer().to_representation(
             instance.stream)
     return ret