Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from django.contrib import admin
from django.db import models
from .widgets import AdminMartorWidget
from .models import MartorField
class MartorModelAdmin(admin.ModelAdmin):
formfield_overrides = {
MartorField: {'widget': AdminMartorWidget}
}
from django.db import models
from martor.models import MartorField
class Post(models.Model):
title = models.CharField(max_length=200)
description = MartorField()
wiki = MartorField()
from django.db import models
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from martor.models import MartorField
from modeltrans.fields import TranslationField
from mptt.models import MPTTModel, TreeForeignKey
from pragmatic.mixins import SlugMixin
class FlatPage_i18n(SlugMixin, models.Model):
FORCE_SLUG_REGENERATION = False
title = models.CharField(_('title'), max_length=200)
slug = models.SlugField(unique=True, max_length=SlugMixin.MAX_SLUG_LENGTH, blank=True, default='')
machine_name = models.SlugField(_('machine name'), max_length=30, blank=True, help_text=_('unique'))
content = MartorField(_('content'), blank=True)
template_name = models.CharField(
_('template name'), max_length=70, blank=True,
help_text=_(u"Example: 'flatpages_i18n/contact_page.html'. If this isn't provided, the system will use 'flatpages_i18n/default.html'."))
registration_required = models.BooleanField(
_('registration required'), default=False,
help_text=_(u"If this is checked, only logged-in users will be able to view the page."))
sites = models.ManyToManyField(Site)
created = models.DateTimeField(_('created'), auto_now_add=True)
modified = models.DateTimeField(_('modified'), auto_now=True)
i18n = TranslationField(fields=('title', 'slug', 'content'))
class Meta:
verbose_name = _('flat page')
verbose_name_plural = _('flat pages')
ordering = ('title',)
indexes = [GinIndex(fields=["i18n"]), ]
from django.db import models
from martor.models import MartorField
class Post(models.Model):
title = models.CharField(max_length=200)
description = MartorField()
wiki = MartorField()
from django.db import models
from django.contrib import admin
from martor.widgets import AdminMartorWidget
from martor.models import MartorField
from app.models import Post
class PostAdmin(admin.ModelAdmin):
list_display = ['title', 'id']
formfield_overrides = {
MartorField: {'widget': AdminMartorWidget},
models.TextField: {'widget': AdminMartorWidget},
}
admin.site.register(Post, PostAdmin)
def __init__(self, *args, **kwargs):
# to setup the editor without label
if not MARTOR_ENABLE_LABEL:
kwargs['label'] = ''
super(MartorFormField, self).__init__(*args, **kwargs)
if not issubclass(self.widget.__class__, MartorWidget):
self.widget = MartorWidget()
# Make sure that the martor value is in the class attr passed in
if 'class' in attrs:
attrs['class'] += ' martor'
else:
attrs['class'] = 'martor'
# Update and overwrite with the attributes passed in
attributes_to_pass.update(attrs)
# Update and overwrite with any attributes that are on the widget
# itself. This is also the only way we can push something in without
# being part of the render chain.
attributes_to_pass.update(self.attrs)
widget = super(MartorWidget, self).render(name,
value,
attributes_to_pass)
template = get_template('martor/editor.html')
return template.render({
'martor': widget,
'field_name': name
})
js = (
'plugins/js/ace.js',
'plugins/js/semantic.min.js',
'plugins/js/mode-markdown.js',
'plugins/js/ext-language_tools.js',
'plugins/js/theme-github.js',
'plugins/js/highlight.min.js',
'plugins/js/resizable.min.js',
'plugins/js/emojis.min.js',
'martor/js/martor.min.js',
)
if MARTOR_ENABLE_CONFIGS['jquery'] == 'true':
js = ('plugins/js/jquery.min.js',).__add__(js)
class AdminMartorWidget(MartorWidget, widgets.AdminTextareaWidget):
pass
def __init__(self, *args, **kwargs):
# to setup the editor without label
if not MARTOR_ENABLE_LABEL:
kwargs['label'] = ''
super(MartorFormField, self).__init__(*args, **kwargs)
if not issubclass(self.widget.__class__, MartorWidget):
self.widget = MartorWidget()
from django import forms
from martor.fields import MartorFormField
from app.models import Post
class SimpleForm(forms.Form):
title = forms.CharField(widget=forms.TextInput())
description = MartorFormField()
wiki = MartorFormField()
class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = '__all__'