]> git.0d.be Git - earwig.git/commitdiff
switch sound description to a rich text field
authorFrédéric Péters <fpeters@0d.be>
Sun, 2 Sep 2018 07:25:15 +0000 (09:25 +0200)
committerFrédéric Péters <fpeters@0d.be>
Sun, 2 Sep 2018 10:12:23 +0000 (12:12 +0200)
earwig/settings.py
earwig/sounds/fields.py [new file with mode: 0644]
earwig/sounds/migrations/0005_auto_20180902_0922.py [new file with mode: 0644]
earwig/sounds/models.py

index 845e65b7617c60e2ee1658652f93088f24bbc778..2bad4f78c9229e992059961b1804d25f9033d52c 100644 (file)
@@ -37,6 +37,7 @@ INSTALLED_APPS = [
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'ckeditor',
     'gadjo',
     'sorl.thumbnail',
     'earwig.sounds',
@@ -139,6 +140,24 @@ MEDIA_URL = '/media/'
 # Login/registration
 LOGIN_REDIRECT_URL = '/'
 
+# ckeditor
+CKEDITOR_UPLOAD_PATH = 'uploads/'
+CKEDITOR_CONFIGS = {
+    'default': {
+        'allowedContent': True,
+        'removePlugins': 'stylesheetparser',
+        'toolbar_Own': [['Source', 'Format', '-', 'Bold', 'Italic'],
+                        ['NumberedList', 'BulletedList'],
+                        ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
+                        ['Link', 'Unlink'],
+                        ['HorizontalRule'],
+                        ['RemoveFormat',],
+                        ['Maximize']],
+        'toolbar': 'Own',
+        'resize_enabled': False,
+    },
+}
+
 
 local_settings_file = os.environ.get('EARWIG_SETTINGS_FILE',
         os.path.join(os.path.dirname(__file__), 'local_settings.py'))
diff --git a/earwig/sounds/fields.py b/earwig/sounds/fields.py
new file mode 100644 (file)
index 0000000..2b3324a
--- /dev/null
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+#
+# earwig
+# Copyright (C) 2018  Frederic Peters
+#
+# This program is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Originally from Combo, (AGPL as well),
+# <http://git.entrouvert.org/combo.git/tree/combo/data/fields.py>
+
+from django.conf import settings
+
+import ckeditor.fields
+
+
+class RichTextField(ckeditor.fields.RichTextField):
+    def formfield(self, **kwargs):
+        defaults = {
+            'form_class': RichTextFormField,
+            'config_name': self.config_name,
+            'extra_plugins' : self.extra_plugins,
+            'external_plugin_resources': self.external_plugin_resources
+        }
+        defaults.update(kwargs)
+        return super(RichTextField, self).formfield(**defaults)
+
+
+class RichTextFormField(ckeditor.fields.RichTextFormField):
+    def clean(self, value):
+        value = super(RichTextFormField, self).clean(value)
+        if settings.LANGUAGE_CODE.startswith('fr-'):
+            # apply some typographic rules
+            value = value.replace(u'&laquo; ', u'«\u202f')
+            value = value.replace(u'« ', u'«\u202f')
+            value = value.replace(u' &raquo;', u'\u202f»')
+            value = value.replace(u' »', u'\u202f»')
+            value = value.replace(u' :', u'\u00a0:')
+            value = value.replace(u' ;', u'\u202f;')
+            value = value.replace(u' !', u'\u202f!')
+            value = value.replace(u' ?', u'\u202f?')
+        return value
diff --git a/earwig/sounds/migrations/0005_auto_20180902_0922.py b/earwig/sounds/migrations/0005_auto_20180902_0922.py
new file mode 100644 (file)
index 0000000..ecee905
--- /dev/null
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.11 on 2018-09-02 07:22
+from __future__ import unicode_literals
+
+from django.db import migrations
+import earwig.sounds.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('sounds', '0004_channel_last_check_timestamp'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='sound',
+            name='description',
+            field=earwig.sounds.fields.RichTextField(blank=True, null=True, verbose_name='Description'),
+        ),
+    ]
index 80a6df6afc7d40b67f8a881394b894de712ccdaa..50bfe3447163fcfef3390e5b9e3c545f9d971619 100644 (file)
@@ -17,6 +17,9 @@
 from django.db import models
 from django.utils.translation import ugettext_lazy as _
 
+from .fields import RichTextField
+
+
 POLICIES = [
     ('', _('Default (moderate)')),
     ('publish', _('Autopublish')),
@@ -61,7 +64,7 @@ class Channel(models.Model):
 class Sound(models.Model):
     sound_url = models.URLField(_('Sound URL'))
     title = models.CharField(_('Title'), max_length=200)
-    description = models.TextField(_('Description'), blank=True)
+    description = RichTextField(_('Description'), blank=True, null=True)
     page_url = models.URLField(_('Page URL'), blank=True)
     uuid = models.CharField(_('Unique Identifier'), max_length=200, blank=True, null=True)
     channel = models.ForeignKey('Channel', on_delete=models.SET_NULL, blank=True, null=True)