Example #1
0
 class Meta:
     model = ActionGroup
     exclude = ('keywords', 'in_menus', 'goals', 'timeline', 'oneliner', 'twoliner', 'potential_members', 'links')
     widgets = {
         'content': CKEditor(ckeditor_config='basic'),
         'announcements': CKEditor(ckeditor_config='basic'),
         'meetings': CKEditor(ckeditor_config='basic'),
         'links': CKEditor(ckeditor_config='basic'),
         'status': HiddenInput(),
         'user': HiddenInput(),
         'category': HiddenInput(),
         'featured_image': AdvancedFileInput(),
         'is_approved': HiddenInput(),
         'slug': HiddenInput(),
         '_meta_title': HiddenInput(),
         'description': HiddenInput(),
         'gen_description': HiddenInput(),
         'keywords': HiddenInput(),
         'short_url': HiddenInput(),
         'publish_date': HiddenInput(),
         'expiry_date': HiddenInput(),
         'in_sitemap': HiddenInput(),
         'theme_color': HiddenInput(),
         '_order': HiddenInput(),
         'login_required': HiddenInput(),
         'in_menus': HiddenInput(),
     }
Example #2
0
 def test_default_config(self):
     ck = CKEditor()
     rendered = ck.render("ck", "Test")
     expected = (
         '<textarea cols="40" name="ck" rows="10">\r\nTest</textarea><script type="text/javascript">\n<!--\nCKEDITOR.basePath = \'/static/js/ckeditor/\';\nCKEDITOR_config = {"language": "en", "toolbar": "full"}\nCKEDITOR.replace(\'id_ck\', CKEDITOR_config);\n-->\n</script>\n'
     )
     self.assertEqual(rendered, expected)
Example #3
0
 def test_custom_config(self):
     ck = CKEditor(ck_config={'extraPlugins': 'myThing'})
     rendered = ck.render("ck", "Test")
     expected = (
         '<textarea cols="40" name="ck" rows="10">\r\nTest</textarea><script type="text/javascript">\n<!--\nCKEDITOR.basePath = \'/static/js/ckeditor/\';\nCKEDITOR_config = {"extraPlugins": "myThing"}\nCKEDITOR.replace(\'id_ck\', CKEDITOR_config);\n-->\n</script>\n'
     )
     self.assertEqual(rendered, expected)
Example #4
0
 def test_config_based_on_allowed_tags(self):
     ck = CKEditor(allowed_tags=['a'])
     rendered = ck.render("ck", "Test")
     expected = (
         '<textarea cols="40" name="ck" rows="10">\r\nTest</textarea><script type="text/javascript">\n<!--\nCKEDITOR.basePath = \'/static/js/ckeditor/\';\nCKEDITOR_config = {"language": "en", "toolbar_full": [["Link", "Unlink", "Anchor"]], "toolbar_simple": [["Link", "Unlink", "Anchor"]], "toolbar": "full"}\nCKEDITOR.replace(\'id_ck\', CKEDITOR_config);\n-->\n</script>\n'
     )
     self.assertEqual(rendered, expected)
Example #5
0
 class Meta:
     model = Organization
     widgets = {
         'slug': forms.HiddenInput(),
         'mandate': CKEditor(ckeditor_config='basic'),
         'communities': CKEditor(ckeditor_config='basic'),
         'sources_of_funding': CKEditor(ckeditor_config='basic'),
     }
Example #6
0
 def test_custom_config(self):
     ck = CKEditor(ck_config={'extraPlugins': 'myThing'})
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\nCKEDITOR.basePath = \'/static/js/ckeditor/\';\n'
                 'CKEDITOR.replace(\'id_ck\', {"extraPlugins": "myThing"});'
                 '\n-->\n</script>\n')
     self.assertEqual(rendered, expected)
Example #7
0
 def test_config_based_on_allowed_tags(self):
     ck = CKEditor(allowed_tags=['a'])
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\nCKEDITOR.basePath = \'/static/js/ckeditor/\';'
                 '\nCKEDITOR.replace(\'id_ck\', {"toolbar": [["Link",'
                 ' "Unlink", "Anchor"]]});\n-->\n</script>\n')
     self.assertEqual(rendered, expected)
