From 9ede43ffb8a4fd40704736258d0897e171da9393 Mon Sep 17 00:00:00 2001 From: cleverson Date: Fri, 2 Feb 2024 12:23:07 -0300 Subject: [PATCH] =?UTF-8?q?adicionando=20flex-wrap=20para=20o=20footer,=20?= =?UTF-8?q?e=20adi=C3=A7=C3=A3o=20de=20conver=C3=A7=C3=A3o=20de=20datetime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/blog.py | 19 ++++++++++++++++++- app/models.py | 8 ++++---- static/css/style.css | 1 + templates/components/footer.html | 2 +- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/blog.py b/app/blog.py index 7a36104..58f659c 100644 --- a/app/blog.py +++ b/app/blog.py @@ -1,4 +1,5 @@ import uuid +import pytz from flask import Blueprint, request, redirect, render_template, abort from .models import Contents, db @@ -10,6 +11,13 @@ @blog.route('/', methods=['GET']) def get_blog(): contents = Contents.query.filter(Contents.status == "published").order_by(Contents.created_at.desc()).all() + + utc_timezone = pytz.timezone('UTC') + user_timezone = pytz.timezone('America/Sao_Paulo') + + for content in contents: + content.created_at = convert_datetime(content.created_at) + return render_template('index.html', contents=contents) @@ -25,7 +33,16 @@ def render_text(slug): title = data.title body = data.body - date = data.created_at.strftime("%d/%m/%Y, %H:%M %p") + date = convert_datetime(data.created_at).strftime("%d/%m/%Y, %H:%M %p") return render_template('blog/render_text.html', title=title, body=body, date=date) + +def convert_datetime(datetime): + utc_timezone = pytz.timezone('UTC') + user_timezone = pytz.timezone('America/Sao_Paulo') + + hour_utc = utc_timezone.localize(datetime) + return hour_utc.astimezone(user_timezone) + + diff --git a/app/models.py b/app/models.py index 9e431bf..42ef626 100644 --- a/app/models.py +++ b/app/models.py @@ -21,8 +21,8 @@ class Contents(db.Model): status = Column(String, CheckConstraint("status IN ('published', 'draft')"), default='draft') accessType = Column(String, CheckConstraint("type IN ('public', 'private')"), default='public') description = Column(String(1000), default='') - created_at = Column(DateTime, default=datetime.now) - updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now) + created_at = Column(DateTime, default=datetime.utcnow) + updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) def __init__(self, id: str, title: str, body:str, slug:str, status:str, accessType:str, description:str) -> None: @@ -42,8 +42,8 @@ class Users(db.Model): username = Column(String(50), nullable=False, unique=True) password = Column(String(100), nullable=False) userType = Column(String, CheckConstraint("userType IN ('admin' , 'user')"), nullable=False, default='user') - created_at = db.Column(db.DateTime, default=datetime.now) - updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now) + created_at = db.Column(db.DateTime, default=datetime.utcnow) + updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) def __init__(self, id:str, username: str, password:str, userType:str) -> None: self.id = id diff --git a/static/css/style.css b/static/css/style.css index 2d27d35..93f3881 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -339,6 +339,7 @@ footer{ .social-media{ display: flex; flex-direction: row; + flex-wrap: wrap; justify-content: center; gap: 25px; padding-top: 20px; diff --git a/templates/components/footer.html b/templates/components/footer.html index 7cc7936..063a123 100644 --- a/templates/components/footer.html +++ b/templates/components/footer.html @@ -3,7 +3,7 @@