Added project table

projects
Domeniko Gentner 4 years ago
parent b4edd48b72
commit 3df5f74ec3
  1. 13
      labertasche/database/__init__.py
  2. 1
      labertasche/models/__init__.py
  3. 3
      labertasche/models/t_comments.py
  4. 2
      labertasche/models/t_emails.py
  5. 2
      labertasche/models/t_location.py
  6. 21
      labertasche/models/t_projects.py
  7. 12
      server.py

@ -7,6 +7,17 @@
# * _license : This project is under MIT License
# *********************************************************************************/
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import MetaData
# naming conventions
convention = {
"ix": 'ix_%(column_0_label)s',
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_%(constraint_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s"
}
metadata = MetaData(naming_convention=convention)
# Create SQLAlchemy
labertasche_db = SQLAlchemy()
labertasche_db = SQLAlchemy(metadata=metadata)

@ -9,3 +9,4 @@
from .t_comments import TComments
from .t_location import TLocation
from .t_emails import TEmail
from .t_projects import TProjects

@ -28,7 +28,8 @@ class TComments(db.Model):
is_published = db.Column(db.Boolean, nullable=False)
is_spam = db.Column(db.Boolean, nullable=False)
spam_score = db.Column(db.Float, nullable=False)
replied_to = db.Column(db.Integer, ForeignKey('t_comments.comments_id'), nullable=True)
replied_to = db.Column(db.Integer, ForeignKey('t_comments.comments_id'), nullable=True, default=None)
confirmation = db.Column(db.Text, nullable=True)
deletion = db.Column(db.Text, nullable=True)
gravatar = db.Column(db.Text, nullable=True)
project_id = db.Column(db.Integer, ForeignKey('t_projects.id_project'), nullable=False)

@ -7,6 +7,7 @@
# * _license : This project is under MIT License
# *********************************************************************************/
from labertasche.database import labertasche_db as db
from sqlalchemy import ForeignKey
class TEmail(db.Model):
@ -21,3 +22,4 @@ class TEmail(db.Model):
email = db.Column(db.Integer, unique=True)
is_blocked = db.Column(db.Boolean)
is_allowed = db.Column(db.Boolean)
project_id = db.Column(db.Integer, ForeignKey('t_projects.id_project'), nullable=False)

@ -7,6 +7,7 @@
# * _license : This project is under MIT License
# *********************************************************************************/
from labertasche.database import labertasche_db as db
from sqlalchemy import ForeignKey
class TLocation(db.Model):
@ -19,3 +20,4 @@ class TLocation(db.Model):
# data
location = db.Column(db.Text, nullable=False, unique=True)
project_id = db.Column(db.Integer, ForeignKey('t_projects.id_project'), nullable=False)

@ -0,0 +1,21 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# /**********************************************************************************
# * _author : Domeniko Gentner
# * _mail : code@tuxstash.de
# * _repo : https://git.tuxstash.de/gothseidank/labertasche
# * _license : This project is under MIT License
# *********************************************************************************/
from labertasche.database import labertasche_db as db
class TProjects(db.Model):
# table name
__tablename__ = "t_projects"
__table_args__ = {'useexisting': True}
# primary key
id_project = db.Column(db.Integer, primary_key=True)
# data
name = db.Column(db.Text, nullable=True, unique=True)

@ -34,9 +34,15 @@ laberflask.config.update(dict(
SQLALCHEMY_TRACK_MODIFICATIONS=False
))
# flask migrate
# Flask migrate
migrate = Migrate(laberflask, labertasche_db, render_as_batch=True)
# Initialize ORM
labertasche_db.init_app(laberflask)
with laberflask.app_context():
labertasche_db.create_all()
# CORS
CORS(laberflask, resources={r"/comments": {"origins": settings.system['blog_url']}})
@ -49,10 +55,6 @@ laberflask.register_blueprint(bp_login)
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
# Initialize ORM
labertasche_db.init_app(laberflask)
with laberflask.app_context():
labertasche_db.create_all()
# Set up login manager
loginmgr = LoginManager(laberflask)

Loading…
Cancel
Save