Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the post editor plugin #368

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add ckeditor-5 for post and comment body.
Signed-off-by: Grant Ramsay <seapagan@gmail.com>
seapagan committed Oct 10, 2024
commit 27f2328cda7aa7e39f6a9d780b58fe1dc5a71bee
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -31,7 +31,9 @@ repos:
# - id: mypy
# name: "run mypy"
# additional_dependencies:
# - "types-requests"
# - "django-stubs"
# - "python-dotenv"
# - "django-user-sessions"

- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
2 changes: 1 addition & 1 deletion blog/feeds.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ class PostsFeed(Feed):
title = "Tek:Cited Posts"
link = "/"
description = "Updates from Tek:Cited."
feed_copyright = "Copyright (c) 2021, Seapagan"
feed_copyright = "Copyright (c) 2021-2024, Seapagan"
feed_type = CorrectMimeTypeFeed

def items(self):
7 changes: 3 additions & 4 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
from django.db import models
from django.template.defaultfilters import slugify
from django.urls import reverse
from django_ckeditor_5.fields import CKEditor5Field
from django_stubs_ext.db.models import TypedModelMeta
from hitcount.conf import settings as hitcount_settings
from hitcount.mixins import HitCountModelMixin
@@ -54,8 +55,7 @@ class Blog(models.Model, HitCountModelMixin):
desc = models.CharField(max_length=250)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
# body = RichTextUploadingField(config_name="post")
body = models.TextField()
body = CKEditor5Field("Post", config_name="extends")
slug = models.SlugField(default="", unique=True)
image = models.ImageField(
upload_to=get_upload_path,
@@ -139,8 +139,7 @@ class Comment(models.Model):
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
# body = RichTextField(config_name="comment", blank=True)
body = models.TextField()
body = CKEditor5Field("Comment", config_name="extends")

class Meta(TypedModelMeta):
"""Meta configuration for the Blog model."""
15 changes: 4 additions & 11 deletions blog/templates/blog/blog_newpost.html
Original file line number Diff line number Diff line change
@@ -7,26 +7,19 @@
<div class="new_post_user">You are Logged in as
<strong>{{ user.username }}</strong>
</div>
<form method="post"
enctype="multipart/form-data">

<form method="post">
{% include 'blog/common/post_form.html' %}

<div class="new_post_buttons">
<button class="btn btn_alt"
type="submit"
name="draft"
value="Draft">
<button class="btn btn_alt" type="submit" name="draft" value="Draft">
<span class="fad fa-save"></span>
&nbsp;Save as DRAFT
</button>
<button class="btn btn_success"
type="submit">
<button class="btn btn_success" type="submit">
<span class="fad fa-comment-alt-check"></span>
&nbsp;Publish!
</button>
<a class="btn"
href="{% url 'blog:index' %}">
<a class="btn" href="{% url 'blog:index' %}">
<span class="fad fa-ban"></span>
&nbsp;Cancel</a>
</div>
1 change: 1 addition & 0 deletions blog/templates/blog/common/post_form.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% csrf_token %}
{{ form.errors }}
{{ form.media }}
{% for field in form %}
{% comment %} first loop on form fields {% endcomment %}
98 changes: 94 additions & 4 deletions pyblog/settings.py
Original file line number Diff line number Diff line change
@@ -51,9 +51,9 @@
"blog",
"users",
"hitcount",
"django_ckeditor_5",
]

# HTML_MINIFY = True

# only include the Admin paths if we are in DEBUG mode
if DEBUG:
@@ -75,7 +75,6 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"dj_pagination.middleware.PaginationMiddleware",
"likes.middleware.SecretBallotUserIpUseragentMiddleware",
# "htmlmin.middleware.HtmlMinifyMiddleware",
# "htmlmin.middleware.MarkRequestMiddleware",
]

@@ -153,7 +152,6 @@

# Setup Email backend
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
# EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
EMAIL_HOST = str(os.getenv("EMAIL_HOST"))
EMAIL_PORT = str(os.getenv("EMAIL_PORT"))
EMAIL_USE_TLS = str(os.getenv("EMAIL_USE_TLS"))
@@ -304,7 +302,7 @@
}

