Example #1
0
 def close(self, msg=None):
     if msg:
         self.context.send(
             self.mtype,
             {'__close__': True,
              'message': ptah.render_message(self.request, msg)})
     else:
         self.context.send(self.mtype, {'__close__': True})
Example #2
0
    def test_messages_render_message_with_error(self):
        from ptah import view

        @view.snippet('custom', view.Message)
        def customMessage(context, request):
            raise ValueError()

        self.init_ptah()

        self.assertEqual(
            ptah.render_message(self.request, 'message', 'custom'),
            'message')
Example #3
0
    def test_messages_render_message(self):
        from ptah import view

        @view.snippet('custom', view.Message)
        def customMessage(context, request):
            return '<div class="customMsg">{0}</div>'.format(context.message)

        self.init_ptah()

        self.assertEqual(
            ptah.render_message(self.request, 'message', 'custom'),
            '<div class="customMsg">message</div>')
Example #4
0
    def render(self):
        data = self.get_msg_data()
        data.update({'id': self.id,
                     'name': self.name,
                     'label': self.label or None,
                     'description': self.description,
                     'fieldsets': []})

        data['actions'] = actions = []
        for name, ac in self.actions.items():
            actions.append({'name': name,
                            'title': ac.title,
                            'cls': ac.klass})

        if self.errors:
            data['errors'] = ptah.render_message(
                self.request, self.errors, 'form-error')

        request = self.request

        fieldsets = data['fieldsets']
        for fieldset in self.widgets.fieldsets:
            widgets = []
            fieldsets.append(
                {'name': fieldset['name'],
                 'title': fieldset['title'] or None,
                 'widgets': widgets})

            for widget in fieldset['widgets']:
                widgets.append(
                    {'type': widget.__field__,
                     'id': widget.id,
                     'title': widget.title,
                     'description': widget.description,
                     'required': widget.required,
                     'error': getattr(getattr(widget,'error',None),'msg',None),
                     'field': widget.render(request),
                     })

        return data