Добавлен ckeditor для форматирования постов

main
Сергей Ванюшкин 2023-09-20 17:02:10 +03:00
parent 67e3d75235
commit 7440259588
8 changed files with 77 additions and 24 deletions

View File

@ -1,8 +1,8 @@
"""initial_migration
Revision ID: 70be0dbb9fbb
Revision ID: af05a1cbd975
Revises:
Create Date: 2023-09-18 21:01:48.648924
Create Date: 2023-09-19 22:57:11.510132
"""
import flask_security
@ -10,7 +10,7 @@ import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "70be0dbb9fbb"
revision = "af05a1cbd975"
down_revision = None
branch_labels = None
depends_on = None
@ -35,7 +35,7 @@ def upgrade():
)
op.create_table(
"tag",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("tag", sa.String(length=20), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
@ -76,9 +76,9 @@ def upgrade():
)
op.create_table(
"post",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("author", sa.Integer(), nullable=True),
sa.Column("slug", sa.String(length=30), nullable=True),
sa.Column("slug", sa.String(length=30), nullable=False),
sa.Column("title", sa.String(length=50), nullable=False),
sa.Column("published", sa.Boolean(), nullable=True),
sa.Column("create_datetime", sa.DateTime(), nullable=True),
@ -88,7 +88,7 @@ def upgrade():
["author"],
["user.id"],
),
sa.PrimaryKeyConstraint("id", "slug"),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("id"),
)
op.create_table(

30
poetry.lock generated
View File

@ -130,6 +130,20 @@ wtforms = "*"
aws = ["boto"]
azure = ["azure-storage-blob"]
[[package]]
name = "flask-ckeditor"
version = "0.4.6"
description = "CKEditor integration for Flask."
optional = false
python-versions = "*"
files = [
{file = "Flask-CKEditor-0.4.6.tar.gz", hash = "sha256:4b6aa0e831616b86c8c393cb1e5dcae8f62c66c16ef4316071dc7ccf77d4c9a1"},
{file = "Flask_CKEditor-0.4.6-py2.py3-none-any.whl", hash = "sha256:aa95bf2fab8d4379fcbe5786310bb4fbae467016ed0149c407101e0e4c278fa8"},
]
[package.dependencies]
Flask = "*"
[[package]]
name = "flask-login"
version = "0.6.2"
@ -249,6 +263,7 @@ files = [
{file = "greenlet-2.0.2-cp27-cp27m-win32.whl", hash = "sha256:6c3acb79b0bfd4fe733dff8bc62695283b57949ebcca05ae5c129eb606ff2d74"},
{file = "greenlet-2.0.2-cp27-cp27m-win_amd64.whl", hash = "sha256:283737e0da3f08bd637b5ad058507e578dd462db259f7f6e4c5c365ba4ee9343"},
{file = "greenlet-2.0.2-cp27-cp27mu-manylinux2010_x86_64.whl", hash = "sha256:d27ec7509b9c18b6d73f2f5ede2622441de812e7b1a80bbd446cb0633bd3d5ae"},
{file = "greenlet-2.0.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:d967650d3f56af314b72df7089d96cda1083a7fc2da05b375d2bc48c82ab3f3c"},
{file = "greenlet-2.0.2-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:30bcf80dda7f15ac77ba5af2b961bdd9dbc77fd4ac6105cee85b0d0a5fcf74df"},
{file = "greenlet-2.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:26fbfce90728d82bc9e6c38ea4d038cba20b7faf8a0ca53a9c07b67318d46088"},
{file = "greenlet-2.0.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:9190f09060ea4debddd24665d6804b995a9c122ef5917ab26e1566dcc712ceeb"},
@ -257,6 +272,7 @@ files = [
{file = "greenlet-2.0.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:76ae285c8104046b3a7f06b42f29c7b73f77683df18c49ab5af7983994c2dd91"},
{file = "greenlet-2.0.2-cp310-cp310-win_amd64.whl", hash = "sha256:2d4686f195e32d36b4d7cf2d166857dbd0ee9f3d20ae349b6bf8afc8485b3645"},
{file = "greenlet-2.0.2-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:c4302695ad8027363e96311df24ee28978162cdcdd2006476c43970b384a244c"},
{file = "greenlet-2.0.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:d4606a527e30548153be1a9f155f4e283d109ffba663a15856089fb55f933e47"},
{file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c48f54ef8e05f04d6eff74b8233f6063cb1ed960243eacc474ee73a2ea8573ca"},
{file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:a1846f1b999e78e13837c93c778dcfc3365902cfb8d1bdb7dd73ead37059f0d0"},
{file = "greenlet-2.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3a06ad5312349fec0ab944664b01d26f8d1f05009566339ac6f63f56589bc1a2"},
@ -286,6 +302,7 @@ files = [
{file = "greenlet-2.0.2-cp37-cp37m-win32.whl", hash = "sha256:3f6ea9bd35eb450837a3d80e77b517ea5bc56b4647f5502cd28de13675ee12f7"},
{file = "greenlet-2.0.2-cp37-cp37m-win_amd64.whl", hash = "sha256:7492e2b7bd7c9b9916388d9df23fa49d9b88ac0640db0a5b4ecc2b653bf451e3"},
{file = "greenlet-2.0.2-cp38-cp38-macosx_10_15_x86_64.whl", hash = "sha256:b864ba53912b6c3ab6bcb2beb19f19edd01a6bfcbdfe1f37ddd1778abfe75a30"},
{file = "greenlet-2.0.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:1087300cf9700bbf455b1b97e24db18f2f77b55302a68272c56209d5587c12d1"},
{file = "greenlet-2.0.2-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:ba2956617f1c42598a308a84c6cf021a90ff3862eddafd20c3333d50f0edb45b"},
{file = "greenlet-2.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fc3a569657468b6f3fb60587e48356fe512c1754ca05a564f11366ac9e306526"},
{file = "greenlet-2.0.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:8eab883b3b2a38cc1e050819ef06a7e6344d4a990d24d45bc6f2cf959045a45b"},
@ -294,6 +311,7 @@ files = [
{file = "greenlet-2.0.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:b0ef99cdbe2b682b9ccbb964743a6aca37905fda5e0452e5ee239b1654d37f2a"},
{file = "greenlet-2.0.2-cp38-cp38-win32.whl", hash = "sha256:b80f600eddddce72320dbbc8e3784d16bd3fb7b517e82476d8da921f27d4b249"},
{file = "greenlet-2.0.2-cp38-cp38-win_amd64.whl", hash = "sha256:4d2e11331fc0c02b6e84b0d28ece3a36e0548ee1a1ce9ddde03752d9b79bba40"},
{file = "greenlet-2.0.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8512a0c38cfd4e66a858ddd1b17705587900dd760c6003998e9472b77b56d417"},
{file = "greenlet-2.0.2-cp39-cp39-macosx_11_0_x86_64.whl", hash = "sha256:88d9ab96491d38a5ab7c56dd7a3cc37d83336ecc564e4e8816dbed12e5aaefc8"},
{file = "greenlet-2.0.2-cp39-cp39-manylinux2010_x86_64.whl", hash = "sha256:561091a7be172ab497a3527602d467e2b3fbe75f9e783d8b8ce403fa414f71a6"},
{file = "greenlet-2.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:971ce5e14dc5e73715755d0ca2975ac88cfdaefcaab078a284fea6cfabf866df"},
@ -430,6 +448,16 @@ files = [
{file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"},
{file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"},
{file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"},
{file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"},
{file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"},
{file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"},
{file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"},
{file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"},
{file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"},
{file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"},
{file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"},
{file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"},
{file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"},
{file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"},
{file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"},
{file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"},
@ -636,4 +664,4 @@ email = ["email-validator"]
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "5e2949c8ed8b545cd39083eb1486141cda4bb10ee12a445f5fab80c64c77aa9a"
content-hash = "478d9db5ee4ac55f1f1c92cac45605f713462b70072ca9125c6bb88fa15a98d0"

View File

@ -1,4 +1,5 @@
from flask_admin import Admin
from flask_ckeditor import CKEditor
admin = Admin(
name="Админ панель",

View File

@ -1,5 +1,6 @@
from flask import abort, redirect, request, url_for
from flask_admin.contrib import sqla
from flask_ckeditor import CKEditorField
from flask_security import current_user
@ -47,15 +48,20 @@ class TagView(MyAdminView):
class PostView(MyAdminView):
# form_excluded_columns = ("author", "create_datetime", "update_datetime")
column_list = (
"title",
"published",
)
column_labels = dict(
tags="Tags",
title="Title",
author="Author",
published="Published",
published_datetime="Pubdate",
)
# # form_excluded_columns = ("author", "create_datetime", "update_datetime")
# column_list = (
# "title",
# "published",
# )
# column_labels = dict(
# tags="Tags",
# title="Title",
# author="Author",
# published="Published",
# published_datetime="Pubdate",
# )
# override form type with CKEditorField
form_overrides = dict(text=CKEditorField)
create_template = "admin/edit.html"
edit_template = "admin/edit.html"

View File

@ -2,6 +2,7 @@ import os
from flask import Flask, render_template_string, request, url_for
from flask_admin import helpers
from flask_ckeditor import CKEditor
from flask_migrate import Migrate
from flask_security.core import Security
@ -25,6 +26,9 @@ def create_app(test_config=None):
db.init_app(app)
ckeditor = CKEditor()
ckeditor.init_app(app)
security = Security(app, user_datastore)
migrate = Migrate(db=db)
@ -56,7 +60,6 @@ def create_app(test_config=None):
@app.route("/ping")
def hello():
logging.info("Проверка ping-pong")
return render_template_string("pong")
return app

View File

@ -31,7 +31,7 @@ tag_post = db.Table(
class Tag(db.Model):
__tablename__ = "tag"
id = Column(Integer, primary_key=True)
id = Column(Integer, primary_key=True, autoincrement=True)
tag = Column(String(20))
def __str__(self) -> str:
@ -40,9 +40,11 @@ class Tag(db.Model):
class Post(db.Model):
__tablename__ = "post"
id = Column(Integer, primary_key=True, nullable=False, unique=True)
id = Column(
Integer, primary_key=True, nullable=False, unique=True, autoincrement=True
)
author = Column(Integer, db.ForeignKey("user.id"))
slug = Column(String(30), primary_key=True, nullable=True)
slug = Column(String(30), nullable=False)
title = Column(String(50), nullable=False)
published = Column(Boolean, default=False)
tags = db.relationship("Tag", secondary=tag_post)

View File

@ -0,0 +1,12 @@
{% extends 'admin/model/edit.html' %}
{% block tail %}
{{ super() }}
{{ ckeditor.load() }}
{#
if you have set the configuration variables more than CKEDITOR_SERVE_LOCAL and CKEDITOR_PKG_TYPE,
or you need to config the CKEditor textarea, use the line below to register the configuration.
The name value should be the name of the CKEditor form field.
#}
{{ ckeditor.config(name='Text') }}
{% endblock %}

View File

@ -16,6 +16,7 @@ flask-migrate = "^4.0.5"
flask-admin = "^1.6.1"
psycopg2 = "^2.9.7"
click = "^8.1.7"
flask-ckeditor = "^0.4.6"
[build-system]