Skip to content

Commit

Permalink
Decouple from djangocms_text_ckeditor
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Sep 11, 2024
1 parent 95831c6 commit 2ad7eb2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 21 deletions.
6 changes: 3 additions & 3 deletions djangocms_blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import cms.models.fields
import django.utils.timezone
import djangocms_text_ckeditor.fields
import filer.fields.image
import meta.models
import taggit_autosuggest.managers
from django.conf import settings
from django.db import migrations, models
from filer.settings import FILER_IMAGE_MODEL

from djangocms_blog.models import HTMLField
from djangocms_blog.models import thumbnail_model

ACTUAL_FILER_IMAGE_MODEL = FILER_IMAGE_MODEL or "filer.Image"
Expand Down Expand Up @@ -243,7 +243,7 @@ class Migration(migrations.Migration):
),
("title", models.CharField(max_length=255, verbose_name="Title")),
("slug", models.SlugField(verbose_name="slug", blank=True)),
("abstract", djangocms_text_ckeditor.fields.HTMLField(verbose_name="Abstract")),
("abstract", HTMLField(verbose_name="Abstract")),
("meta_description", models.TextField(default="", verbose_name="Post meta description", blank=True)),
("meta_keywords", models.TextField(default="", verbose_name="Post meta keywords", blank=True)),
(
Expand All @@ -256,7 +256,7 @@ class Migration(migrations.Migration):
blank=True,
),
),
("post_text", djangocms_text_ckeditor.fields.HTMLField(default="", verbose_name="Text", blank=True)),
("post_text", HTMLField(default="", verbose_name="Text", blank=True)),
(
"master",
models.ForeignKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import django.db.models.deletion
import django.db.models.expressions
import djangocms_text_ckeditor.fields
import filer.fields.image
import meta.models
import parler.fields
Expand Down Expand Up @@ -642,7 +641,7 @@ class Migration(migrations.Migration):
),
(
"abstract",
djangocms_text_ckeditor.fields.HTMLField(blank=True, default="", verbose_name="abstract"),
djangocms_blog.models.HTMLField(blank=True, default="", verbose_name="abstract"),
),
],
options={
Expand Down Expand Up @@ -690,7 +689,7 @@ class Migration(migrations.Migration):
("subtitle", models.CharField(blank=True, default="", max_length=767, verbose_name="subtitle")),
(
"abstract",
djangocms_text_ckeditor.fields.HTMLField(blank=True, default="", verbose_name="abstract"),
djangocms_blog.models.HTMLField(blank=True, default="", verbose_name="abstract"),
),
("meta_description", models.TextField(blank=True, default="", verbose_name="post meta description")),
("meta_keywords", models.TextField(blank=True, default="", verbose_name="post meta keywords")),
Expand All @@ -704,7 +703,7 @@ class Migration(migrations.Migration):
verbose_name="post meta title",
),
),
("post_text", djangocms_text_ckeditor.fields.HTMLField(blank=True, default="", verbose_name="text")),
("post_text", djangocms_blog.models.HTMLField(blank=True, default="", verbose_name="text")),
("post", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="djangocms_blog.post")),
],
options={
Expand Down
5 changes: 3 additions & 2 deletions djangocms_blog/migrations/0006_auto_20150214_1907.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import djangocms_text_ckeditor.fields
from django.db import migrations

from djangocms_blog.models import HTMLField


class Migration(migrations.Migration):
dependencies = [
Expand All @@ -11,7 +12,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="posttranslation",
name="abstract",
field=djangocms_text_ckeditor.fields.HTMLField(verbose_name="Abstract", blank=True, default=""),
field=HTMLField(verbose_name="Abstract", blank=True, default=""),
preserve_default=True,
),
]
7 changes: 3 additions & 4 deletions djangocms_blog/migrations/0007_auto_20150719_0933.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import django.db.models.deletion
import django.utils.timezone
import djangocms_text_ckeditor.fields
import filer.fields.image
from django.conf import settings
from django.db import migrations, models
from filer.settings import FILER_IMAGE_MODEL

from djangocms_blog.models import thumbnail_model
from djangocms_blog.models import HTMLField, thumbnail_model

ACTUAL_FILER_IMAGE_MODEL = FILER_IMAGE_MODEL or "filer.Image"

