diff --git a/migrations/versions/5e6d181b4b74_.py b/migrations/versions/5e6d181b4b74_.py new file mode 100644 index 0000000..2cd7112 --- /dev/null +++ b/migrations/versions/5e6d181b4b74_.py @@ -0,0 +1,34 @@ +"""empty message + +Revision ID: 5e6d181b4b74 +Revises: e24055e16b26 +Create Date: 2023-10-04 08:46:50.473590 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '5e6d181b4b74' +down_revision = 'e24055e16b26' +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('update_datetime', sa.DateTime(), nullable=True)) + batch_op.create_unique_constraint(None, ['id']) + + # ### 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_constraint(None, type_='unique') + batch_op.drop_column('update_datetime') + + # ### end Alembic commands ### diff --git a/pyproger/dbase/database.py b/pyproger/dbase/database.py index 0169898..9582057 100644 --- a/pyproger/dbase/database.py +++ b/pyproger/dbase/database.py @@ -71,9 +71,3 @@ def get_posts_for_sitemap(): .all() ) return posts - - -def get_pages_for_sitemap(): - pages = db.session.query(Page.slug).all() - date = datetime.utcnow().strftime("%Y-%m-%d") - return pages, date diff --git a/pyproger/dbase/models.py b/pyproger/dbase/models.py index abb25d9..218d336 100644 --- a/pyproger/dbase/models.py +++ b/pyproger/dbase/models.py @@ -102,3 +102,8 @@ class Page(db.Model): name = Column(String(20)) slug = Column(String(50), nullable=False) text = Column(Text) + update_datetime = Column( + DateTime(), + default=func.now(), + onupdate=func.now(), + ) diff --git a/pyproger/robots/urls.py b/pyproger/robots/urls.py index b12642b..89e8084 100644 --- a/pyproger/robots/urls.py +++ b/pyproger/robots/urls.py @@ -1,7 +1,7 @@ from flask import make_response, render_template from sqlalchemy.sql import func -from pyproger.dbase.database import get_pages_for_sitemap, get_posts_for_sitemap +from pyproger.dbase.database import get_posts_for_sitemap from .robots import bp @@ -9,12 +9,9 @@ from .robots import bp @bp.route("/sitemap.xml", methods=["GET"]) def sitemap_xml(): sm_posts = get_posts_for_sitemap() - sm_pages, date = get_pages_for_sitemap() sm_render = render_template( "robots/sitemap.xml", - sm_pages=sm_pages, sm_posts=sm_posts, - date=date, ) response = make_response(sm_render) response.headers["Content-Type"] = "application/rss+xml" diff --git a/pyproger/templates/robots/sitemap.xml b/pyproger/templates/robots/sitemap.xml index a05e521..8b07b9a 100644 --- a/pyproger/templates/robots/sitemap.xml +++ b/pyproger/templates/robots/sitemap.xml @@ -1,6 +1,5 @@ - {% for p in sm_posts %} http://www.pyproger.ru/post/{{ p.slug }}