Exemplo n.º 1
0
class ThemeModelForm(forms.ModelForm):
    css = forms.CharField(help_text=_("Enter custom CSS"),
                          label=_("CSS"),
                          required=False,
                          widget=CodeMirrorEditor(options={'mode': 'css', 'lineNumbers': True}))
    html_before_header = forms.CharField(help_text=_("HTML that will be displayed above site header"),
                                         label=_("HTML (before header)"),
                                         required=False,
                                         widget=CodeMirrorEditor(options={'mode': 'xml', 'lineNumbers': True}))
    html_after_header = forms.CharField(help_text=_("HTML that will be displayed after site header"),
                                        label=_("HTML (after header)"),
                                        required=False,
                                        widget=CodeMirrorEditor(options={'mode': 'xml', 'lineNumbers': True}))
    html_after_body = forms.CharField(help_text=_("HTML that will be displayed after the body tag"),
                                      label=_("HTML (after body)"),
                                      required=False,
                                    widget=CodeMirrorEditor(options={'mode': 'xml', 'lineNumbers': True}))
    html_footer = forms.CharField(help_text=_("HTML that will be displayed in the footer. You can also use the special tags such as {ORGANIZATION} and {YEAR}."),
                                  label=_("HTML (footer)"),
                                  required=False,
                                  widget=CodeMirrorEditor(options={'mode': 'xml', 'lineNumbers': True}))

    class Meta:
        model = Theme
        fields = '__all__'
def test_dont_share_options(settings):
    settings.CODEMIRROR_DEFAULT_OPTIONS = {"default": "option"}
    w1 = CodeMirrorEditor(options={"w1": "opt1"})
    w2 = CodeMirrorEditor(options={"w2": "opt2"})

    assert w1.options != w2.options
    assert w1.options == {"w1": "opt1", "default": "option"}
    assert w2.options == {"w2": "opt2", "default": "option"}
Exemplo n.º 3
0
class PageAdminCodeForm(forms.ModelForm):
    content = forms.CharField(widget=CodeMirrorEditor(
        options={
            'mode': 'htmlmixed',
            'width': '1170px',
            'indentWithTabs': 'true',
            #'indentUnit' : '4',
            'lineNumbers': 'true',
            'autofocus': 'true',
            #'highlightSelectionMatches': '{showToken: /\w/, annotateScrollbar: true}',
            'styleActiveLine': 'true',
            'autoCloseTags': 'true',
            'keyMap': CODEMIRROR_KEYMAP,
            'theme': 'blackboard',
            #'fullScreen':'true',
        },
        script_template='codemirror2/codemirror_script_vvpages.html',
        modes=['css', 'xml', 'javascript', 'htmlmixed'],
    ))
    content.required = False
    content.label = ""

    class Meta:
        model = Page
        exclude = ('edited', 'created', "editor")
Exemplo n.º 4
0
class DirtyEditForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(DirtyEditForm, self).__init__(*args, **kwargs)
        if 'django_admin_bootstrapped' in settings.INSTALLED_APPS:
            self.fields['content'].label = ''

    if EDIT_MODE == 'html':
        content = forms.CharField(widget=CKEditorUploadingWidget())
    elif EDIT_MODE == 'code':
        content = forms.CharField(widget=CodeMirrorEditor(
            options={
                'mode': 'htmlmixed',
                'width': '1170px',
                'indentWithTabs': 'true',
                'indentUnit': '4',
                'lineNumbers': 'true',
                'autofocus': 'true',
                #'highlightSelectionMatches': '{showToken: /\w/, annotateScrollbar: true}',
                'styleActiveLine': 'true',
                'autoCloseTags': 'true',
                'keyMap': CODEMIRROR_KEYMAP,
                'theme': 'blackboard',
            },
            modes=['css', 'xml', 'javascript', 'htmlmixed'],
        ))
    else:
        content = forms.CharField(widget=forms.Textarea)
    content.required = False

    class Meta:
        model = FileToEdit
        exclude = ('created', 'edited', 'editor')
