-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename to
djangocms_text
and fix tests
- Loading branch information
Showing
593 changed files
with
878 additions
and
2,903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
See PEP 440 (https://www.python.org/dev/peps/pep-0440/) | ||
Release logic: | ||
1. Increase version number (change __version__ below). | ||
2. Ensure the static bundle is upto date with ``nvm use && gulp bundle`` | ||
3. Assure that all changes have been documented in CHANGELOG.rst. | ||
4. In setup.py check that | ||
- versions from all third party packages are pinned in ``REQUIREMENTS``. | ||
- the list of ``CLASSIFIERS`` is up to date. | ||
5. git add djangocms_text_ckeditor/__init__.py CHANGELOG.rst setup.py | ||
6. git commit -m 'Bump to {new version}' | ||
7. git push | ||
8. Assure that all tests pass on https://github.com/django-cms/djangocms-text-ckeditor/actions | ||
9. Create a new release on https://github.com/django-cms/djangocms-text-ckeditor/releases/new | ||
10. Publish the release when ready | ||
11. Github actions will publish the new package to pypi | ||
""" | ||
__version__ = "0.1.0" | ||
|
||
default_app_config = "djangocms_text.apps.TextConfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class TextConfig(AppConfig): | ||
name = "djangocms_text" | ||
verbose_name = "django CMS Rich Text" | ||
default_auto_field = "django.db.models.AutoField" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from django.contrib.admin import widgets as admin_widgets | ||
from django.db import models | ||
from django.forms.fields import CharField | ||
from django.utils.safestring import mark_safe | ||
|
||
from .html import clean_html | ||
from .widgets import TextEditorWidget | ||
|
||
|
||
class HTMLFormField(CharField): | ||
widget = TextEditorWidget | ||
|
||
def __init__(self, *args, **kwargs): | ||
conf = kwargs.pop("configuration", None) | ||
|
||
if conf: | ||
widget = TextEditorWidget(configuration=conf) | ||
else: | ||
widget = None | ||
kwargs.setdefault("widget", widget) | ||
super().__init__(*args, **kwargs) | ||
|
||
def clean(self, value): | ||
value = super().clean(value) | ||
clean_value = clean_html(value, full=False) | ||
|
||
# We `mark_safe` here (as well as in the correct places) because Django | ||
# Parler cache's the value directly from the in-memory object as it | ||
# also stores the value in the database. So the cached version is never | ||
# processed by `from_db_value()`. | ||
clean_value = mark_safe(clean_value) | ||
|
||
return clean_value | ||
|
||
|
||
class HTMLField(models.TextField): | ||
def __init__(self, *args, **kwargs): | ||
# This allows widget configuration customization | ||
# from the model definition | ||
self.configuration = kwargs.pop("configuration", None) | ||
super().__init__(*args, **kwargs) | ||
|
||
def from_db_value(self, value, expression, connection, context=None): | ||
if value is None: | ||
return value | ||
return mark_safe(value) | ||
|
||
def to_python(self, value): | ||
# On Django >= 1.8 a new method | ||
# was introduced (from_db_value) which is called | ||
# whenever the value is loaded from the db. | ||
# And to_python is called for serialization and cleaning. | ||
# This means we don't need to add mark_safe on Django >= 1.8 | ||
# because it's handled by (from_db_value) | ||
if value is None: | ||
return value | ||
return value | ||
|
||
def formfield(self, **kwargs): | ||
if self.configuration: | ||
widget = TextEditorWidget(configuration=self.configuration) | ||
else: | ||
widget = TextEditorWidget | ||
|
||
defaults = { | ||
"form_class": HTMLFormField, | ||
"widget": widget, | ||
} | ||
defaults.update(kwargs) | ||
|
||
# override the admin widget | ||
if defaults["widget"] == admin_widgets.AdminTextareaWidget: | ||
defaults["widget"] = widget | ||
return super().formfield(**defaults) | ||
|
||
def clean(self, value, model_instance): | ||
# This needs to be marked safe as well because the form field's | ||
# clean method is not called on model.full_clean() | ||
value = super().clean(value, model_instance) | ||
return mark_safe(clean_html(value, full=False)) |
Oops, something went wrong.