Expand Down Expand Up @@ -168,7 +167,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="posttranslation",
name="abstract",
field=djangocms_text_ckeditor.fields.HTMLField(verbose_name="abstract"),
field=HTMLField(verbose_name="abstract"),
preserve_default=True,
),
migrations.AlterField(
Expand Down Expand Up @@ -204,7 +203,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="posttranslation",
name="post_text",
field=djangocms_text_ckeditor.fields.HTMLField(blank=True, verbose_name="text", default=""),
field=HTMLField(blank=True, verbose_name="text", default=""),
preserve_default=True,
),
migrations.AlterField(
Expand Down
4 changes: 2 additions & 2 deletions djangocms_blog/migrations/0008_auto_20150814_0831.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import djangocms_text_ckeditor.fields
from django.db import migrations

import djangocms_blog.models

class Migration(migrations.Migration):
dependencies = [
Expand All @@ -11,7 +11,7 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name="posttranslation",
name="abstract",
field=djangocms_text_ckeditor.fields.HTMLField(default=b"", verbose_name="abstract", blank=True),
field=djangocms_blog.models.HTMLField(default=b"", verbose_name="abstract", blank=True),
preserve_default=True,
),
]
5 changes: 3 additions & 2 deletions djangocms_blog/migrations/0040_auto_20211128_1503.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Generated by Django 3.0.14 on 2021-11-28 14:03

import django.db.models.deletion
import djangocms_text_ckeditor.fields
import filer.fields.image
from django.conf import settings
from django.db import migrations, models

import djangocms_blog.models


class Migration(migrations.Migration):
dependencies = [
Expand Down Expand Up @@ -57,7 +58,7 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="blogcategorytranslation",
name="abstract",
field=djangocms_text_ckeditor.fields.HTMLField(blank=True, default="", verbose_name="abstract"),
field=djangocms_blog.models.HTMLField(blank=True, default="", verbose_name="abstract"),
),
migrations.AddField(
model_name="post",
Expand Down
5 changes: 2 additions & 3 deletions djangocms_blog/migrations/0043_postcontent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 3.2 on 2023-02-03 12:15

import django.db.models.deletion
import djangocms_text_ckeditor.fields
from django.db import migrations, models

import djangocms_blog.models
Expand Down Expand Up @@ -58,7 +57,7 @@ class Migration(migrations.Migration):
("subtitle", models.CharField(blank=True, default="", max_length=767, verbose_name="subtitle")),
(
"abstract",
djangocms_text_ckeditor.fields.HTMLField(blank=True, default="", verbose_name="abstract"),
djangocms_blog.models.HTMLField(blank=True, default="", verbose_name="abstract"),
),
("meta_description", models.TextField(blank=True, default="", verbose_name="post meta description")),
("meta_keywords", models.TextField(blank=True, default="", verbose_name="post meta keywords")),
Expand All @@ -72,7 +71,7 @@ class Migration(migrations.Migration):
verbose_name="post meta title",
),
),
("post_text", djangocms_text_ckeditor.fields.HTMLField(blank=True, default="", verbose_name="text")),
("post_text", djangocms_blog.models.HTMLField(blank=True, default="", verbose_name="text")),
("post", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="djangocms_blog.post")),
],
bases=(djangocms_blog.models.BlogMetaMixin, models.Model),
Expand Down
17 changes: 16 additions & 1 deletion djangocms_blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from django.utils.html import strip_tags
from django.utils.timezone import now
from django.utils.translation import get_language, gettext, gettext_lazy as _
from djangocms_text_ckeditor.fields import HTMLField
from filer.fields.image import FilerImageField
from filer.models import ThumbnailOption
from meta.models import ModelMeta
Expand Down Expand Up @@ -52,6 +51,22 @@ class KnockerModel:

pass

# HTMLField is a custom field that allows to use a rich text editor
# Probe for djangocms_text first, then for djangocms_text_ckeditor
# and finally fallback to a simple textarea
try:
from djangocms_text.fields import HTMLField
except ImportError: # pragma: no cover
try:
from djangocms_text_ckeditor.fields import HTMLField
except ImportError:
from django import forms

class HTMLField(models.TextField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("widget", forms.Textarea)
super().__init__(*args, **kwargs)


def _get_language(instance, language):
available_languages = instance.get_available_languages()
Expand Down

0 comments on commit 2ad7eb2

Please sign in to comment.