Exemplo n.º 5
0
 class Meta:
     model = Product
     fields = ['name', 'slug', 'description', 'short_description', 'brand', 'category', 'status', 'editor', 'slideshow_type', 'slideshow_width', 'slideshow_height']
     description_widget = forms.Textarea(attrs={'style': 'width:100%;'})
     if CODE_MODE is True:
         description_widget = CodeMirrorEditor(options={
                                                          'mode':'htmlmixed',
                                                          'indentWithTabs':'true', 
                                                          'indentUnit' : '4',
                                                          #'lineNumbers':'false',
                                                          'autofocus':'true',
                                                          #'highlightSelectionMatches': '{showToken: /\w/, annotateScrollbar: true}',
                                                          'styleActiveLine': 'true',
                                                          'autoCloseTags': 'true',
                                                          'keyMap':'vim',
                                                          'theme':'blackboard',
                                                          }, 
                                                          modes=['css', 'xml', 'javascript', 'htmlmixed'],
                                                 )
     else:
         description_widget = CKEditorUploadingWidget(config_name='mcat')
     short_description_widget = forms.Textarea(attrs={'style': 'min-width:100% !important;', 'rows':6, 'cols':80})
     widgets = {
                'status': forms.RadioSelect,
                'description': description_widget,
                'short_description' : short_description_widget,
                }
Exemplo n.º 6
0
class PageAdminForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(PageAdminForm, self).__init__(*args, **kwargs)
        self.fields['template_name'].help_text = _(u'If no template is defined neither any layout, "alapage/default.html" will be used' )
        if 'django_admin_bootstrapped' in settings.INSTALLED_APPS:
            self.fields['content'].label = ''
    
    if EDIT_MODE == 'visual':    
        content = forms.CharField(widget=CKEditorUploadingWidget())
    elif EDIT_MODE == 'code':
        content = forms.CharField(
                                  widget=CodeMirrorEditor(options={
                                                             'mode':'htmlmixed',
                                                             'width':'1170px',
                                                             'indentWithTabs':'true', 
                                                             'indentUnit' : '4',
                                                             'lineNumbers':'true',
                                                             'autofocus':'true',
                                                             #'highlightSelectionMatches': '{showToken: /\w/, annotateScrollbar: true}',
                                                             'styleActiveLine': 'true',
                                                             'autoCloseTags': 'true',
                                                             'keyMap': CODEMIRROR_KEYMAP,
                                                             'theme':'blackboard',
                                                             }, 
                                                             modes=['css', 'xml', 'javascript', 'htmlmixed'],
                                                             )
                                  
                                  )
    else:
        content = forms.CharField(widget=forms.Textarea)
    content.required = False
    
    class Meta:
        model = Page
        exclude = ('enable_comments','sites')
Exemplo n.º 7
0
 class Meta:
     model = Album
     fields = ['title', 'slug', 'parent', 'image', 'status', 'editor']
     widgets = {
         'status':
         forms.RadioSelect,
         'description':
         CodeMirrorEditor(
             options={
                 'mode': 'htmlmixed',
                 'width': '1170px',
                 'indentWithTabs': 'true',
                 #'indentUnit' : '4',
                 'lineNumbers': 'true',
                 'autofocus': 'true',
                 #'highlightSelectionMatches': '{showToken: /\w/, annotateScrollbar: true}',
                 'styleActiveLine': 'true',
                 'autoCloseTags': 'true',
                 'theme': 'blackboard',
                 #'fullScreen':'true',
             },
             script_template='codemirror2/codemirror_script_vvpages.html',
             modes=['css', 'xml', 'javascript', 'htmlmixed'],
         )
     }
Exemplo n.º 8
0
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.attname == "body":
            kwargs['widget'] = CodeMirrorEditor(
                options={'mode': 'htmlmixed'},
                modes=['css', 'xml', 'javascript', 'htmlmixed'])

        return super(SnippetAdmin,
                     self).formfield_for_dbfield(db_field, **kwargs)
Exemplo n.º 9
0
 def formfield_for_dbfield(self, db_field, **kwargs):
     if db_field.attname == "css":
         kwargs['widget'] = CodeMirrorEditor(options={
             'mode': 'css',
             'lineNumbers': True
         })
     return super(TestCssAdmin,
                  self).formfield_for_dbfield(db_field, **kwargs)
