Exemplo n.º 1
0
 def test_update_validator_script(self):
     addValidatorScript('simple_test_type', 'test_string_field')
     updateValidatorScript('simple_test_type', 'test_string_field',
                           "error_message = 'something'")
     my_script = getAmbidexterityFile('simple_test_type',
                                      'test_string_field', 'validate.py')
     self.assertTrue("error_message = 'something'" in my_script)
Exemplo n.º 2
0
 def test_update_vocabulary_script(self):
     addVocabularyScript('simple_test_type', 'test_choice_field')
     updateVocabularyScript('simple_test_type', 'test_choice_field',
                            "vocabulary = [('test', ), ]")
     my_script = getAmbidexterityFile('simple_test_type',
                                      'test_choice_field', 'vocabulary.py')
     self.assertTrue("vocabulary = [('test', ), ]" in my_script)
Exemplo n.º 3
0
 def test_update_default_script(self):
     addDefaultScript('simple_test_type', 'test_integer_field')
     updateDefaultScript('simple_test_type', 'test_integer_field',
                         'default = 42')
     my_script = getAmbidexterityFile('simple_test_type',
                                      'test_integer_field', 'default.py')
     self.assertTrue('default = 42' in my_script)
Exemplo n.º 4
0
    def button_action(self):
        """ Respond to button clicks.
        """

        PostOnly(self.request)
        CheckAuthenticator(self.request)

        form = self.request.form
        button_id = form['button_id']
        content_type = form['content_type']
        field_name = form['field_name']

        result = {}

        if button_id == 'add_default':
            default_script.addDefaultScript(content_type, field_name)
            models.setDefaultFactory(content_type, field_name)
        elif button_id == 'remove_default':
            default_script.rmDefaultScript(content_type, field_name)
            models.removeDefaultFactory(content_type, field_name)
        elif button_id == 'edit_default':
            result = dict(
                action='edit',
                source=getAmbidexterityFile(content_type, field_name,
                                            'default.py'),
            )
        elif button_id == 'add_validator':
            validator_script.addValidatorScript(content_type, field_name)
            models.setValidator(content_type, field_name)
        elif button_id == 'remove_validator':
            validator_script.rmValidatorScript(content_type, field_name)
            models.removeValidator(content_type, field_name)
        elif button_id == 'edit_validator':
            result = dict(
                action='edit',
                source=getAmbidexterityFile(content_type, field_name,
                                            'validate.py'),
            )
        elif button_id == 'add_vocabulary':
            vocabulary_script.addVocabularyScript(content_type, field_name)
            models.setVocabulary(content_type, field_name)
        elif button_id == 'remove_vocabulary':
            vocabulary_script.rmVocabularyScript(content_type, field_name)
            models.removeVocabulary(content_type, field_name)
        elif button_id == 'edit_vocabulary':
            result = dict(
                action='edit',
                source=getAmbidexterityFile(content_type, field_name,
                                            'vocabulary.py'),
            )
        elif button_id == 'add_view':
            ad_view.addViewTemplate(content_type)
            models.setAmbidexterityView(content_type)
        elif button_id == 'edit_view':
            result = dict(
                action='edit',
                source=getAmbidexterityFile(content_type, None, 'view.pt'),
            )
        elif button_id == 'remove_view':
            ad_view.rmViewTemplate(content_type)
            models.removeAmbidexterityView(content_type)

        self.request.RESPONSE.setHeader('Content-Type', 'application/json')
        self.request.RESPONSE.setHeader('Cache-Control', 'no-cache')
        return json.dumps(result)
Exemplo n.º 5
0
 def test_rm_validator_script(self):
     addValidatorScript('simple_test_type', 'test_string_field')
     rmValidatorScript('simple_test_type', 'test_string_field')
     with self.assertRaises(KeyError):
         getAmbidexterityFile('simple_test_type', 'test_string_field',
                              'validate.py')
Exemplo n.º 6
0
 def test_add_validator_script(self):
     addValidatorScript('simple_test_type', 'test_string_field')
     my_script = getAmbidexterityFile('simple_test_type',
                                      'test_string_field', 'validate.py')
     self.assertTrue('error_message =' in my_script)
Exemplo n.º 7
0
 def test_rm_vocabulary_script(self):
     addVocabularyScript('simple_test_type', 'test_choice_field')
     rmVocabularyScript('simple_test_type', 'test_choice_field')
     with self.assertRaises(KeyError):
         getAmbidexterityFile('simple_test_type', 'test_choice_field',
                              'vocabulary.py')
Exemplo n.º 8
0
 def test_add_vocabulary_script(self):
     addVocabularyScript('simple_test_type', 'test_choice_field')
     my_script = getAmbidexterityFile('simple_test_type',
                                      'test_choice_field', 'vocabulary.py')
     self.assertTrue('vocabulary = []' in my_script)
Exemplo n.º 9
0
 def test_rm_default_script(self):
     addDefaultScript('simple_test_type', 'test_integer_field')
     rmDefaultScript('simple_test_type', 'test_integer_field')
     with self.assertRaises(KeyError):
         getAmbidexterityFile('simple_test_type', 'test_integer_field',
                              'default.py')
Exemplo n.º 10
0
 def test_get_view_file(self):
     pt = utilities.getAmbidexterityFile('simple_test_type', None, 'view.pt')
     self.assertEqual('view.pt for <span tal:replace="context/id" />', pt)