# Secret Ballot settings.
SECRETBALLOT_FOR_MODELS = {
SECRETBALLOT_FOR_MODELS:dict[str,dict] = {
"blog.Blog": {},
}

@@ -319,3 +317,95 @@
# rundevserver settings
RDS_ALL_INTERFACES = True
RDS_DEBUG = True


customColorPalette = [
{
'color': 'hsl(4, 90%, 58%)',
'label': 'Red'
},
{
'color': 'hsl(340, 82%, 52%)',
'label': 'Pink'
},
{
'color': 'hsl(291, 64%, 42%)',
'label': 'Purple'
},
{
'color': 'hsl(262, 52%, 47%)',
'label': 'Deep Purple'
},
{
'color': 'hsl(231, 48%, 48%)',
'label': 'Indigo'
},
{
'color': 'hsl(207, 90%, 54%)',
'label': 'Blue'
},
]

CKEDITOR_5_CONFIGS = {
'default': {
'toolbar': ['heading', '|', 'bold', 'italic', 'link',
'bulletedList', 'numberedList', 'blockQuote', 'imageUpload', ],

},
'extends': {
'blockToolbar': [
'paragraph', 'heading1', 'heading2', 'heading3',
'|',
'bulletedList', 'numberedList',
'|',
'blockQuote',
],
'toolbar': ['heading', '|', 'outdent', 'indent', '|', 'bold', 'italic', 'link', 'underline', 'strikethrough',
'code','subscript', 'superscript', 'highlight', '|', 'codeBlock', 'sourceEditing', 'insertImage',
'bulletedList', 'numberedList', 'todoList', '|', 'blockQuote', 'imageUpload', '|',
'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', 'mediaEmbed', 'removeFormat',
'insertTable',],
'image': {
'toolbar': ['imageTextAlternative', '|', 'imageStyle:alignLeft',
'imageStyle:alignRight', 'imageStyle:alignCenter', 'imageStyle:side', '|'],
'styles': [
'full',
'side',
'alignLeft',
'alignRight',
'alignCenter',
]

},
'table': {
'contentToolbar': [ 'tableColumn', 'tableRow', 'mergeTableCells',
'tableProperties', 'tableCellProperties' ],
'tableProperties': {
'borderColors': customColorPalette,
'backgroundColors': customColorPalette
},
'tableCellProperties': {
'borderColors': customColorPalette,
'backgroundColors': customColorPalette
}
},
'heading' : {
'options': [
{ 'model': 'paragraph', 'title': 'Paragraph', 'class': 'ck-heading_paragraph' },
{ 'model': 'heading1', 'view': 'h1', 'title': 'Heading 1', 'class': 'ck-heading_heading1' },
{ 'model': 'heading2', 'view': 'h2', 'title': 'Heading 2', 'class': 'ck-heading_heading2' },
{ 'model': 'heading3', 'view': 'h3', 'title': 'Heading 3', 'class': 'ck-heading_heading3' }
]
}
},
'list': {
'properties': {
'styles': 'true',
'startIndex': 'true',
'reversed': 'true',
}
}
}

# Define a constant in settings.py to specify file upload permissions
CKEDITOR_5_FILE_UPLOAD_PERMISSION = "authenticated" # Possible values: "staff", "authenticated", "any"
1 change: 1 addition & 0 deletions pyblog/urls.py
Original file line number Diff line number Diff line change
@@ -49,6 +49,7 @@
path("likes/", include("likes.urls")),
path("maintenance-mode/", include("maintenance_mode.urls")),
path("", include("user_sessions.urls", "user_sessions")),
path("ckeditor5/", include("django_ckeditor_5.urls")),
]
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ dependencies = [
"requests>=2.32.3",
"dj-pagination",
"django-likes",
"django-ckeditor-5>=0.2.13",
]

[project.urls]
5 changes: 2 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -16,16 +16,15 @@ colorama==0.4.6
columnar==1.4.1
coverage==7.6.2
csscompressor==0.9.5
distlib==0.3.8
distlib==0.3.9
dj-hitcount==1.3.0
dj-pagination @ git+https://github.com/seapagan/dj-pagination.git@7a6b7b7bfd21dd5232b2dae43de7f8010165e94a
django==5.1.2
django-appconf==1.0.6
django-ckeditor==6.7.1
django-ckeditor-5==0.2.13
django-compressor==4.5.1
django-etc==1.4.0
django-gravatar2==1.4.5
django-js-asset==2.2.0
django-likes @ git+https://github.com/seapagan/django-likes.git@c60a7f54cfb4de2e8bf941b0e06e49ad1113ccc7
django-maintenance-mode==0.21.1
django-recaptcha==4.0.0
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -12,11 +12,10 @@ dj-hitcount==1.3.0
dj-pagination @ git+https://github.com/seapagan/dj-pagination.git@7a6b7b7bfd21dd5232b2dae43de7f8010165e94a
django==5.1.2
django-appconf==1.0.6
django-ckeditor==6.7.1
django-ckeditor-5==0.2.13
django-compressor==4.5.1
django-etc==1.4.0
django-gravatar2==1.4.5
django-js-asset==2.2.0
django-likes @ git+https://github.com/seapagan/django-likes.git@c60a7f54cfb4de2e8bf941b0e06e49ad1113ccc7
django-maintenance-mode==0.21.1
django-recaptcha==4.0.0
21 changes: 18 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.