littlefix

main
Сергей Ванюшкин 2023-09-22 09:00:58 +03:00
parent 2cf2b3d0c0
commit 23e8a2e492
3 changed files with 41 additions and 76 deletions

View File

@ -13,17 +13,10 @@ class MyAdminView(sqla.ModelView):
) )
def _handle_view(self, name, **kwargs): def _handle_view(self, name, **kwargs):
"""
Override builtin _handle_view in
order to redirect users when a
view is not accessible.
"""
if not self.is_accessible(): if not self.is_accessible():
if current_user.is_authenticated: if current_user.is_authenticated:
# permission denied
abort(403) abort(403)
else: else:
# login
return redirect(url_for("security.login", next=request.url)) return redirect(url_for("security.login", next=request.url))
@ -59,7 +52,10 @@ class RoleView(MyAdminView):
"name", "name",
"description", "description",
) )
column_labels = dict(name="Название", description="Описание") column_labels = dict(
name="Название",
description="Описание",
)
class TagView(MyAdminView): class TagView(MyAdminView):
@ -67,12 +63,6 @@ class TagView(MyAdminView):
class PostView(MyAdminView): class PostView(MyAdminView):
# form_excluded_columns = (
# "author",
# "create_datetime",
# "update_datetime",
# "text",
# )
column_list = ( column_list = (
"title", "title",
"published", "published",
@ -89,7 +79,6 @@ class PostView(MyAdminView):
text="Текст", text="Текст",
) )
# override form type with CKEditorField
form_overrides = dict(text=CKEditorField) form_overrides = dict(text=CKEditorField)
create_template = "admin/edit.html" create_template = "admin/edit.html"
edit_template = "admin/edit.html" edit_template = "admin/edit.html"

View File

@ -2,46 +2,71 @@ import datetime
from flask_security.models import fsqla from flask_security.models import fsqla
from sqlalchemy import Boolean, Column, DateTime, Integer, String, Text from sqlalchemy import Boolean, Column, DateTime, Integer, String, Text
from sqlalchemy.util import unique_list
from . import db from . import db
class Role(db.Model, fsqla.FsRoleMixin): class Role(db.Model, fsqla.FsRoleMixin):
def __str__(self) -> str: name = Column(
String(80),
unique=True,
nullable=False,
)
def __str__(self):
return self.name return self.name
class User(db.Model, fsqla.FsUserMixin): class User(db.Model, fsqla.FsUserMixin):
first_name = Column(String(255)) first_name = Column(String(255))
last_name = Column(String(255)) last_name = Column(String(255))
posts = db.relationship("Post", backref="user", lazy="dynamic") posts = db.relationship(
"Post",
backref="user",
lazy="dynamic",
)
def __str__(self) -> str: def __str__(self):
return self.email return self.email
tag_post = db.Table( tag_post = db.Table(
"tag_post", "tag_post",
db.Column("tag_id", db.Integer, db.ForeignKey("tag.id")), db.Column(
db.Column("post_id", db.Integer, db.ForeignKey("post.id")), "tag_id",
db.Integer,
db.ForeignKey("tag.id"),
),
db.Column(
"post_id",
db.Integer,
db.ForeignKey("post.id"),
),
) )
class Tag(db.Model): class Tag(db.Model):
__tablename__ = "tag" __tablename__ = "tag"
id = Column(Integer, primary_key=True, autoincrement=True) id = Column(
Integer,
primary_key=True,
autoincrement=True,
)
tag = Column(String(20)) tag = Column(String(20))
def __str__(self) -> str: def __str__(self):
return self.tag return self.tag
class Post(db.Model): class Post(db.Model):
__tablename__ = "post" __tablename__ = "post"
id = Column( id = Column(
Integer, primary_key=True, nullable=False, unique=True, autoincrement=True Integer,
primary_key=True,
nullable=False,
unique=True,
autoincrement=True,
) )
author = Column(Integer, db.ForeignKey("user.id")) author = Column(Integer, db.ForeignKey("user.id"))
slug = Column(String(30), nullable=False) slug = Column(String(30), nullable=False)
@ -50,7 +75,9 @@ class Post(db.Model):
tags = db.relationship("Tag", secondary=tag_post) tags = db.relationship("Tag", secondary=tag_post)
create_datetime = Column( create_datetime = Column(
DateTime(), nullable=True, default=datetime.datetime.utcnow() DateTime(),
nullable=True,
default=datetime.datetime.utcnow(),
) )
update_datetime = Column( update_datetime = Column(
DateTime(), DateTime(),

View File

@ -1,51 +0,0 @@
# Russian translations for PROJECT.
# Copyright (C) 2023 ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2023.
#
msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2023-07-03 23:52+0300\n"
"PO-Revision-Date: 2023-07-02 22:55+0300\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: ru\n"
"Language-Team: ru <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && "
"n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"
#: pi3code/admin/views.py:64
msgid "Tags"
msgstr "Тэги"
#: pi3code/admin/views.py:65
msgid "Title"
msgstr "Заголовок"
#: pi3code/admin/views.py:66
msgid "Author"
msgstr "Автор"
#: pi3code/admin/views.py:67
msgid "Published"
msgstr "Опубликован"
#: pi3code/admin/views.py:68
msgid "Publication day"
msgstr "Дата публикации"
#: pi3code/templates/admin/index.html:29
msgid "Back"
msgstr "Назад"
#~ msgid "Name"
#~ msgstr "тема"
#~ msgid "\"\"Translation and localization commands.\"\""
#~ msgstr "\"\"Команды для перевода и локализации\"\""