Example #8
0
 def test_default_config(self):
     ck = CKEditor()
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\n'
                 "CKEDITOR.replace('id_ck');\n"
                 '-->\n'
                 '</script>')
     self.assertEqual(rendered, expected)
Example #9
0
 def test_config_based_on_allowed_tags(self):
     ck = CKEditor(allowed_tags=['a'])
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\nCKEDITOR.basePath = \'/static/js/ckeditor/\';'
                 '\nCKEDITOR.replace(\'id_ck\', {"toolbar": [["Link",'
                 ' "Unlink", "Anchor"]]});\n-->\n</script>\n'
                 )
     self.assertEqual(rendered, expected)
Example #10
0
 def test_default_config(self):
     ck = CKEditor()
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\n'
                 "CKEDITOR.replace('id_ck');\n"
                 '-->\n'
                 '</script>')
     self.assertEqual(rendered, expected)
Example #11
0
 def test_custom_config(self):
     ck = CKEditor(ck_config={'extraPlugins': 'myThing'})
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\n'
                 "CKEDITOR.replace('id_ck', "
                 '{"extraPlugins": "myThing"});\n'
                 '-->\n'
                 '</script>')
     self.assertEqual(rendered, expected)
Example #12
0
 def test_default_config(self):
     ck = CKEditor()
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\n'
                 'CKEDITOR.basePath = \'/static/js/ckeditor/\';\n'
                 'CKEDITOR.replace(\'id_ck\', {"language": "en-us"});\n'
                 '-->\n'
                 '</script>\n')
     self.assertEqual(rendered, expected)
Example #13
0
 def test_default_config(self):
     ck = CKEditor()
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\n'
                 'CKEDITOR.basePath = \'/static/js/ckeditor/\';\n'
                 'CKEDITOR.replace(\'id_ck\', {"language": "en-us"});\n'
                 '-->\n'
                 '</script>\n')
     self.assertEqual(rendered, expected)
Example #14
0
 def test_config_based_on_allowed_tags(self):
     ck = CKEditor(allowed_tags=['a'])
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\n'
                 "CKEDITOR.replace('id_ck', "
                 '{"toolbar": [["Link", "Unlink", "Anchor"]]});\n'
                 '-->\n'
                 '</script>')
     self.assertEqual(rendered, expected)
Example #15
0
 def test_config_based_on_allowed_tags(self):
     ck = CKEditor(allowed_tags=['a'])
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\n'
                 "CKEDITOR.replace('id_ck', "
                 '{"toolbar": [["Link", "Unlink", "Anchor"]]});\n'
                 '-->\n'
                 '</script>')
     self.assertEqual(rendered, expected)
Example #16
0
 def test_custom_config(self):
     ck = CKEditor(ck_config={'extraPlugins': 'myThing'})
     rendered = ck.render("ck", "Test")
     expected = ('<textarea rows="10" cols="40" name="ck">Test</textarea>'
                 '<script type="text/javascript">\n'
                 '<!--\n'
                 "CKEDITOR.replace('id_ck', "
                 '{"extraPlugins": "myThing"});\n'
                 '-->\n'
                 '</script>')
     self.assertEqual(rendered, expected)
Example #17
0
 def test_default_config(self):
     ck = CKEditor()
     rendered = ck.render("ck", "Test")
     expected = (
         '<textarea rows="10" cols="40" name="ck">Test</textarea>'
         '<script type="text/javascript">\n'
         "<!--\n"
         "CKEDITOR.basePath = '/static/js/ckeditor/';\n"
         "CKEDITOR.replace('id_ck');\n"
         "-->\n"
         "</script>\n"
     )
     self.assertEqual(rendered, expected)
Example #18
0
 class Meta:
     model = Profile
     exclude = (get_profile_user_fieldname(), ) + _exclude_fields
     widgets = {
         'organization': HiddenInput(),
         'bio': CKEditor(ckeditor_config='basic')
     }