Exemplo n.º 10
0
 def formfield_for_dbfield(self, db_field, **kwargs):
     if db_field.attname in ['head', 'conditions', 'effects']:
         kwargs['widget'] = CodeMirrorEditor(options={
             'mode': 'python',
             'lineNumbers': True
         })
     return super(OperatorAdmin,
                  self).formfield_for_dbfield(db_field, **kwargs)
def test_staticfiles_exist():
    """
    in default configuration (with "all" modes), the static files should exist
    """
    w = CodeMirrorEditor()
    js, css = w.media._js, w.media._css
    for f in chain(js, css["screen"]):
        assert find(f)
Exemplo n.º 12
0
 class EditorForm(forms.Form):
     textarea = forms.CharField(label='', widget=CodeMirrorEditor(options={
         'mode': language_mode,
         'lineNumbers': True,
         'matchBrackets': True,
         'tabSize': 4,
         'smartIndent': False,
         'lineWrapping': True,
     }), initial=initial)
Exemplo n.º 13
0
 def formfield_for_dbfield(self, db_field, **kwargs):
     if db_field.attname == "html":
         kwargs['widget'] = CodeMirrorEditor(
             options={
                 'mode': 'htmlmixed',
                 'lineNumbers': True
             },
             modes=['css', 'xml', 'javascript', 'htmlmixed'])
     return super(TestHTMLAdmin,
                  self).formfield_for_dbfield(db_field, **kwargs)
Exemplo n.º 14
0
class ThemeModelForm(forms.ModelForm):
    css = forms.CharField(help_text="Enter custom CSS",
                          required=False,
                          widget=CodeMirrorEditor(options={
                              'mode': 'css',
                              'lineNumbers': True
                          }))
    html_before_header = forms.CharField(
        help_text="HTML that will be displayed above site header",
        required=False,
        widget=CodeMirrorEditor(options={
            'mode': 'xml',
            'lineNumbers': True
        }))
    html_after_header = forms.CharField(
        help_text="HTML that will be displayed after site header",
        required=False,
        widget=CodeMirrorEditor(options={
            'mode': 'xml',
            'lineNumbers': True
        }))
    html_after_body = forms.CharField(
        help_text="HTML that will be displayed after the </body> tag",
        required=False,
        widget=CodeMirrorEditor(options={
            'mode': 'xml',
            'lineNumbers': True
        }))
    html_footer = forms.CharField(
        help_text=
        "HTML that will be displayed in the footer. You can also use the special tags:"
        "<p class='help'>{ORGANIZATION}: show a link to your organization.</p>"
        "<p class='help'>{YEAR}: show current year</p>",
        required=False,
        widget=CodeMirrorEditor(options={
            'mode': 'xml',
            'lineNumbers': True
        }))

    class Meta:
        model = Theme
        fields = '__all__'
def test_media_w_mode():
    w = CodeMirrorEditor(options={"mode": "python"})
    js, css = w.media._js, w.media._css
    assert js == [
        "codemirror2/lib/codemirror.js",
        "codemirror2/addon/mode/overlay.js",
        "codemirror2/mode/python/python.js",
    ]
    assert css == {"screen": ["codemirror2/lib/codemirror.css"]}
    for f in chain(js, css["screen"]):
        assert find(f)
Exemplo n.º 16
0
class CustomModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        DummyJsonField: {
            'widget': JSONEditor()
        },
        DummyHtmlField: {
            'widget':
            CodeMirrorEditor(options={
                'mode': 'xml',
                'lineNumbers': True,
                'lineWrapping': True
            })
        }
    }
