From 50e74ccf385fc53ec7714d5804d40e7eb432c44f Mon Sep 17 00:00:00 2001 From: pi3c Date: Mon, 23 Oct 2023 10:03:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20ta?= =?UTF-8?q?g=20description=20=D0=BD=D0=B0=20=D1=81=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=86=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- migrations/versions/055327bef08e_.py | 33 +++++++++++++++++ migrations/versions/849ff22feb97_.py | 53 +++++++++++++++++++++++++++ pyproger/admin/views.py | 2 + pyproger/blog/urls.py | 17 ++++----- pyproger/dbase/models.py | 2 + pyproger/templates/blog/base.html | 1 + pyproger/templates/blog/index.html | 4 ++ pyproger/templates/blog/page.html | 4 ++ pyproger/templates/blog/postview.html | 4 ++ pyproger/templates/blog/tags.html | 4 ++ 10 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 migrations/versions/055327bef08e_.py create mode 100644 migrations/versions/849ff22feb97_.py diff --git a/migrations/versions/055327bef08e_.py b/migrations/versions/055327bef08e_.py new file mode 100644 index 0000000..2a4b881 --- /dev/null +++ b/migrations/versions/055327bef08e_.py @@ -0,0 +1,33 @@ +"""empty message + +Revision ID: 055327bef08e +Revises: 849ff22feb97 +Create Date: 2023-10-23 09:29:00.193470 + +""" +from alembic import op +import sqlalchemy as sa +import flask_security + + +# revision identifiers, used by Alembic. +revision = '055327bef08e' +down_revision = '849ff22feb97' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('page', schema=None) as batch_op: + batch_op.add_column(sa.Column('header_description', sa.Text(), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('page', schema=None) as batch_op: + batch_op.drop_column('header_description') + + # ### end Alembic commands ### diff --git a/migrations/versions/849ff22feb97_.py b/migrations/versions/849ff22feb97_.py new file mode 100644 index 0000000..3cdc1cf --- /dev/null +++ b/migrations/versions/849ff22feb97_.py @@ -0,0 +1,53 @@ +"""empty message + +Revision ID: 849ff22feb97 +Revises: 68537cc1688c +Create Date: 2023-10-23 08:34:08.251453 + +""" +from alembic import op +import sqlalchemy as sa +import flask_security + + +# revision identifiers, used by Alembic. +revision = '849ff22feb97' +down_revision = '68537cc1688c' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('footer_icons', schema=None) as batch_op: + batch_op.create_unique_constraint(None, ['id']) + + with op.batch_alter_table('page', schema=None) as batch_op: + batch_op.create_unique_constraint(None, ['id']) + + with op.batch_alter_table('post', schema=None) as batch_op: + batch_op.add_column(sa.Column('header_description', sa.Text(), nullable=True)) + batch_op.create_unique_constraint(None, ['id']) + + with op.batch_alter_table('site_headers', schema=None) as batch_op: + batch_op.create_unique_constraint(None, ['id']) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('site_headers', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='unique') + + with op.batch_alter_table('post', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='unique') + batch_op.drop_column('header_description') + + with op.batch_alter_table('page', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='unique') + + with op.batch_alter_table('footer_icons', schema=None) as batch_op: + batch_op.drop_constraint(None, type_='unique') + + # ### end Alembic commands ### diff --git a/pyproger/admin/views.py b/pyproger/admin/views.py index d1306f4..d26e2bd 100644 --- a/pyproger/admin/views.py +++ b/pyproger/admin/views.py @@ -72,6 +72,7 @@ class PostView(MyAdminView): tags="Тэги", slug="Слаг", title="Заголовок", + header_description="description заголовок в head страницы", description="Краткое описание статьи", author="Автор", published="Опубликовано", @@ -92,6 +93,7 @@ class PostView(MyAdminView): class PageView(MyAdminView): column_labels = dict( name="Название страницы", + header_description="description заголовок в head страницы", slug="URL страницы", text="Содержимое страницы", ) diff --git a/pyproger/blog/urls.py b/pyproger/blog/urls.py index 47a7395..8b70ae7 100644 --- a/pyproger/blog/urls.py +++ b/pyproger/blog/urls.py @@ -1,15 +1,11 @@ import locale import re -from flask import abort, current_app, redirect, render_template, request, url_for +from flask import (abort, current_app, redirect, render_template, request, + url_for) -from ..dbase.database import ( - get_all_posts_by_tag, - get_page, - get_paginated_posts, - get_post, - get_tags, -) +from ..dbase.database import (get_all_posts_by_tag, get_page, + get_paginated_posts, get_post, get_tags) from .blog import bp locale.setlocale(locale.LC_ALL, ("ru", "utf-8")) @@ -29,6 +25,7 @@ def index(page=1): return render_template( "blog/index.html", title=f'{current_app.config.get("BRAND")} - разговоры про питон', + header_description="Про изучение python, веб разработку и прочие вещи", headers=current_app.config.get("SITE_HEADERS"), menu_title=current_app.config.get("BRAND"), menu_items=current_app.config.get("MENU_ITEMS"), @@ -77,6 +74,7 @@ def get_all_tags(): return render_template( "blog/tags.html", title=f'{current_app.config.get("BRAND")} - поиск по тэгу', + header_description="Выбор статей по тематике", headers=current_app.config.get("SITE_HEADERS"), menu_title=current_app.config.get("BRAND"), tags=tags, @@ -91,7 +89,6 @@ def get_all_tags(): def get_posts_by_tag(page=1, tag=None): per_page = current_app.config.get("POSTS_ON_PAGE") posts, total = get_all_posts_by_tag(tag, page, per_page) - if posts is None: abort(404) @@ -104,6 +101,7 @@ def get_posts_by_tag(page=1, tag=None): return render_template( "blog/tagget_posts.html", title=f'{current_app.config.get("BRAND")} - посты по {tag}', + header_description=f"Статьи по теме {tag}", headers=current_app.config.get("SITE_HEADERS"), menu_title=current_app.config.get("BRAND"), menu_items=current_app.config.get("MENU_ITEMS"), @@ -125,6 +123,7 @@ def page(slug=None): return render_template( "blog/page.html", title=f'{current_app.config.get("BRAND")} - {page.name}', + header_description=page.header_description, headers=current_app.config.get("SITE_HEADERS"), menu_title=current_app.config.get("BRAND"), menu_items=current_app.config.get("MENU_ITEMS"), diff --git a/pyproger/dbase/models.py b/pyproger/dbase/models.py index 5a2012e..5130a85 100644 --- a/pyproger/dbase/models.py +++ b/pyproger/dbase/models.py @@ -72,6 +72,7 @@ class Post(db.Model): author = Column(Integer, db.ForeignKey("user.id")) slug = Column(String(100), nullable=False) title = Column(Text, nullable=False) + header_description = Column(Text) description = Column(Text, nullable=False) published = Column(Boolean, default=False) tags = db.relationship("Tag", secondary=tag_post) @@ -99,6 +100,7 @@ class Page(db.Model): unique=True, autoincrement=True, ) + header_description = Column(Text) name = Column(String(20)) slug = Column(String(50), nullable=False) text = Column(Text) diff --git a/pyproger/templates/blog/base.html b/pyproger/templates/blog/base.html index a29614a..3ecdc2e 100644 --- a/pyproger/templates/blog/base.html +++ b/pyproger/templates/blog/base.html @@ -6,6 +6,7 @@ {% block title %}{% endblock title %} + {% for h in headers %} {{h.content | safe}} {% endfor %} diff --git a/pyproger/templates/blog/index.html b/pyproger/templates/blog/index.html index a6e5347..18a591b 100644 --- a/pyproger/templates/blog/index.html +++ b/pyproger/templates/blog/index.html @@ -4,6 +4,10 @@ {{title}} {% endblock %} +{% block header_description %} + {{ header_description }} +{% endblock %} + {% block menu_title %} {{ menu_title }} {% endblock %} diff --git a/pyproger/templates/blog/page.html b/pyproger/templates/blog/page.html index 9eb1225..ae8f84f 100644 --- a/pyproger/templates/blog/page.html +++ b/pyproger/templates/blog/page.html @@ -8,6 +8,10 @@ {{ menu_title }} {% endblock %} +{% block header_description %} + {{ header_description }} +{% endblock %} + {% block content %}
diff --git a/pyproger/templates/blog/postview.html b/pyproger/templates/blog/postview.html index 1b06b93..dda7e1e 100644 --- a/pyproger/templates/blog/postview.html +++ b/pyproger/templates/blog/postview.html @@ -4,6 +4,10 @@ {{ title }} {% endblock %} +{% block header_description%} + {{ post.Post.header_description }} +{% endblock%} + {% block menu_title %} {{ menu_title }} {% endblock %} diff --git a/pyproger/templates/blog/tags.html b/pyproger/templates/blog/tags.html index dd5cb8c..18eadb2 100644 --- a/pyproger/templates/blog/tags.html +++ b/pyproger/templates/blog/tags.html @@ -4,6 +4,10 @@ {{title}} {% endblock %} +{% block header_description %} + {{ header_description }} +{% endblock %} + {% block menu_title %} {{ menu_title }} {% endblock %}