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
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion blog/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
233 changes: 55 additions & 178 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,219 +1,96 @@
"""Database Migration."""
# Generated by Django 3.2.13 on 2022-06-29 13:03
# Generated by Django 5.1.2 on 2024-10-09 17:01

import ckeditor.fields
import ckeditor_uploader.fields
import blog.models
import django.db.models.deletion
import django.db.models.manager
import hitcount.mixins
from django.conf import settings
from django.db import migrations, models

import blog.models


class Migration(migrations.Migration):
"""Define the Initial database migration for the blog app."""

initial = True

dependencies = [
('preferences', '0001_initial'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("preferences", "0001_initial"),
]

operations = [
migrations.CreateModel(
name="Blog",
name='Blog',
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=50)),
("desc", models.CharField(max_length=250)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("body", ckeditor_uploader.fields.RichTextUploadingField()),
("slug", models.SlugField(default="", unique=True)),
(
"image",
models.ImageField(
blank=True,
null=True,
storage=blog.models.OverwriteStorage(),
upload_to=blog.models.get_upload_path,
),
),
("draft", models.BooleanField(default=False)),
(
"image_attrib_name",
models.CharField(blank=True, default="", max_length=50),
),
(
"image_attrib_name_link",
models.CharField(blank=True, default="", max_length=100),
),
(
"image_attrib_site",
models.CharField(blank=True, default="", max_length=50),
),
(
"image_attrib_site_link",
models.URLField(blank=True, default=""),
),
(
"user",
models.ForeignKey(
default=1,
on_delete=django.db.models.deletion.CASCADE,
related_name="blog_posts",
to=settings.AUTH_USER_MODEL,
),
),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('desc', models.CharField(max_length=250)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('body', models.TextField()),
('slug', models.SlugField(default='', unique=True)),
('image', models.ImageField(blank=True, null=True, storage=blog.models.OverwriteStorage(), upload_to=blog.models.get_upload_path)),
('draft', models.BooleanField(default=False)),
('image_attrib_name', models.CharField(blank=True, default='', max_length=50)),
('image_attrib_name_link', models.CharField(blank=True, default='', max_length=100)),
('image_attrib_site', models.CharField(blank=True, default='', max_length=50)),
('image_attrib_site_link', models.URLField(blank=True, default='')),
('user', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, related_name='blog_posts', to=settings.AUTH_USER_MODEL)),
],
options={
"ordering": ["-created_at"],
'ordering': ['-created_at'],
},
bases=(models.Model, hitcount.mixins.HitCountModelMixin),
),
migrations.CreateModel(
name="Tag",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("tag_name", models.CharField(max_length=15)),
("slug", models.SlugField(default="", unique=True)),
("posts", models.ManyToManyField(blank=True, to="blog.Blog")),
(
"tag_creator",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="tags",
to=settings.AUTH_USER_MODEL,
),
),
],
),
migrations.CreateModel(
name="SitePreferences",
name='Comment',
fields=[
(
"preferences_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to="preferences.preferences",
),
),
(
"sitename",
models.CharField(default="My Sexy Blog", max_length=50),
),
("title", models.CharField(default="My Blog", max_length=20)),
(
"heading",
models.CharField(
default="A blog of blogging blogosity.", max_length=200
),
),
("twitter_site", models.CharField(default="", max_length=50)),
(
"pinned_post",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="blog.blog",
),
),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_by_guest', models.CharField(blank=True, max_length=50)),
('guest_email', models.EmailField(blank=True, max_length=254)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('body', models.TextField()),
('created_by_user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='comments', to=settings.AUTH_USER_MODEL)),
('related_post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='blog.blog')),
],
options={
"verbose_name_plural": "Site Preferences",
'ordering': ['created_at'],
},
bases=("preferences.preferences",),
managers=[
("singleton", django.db.models.manager.Manager()),
],
),
migrations.CreateModel(
name="Redirect",
name='Redirect',
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("old_slug", models.SlugField(default="", unique=True)),
(
"old_post",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="blog.blog",
),
),
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('old_slug', models.SlugField(default='', unique=True)),
('old_post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.blog')),
],
),
migrations.CreateModel(
name="Comment",
name='SitePreferences',
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"created_by_guest",
models.CharField(blank=True, max_length=50),
),
("guest_email", models.EmailField(blank=True, max_length=254)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("body", ckeditor.fields.RichTextField(blank=True)),
(
"created_by_user",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="comments",
to=settings.AUTH_USER_MODEL,
),
),
(
"related_post",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="comments",
to="blog.blog",
),
),
('preferences_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='preferences.preferences')),
('sitename', models.CharField(default='My Sexy Blog', max_length=50)),
('title', models.CharField(default='My Blog', max_length=20)),
('heading', models.CharField(default='A blog of blogging blogosity.', max_length=200)),
('twitter_site', models.CharField(default='', max_length=50)),
('pinned_post', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='blog.blog')),
],
options={
"ordering": ["created_at"],
'verbose_name_plural': 'Site Preferences',
},
bases=('preferences.preferences',),
managers=[
('singleton', django.db.models.manager.Manager()),
],
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tag_name', models.CharField(max_length=15)),
('slug', models.SlugField(default='', unique=True)),
('posts', models.ManyToManyField(blank=True, to='blog.blog')),
('tag_creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tags', to=settings.AUTH_USER_MODEL)),
],
),
]
7 changes: 3 additions & 4 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
from pathlib import Path
from typing import Any, Optional

from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericRelation
from django.core.files.storage import FileSystemStorage
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
Expand Down Expand Up @@ -56,7 +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 = CKEditor5Field("Post", config_name="extends")
slug = models.SlugField(default="", unique=True)
image = models.ImageField(
upload_to=get_upload_path,
Expand Down Expand Up @@ -140,7 +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 = CKEditor5Field("Comment", config_name="extends")

class Meta(TypedModelMeta):
"""Meta configuration for the Blog model."""
Expand Down
15 changes: 4 additions & 11 deletions blog/templates/blog/blog_newpost.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
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 %}
Expand Down
Loading