Skip to content

Commit

Permalink
feat: use CKEditor on more fields
Browse files Browse the repository at this point in the history
  • Loading branch information
santi committed Mar 23, 2019
1 parent b079092 commit 890ac81
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 16 deletions.
66 changes: 66 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,72 @@
'dialogui',
'elementspath'
]),
},
'small': {
'toolbar_Article': [
{
'name': 'styles',
'items': ['Styles', 'Format', 'FontSize', 'Source', '-', 'ShowBlocks', 'Maximize'],
},
'/',
{
'name': 'justify',
'items': ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
},
{
'name':
'basicstyles',
'items': [
'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript',
'Blockquote', '-', 'RemoveFormat'
],
},
{
'name': 'colors',
'items': ['TextColor', 'BGColor'],
},
{
'name': 'clipboard',
'items': ['Cut', 'Copy', 'SelectAll', '-', 'Undo', 'Redo'],
},
'/',
{
'name': 'paragraph',
'items': ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent'],
},
{
'name': 'links',
'items': ['Link', 'Unlink', 'Anchor']
},
],
'toolbar':
'Article',
'height':
300,
'width':
600,
'forcePasteAsPlainText':
True,
'font_names':
'Arial/Arial, Helvetica, sans-serif',
'font_defaultLabel':
'Arial',
'tabSpaces':
4,
'contentsCss':
'/static/ckeditor/editor.css',
'extraPlugins':
','.join([
# your extra plugins here
'autolink',
# 'devtools',
'widget',
'lineutils',
'clipboard',
'dialog',
'dialogui',
'elementspath'
]),
}
}

Expand Down
33 changes: 19 additions & 14 deletions data_models/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ class Meta:
fields = '__all__'


class ShowAdminForm(forms.ModelForm):
content = forms.CharField(
widget=CKEditorUploadingWidget(config_name='small'), label='Lang beskrivelse')

class Meta:
model = Show
fields = '__all__'


class EpisodeAdminForm(forms.ModelForm):
lead = forms.CharField(widget=CKEditorUploadingWidget(config_name='small'), label='Beskrivelse')

class Meta:
model = Episode
fields = '__all__'


@admin.register(Post)
class PostAdmin(ImageCroppingMixin, admin.ModelAdmin):
list_display = ('title', 'show', 'publish_at', 'ready_to_be_published', 'deleted')
Expand Down Expand Up @@ -91,24 +108,12 @@ class ShowAdmin(admin.ModelAdmin):
list_filter = ('archived', )
ordering = ('archived', 'name')
search_fields = ('name', )

# Set form field for "lead" to Textarea instead of Textinput
def formfield_for_dbfield(self, db_field, **kwargs):
formfield = super(ShowAdmin, self).formfield_for_dbfield(db_field, **kwargs)
if db_field.name == 'lead':
formfield.widget = forms.Textarea(attrs={'cols': 40, 'rows': 3})
return formfield
form = ShowAdminForm


@admin.register(Episode)
class EpisodeAdmin(admin.ModelAdmin):
list_display = ('title', 'show', 'publish_at')
list_filter = (ActiveShowFilter, ArchivedShowFilter)
search_fields = ('title', 'show__name')

# Set form field for "lead" to Textarea instead of Textinput
def formfield_for_dbfield(self, db_field, **kwargs):
formfield = super(EpisodeAdmin, self).formfield_for_dbfield(db_field, **kwargs)
if db_field.name == 'lead':
formfield.widget = forms.Textarea(attrs={'cols': 60, 'rows': 5})
return formfield
form = EpisodeAdminForm
23 changes: 23 additions & 0 deletions data_models/migrations/0021_more_textfields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.0.12 on 2019-03-18 20:01

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('data_models', '0020_settings_music_producer'),
]

operations = [
migrations.AlterField(
model_name='episode',
name='lead',
field=models.TextField(verbose_name='Beskrivelse'),
),
migrations.AlterField(
model_name='show',
name='lead',
field=models.TextField(max_length=255, verbose_name='Kort beskrivelse'),
),
]
4 changes: 2 additions & 2 deletions data_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Meta:
name = models.CharField('Navn', max_length=64, unique=True)
slug = AutoSlugField(populate_from=['name'])
image = models.ImageField('Programlogo', upload_to='uploads/images')
lead = models.CharField('Kort beskrivelse', max_length=140)
lead = models.TextField('Kort beskrivelse', max_length=255)
content = models.TextField('Lang beskrivelse')

categories = models.ManyToManyField(Category, blank=True, verbose_name='Kategorier')
Expand Down Expand Up @@ -85,7 +85,7 @@ class Meta:
default=False,
help_text='Vis tittelen på episoden. ' +
'Om ikke tittel benyttes vises "Navn på show" + "Publiseringsdato"')
lead = models.CharField('Beskrivelse', max_length=140)
lead = models.TextField('Beskrivelse')

show = models.ForeignKey(
Show,
Expand Down

0 comments on commit 890ac81

Please sign in to comment.