Exemplo n.º 17
0
class TemplateForm(forms.Form):

    subject = forms.CharField(max_length=1000)
    tname = forms.CharField()
    src = forms.CharField(widget=CodeMirrorEditor(options={'mode': 'jinja2','lineNumbers' : True}))
    type = forms.ChoiceField(choices=[('', '----')] + list(Template.TYPE), required=False)

    def __init__(self, template, *args, **kwargs):
        super(TemplateForm, self).__init__(*args, **kwargs)

        self.fields['subject'].initial = template.templateversion_set.last().subject
        self.fields['src'].initial = template.templateversion_set.last().src
        self.fields['type'].initial = template.type
        self.fields['tname'].initial = template.name
        self.tournament = template.tournament

    def clean_name(self):
        name = self.cleaned_data['name']
        return name
Exemplo n.º 18
0
class TemplateForm(forms.Form):

    tname = forms.CharField(label="Template Name")
    files = forms.ModelMultipleChoiceField(queryset=Pdf.objects.none(),
                                           widget=Select2MultipleWidget,
                                           required=False)
    src = forms.CharField(widget=CodeMirrorEditor(options={
        'mode': 'stex',
        'lineNumbers': True
    }))
    name = forms.CharField(required=False)
    type = forms.ChoiceField(choices=[('', '----')] + list(Template.TYPE),
                             required=False)

    def __init__(self, template, *args, **kwargs):
        super(TemplateForm, self).__init__(*args, **kwargs)

        src = template.templateversion_set.last().src
        if src == "":
            src = "empty"
        self.fields['src'].initial = src
        self.fields['type'].initial = template.type
        self.fields['files'].queryset = Pdf.objects.filter(
            tournament=template.tournament)
        self.fields['files'].initial = template.files.all()
        self.fields['tname'].initial = template.name
        self.tournament = template.tournament

    def clean_name(self):
        name = self.cleaned_data['name']

        if name != "":
            if Pdf.objects.filter(tournament=self.tournament,
                                  name=name).exists():
                raise forms.ValidationError(
                    "File with name %(name)s already exists",
                    params={'name': name},
                    code="double-name")

        return name
Exemplo n.º 19
0
class ownRetrievalForm(forms.ModelForm):
    # read sample ranker to set default value
    class Meta:
        model = Customized_retrieval
        fields = ('name', )
        labels = {'name': _('Enter the name of your retrieval function')}

    sample_file = 'IRLab/static/sample.py'
    sample_file = os.path.join(os.path.abspath(settings.BASE_DIR), sample_file)
    sample = ''
    with open(sample_file) as f:
        sample = f.readlines()
    sample = ''.join(sample)

    # one textarea: source
    code = forms.CharField(
        label='Implement your retrieval function',
        initial=sample,
        widget=CodeMirrorEditor(options={
            'mode': 'python',
            'theme': 'eclipse',
            'lineNumbers': True,
        }))
def test_pass_modes():
    modes = ["python", "css", "xml", "javascript", "htmlmixed"]
    w = CodeMirrorEditor(options={"mode": "python"}, modes=modes)
    assert w.modes == modes
    assert w.options == {"mode": "python"}
Exemplo n.º 21
0
class FunctionForm(forms.ModelForm):
    body = forms.CharField(widget=CodeMirrorEditor(options={'mode': 'python'}))

    class Meta:
        model = Function
        fields = ('name', 'body',)
def test_mode_populated_from_options():
    w = CodeMirrorEditor(options={"mode": "python"})
    assert w.modes == ["python"]
Exemplo n.º 23
0
	class Meta:
		model = Script
		fields = '__all__' 
		widgets = {
			'text': CodeMirrorEditor(options={'lineNumbers': True, 'mode': "shell", 'matchBrackets': True})}
def test_mode_extra_css():
    w = CodeMirrorEditor(options={"mode": "tiki"})
    js, css = w.media._js, w.media._css
    assert "codemirror2/mode/tiki/tiki.css" in css["screen"]
    for f in chain(js, css["screen"]):
        assert find(f)
def w():
    """
    construct a CodeMirrorEditor widget with default settings
    """
    return CodeMirrorEditor()
def test_themes_populated_from_args():
    themes = ["light", "dark", "default"]
    w = CodeMirrorEditor(themes=themes)
    assert w.themes == themes
def test_themes_populated_from_options():
    w = CodeMirrorEditor(options={"theme": "dark"})
    assert w.themes == ["dark"]