Example #19
0
 class Meta:
     model = Project
     exclude = ('slug', 'in_menus',)
     widgets = {
         'time_per_week': CKEditor(ckeditor_config='basic'),
         'support_method': CKEditor(ckeditor_config='basic'),
         'results_plan': CKEditor(ckeditor_config='basic'),
         'larger_goal': CKEditor(ckeditor_config='basic'),
         'researcher_qualities': CKEditor(ckeditor_config='basic'),
         'description_short': HiddenInput(),
         'size': HiddenInput(),
         'description_long': CKEditor(ckeditor_config='basic'),
         'liaison': SelectWithPopUp('Liaison'),
         'user': HiddenInput(),
         'category': HiddenInput(),
         'is_submitted': HiddenInput(),
         'is_approved': HiddenInput(),
         'is_underway': HiddenInput(),
         'is_finished': HiddenInput(),
         'is_completed_successfully': HiddenInput(),
         'date_start': HiddenInput(),
     }
 def test_config_based_on_allowed_tags(self):
     ck = CKEditor(allowed_tags=['a'])
     rendered = ck.render("ck", "Test")
     expected = ('<textarea cols="40" name="ck" rows="10">\r\nTest</textarea><script type="text/javascript">\n<!--\nCKEDITOR.basePath = \'/static/js/ckeditor/\';\nCKEDITOR_config = {"language": "en", "toolbar_full": [["Link", "Unlink", "Anchor"]], "toolbar_simple": [["Link", "Unlink", "Anchor"]], "toolbar": "full"}\nCKEDITOR.replace(\'id_ck\', CKEDITOR_config);\n-->\n</script>\n')
     self.assertEqual(rendered, expected)
 def test_default_config(self):
     ck = CKEditor()
     rendered = ck.render("ck", "Test")
     expected = ('<textarea cols="40" name="ck" rows="10">\r\nTest</textarea><script type="text/javascript">\n<!--\nCKEDITOR.basePath = \'/static/js/ckeditor/\';\nCKEDITOR_config = {"language": "en", "toolbar": "full"}\nCKEDITOR.replace(\'id_ck\', CKEDITOR_config);\n-->\n</script>\n')
     self.assertEqual(rendered, expected)
Example #22
0
File: forms.py Project: sjl/stoat
def _get_field(typ, title, options):
    typ = typ.lower()
    required = options.get('required', False)

    if typ == 'char':
        return forms.CharField(max_length=140, label=title, required=required)

    if typ == 'text':
        return forms.CharField(widget=forms.Textarea(),
                               label=title,
                               required=required)

    if typ == 'int':
        return forms.IntegerField(label=title, required=required)

    if typ == 'url':
        return forms.URLField(label=title,
                              required=required,
                              verify_exists=False)

    if typ == 'ckeditor':
        from ckeditor.widgets import CKEditor

        config = options.get('config', 'default')
        return forms.CharField(widget=CKEditor(ckeditor_config=config),
                               label=title,
                               required=required)

    if typ == 'email':
        return forms.EmailField(label=title, required=required)

    if typ == 'bool':
        return forms.BooleanField(label=title, required=required)

    if typ == 'float':
        return forms.FloatField(label=title, required=required)

    if typ == 'decimal':
        return forms.DecimalField(label=title, required=required)

    if typ == 'img':
        from filebrowser.fields import FileBrowseFormField, FileBrowseWidget

        attrs = {
            'directory': '',
            'extensions': '',
            'format': 'Image',
        }

        return FileBrowseFormField(format='Image',
                                   label=title,
                                   required=required,
                                   widget=FileBrowseWidget(attrs=attrs))

    if typ == 'fk':
        app_label = options.get('app', 'stoat')
        model_name = options.get('model', 'Page')
        model = get_model(app_label, model_name)

        return forms.ModelChoiceField(model.objects.all(),
                                      label=title,
                                      required=required)

    if typ == 'inline':
        return None

    assert False, "Unknown field type '%s' for field '%s'" % (typ, title)