from flask_user import UserMixin from werkzeug.security import generate_password_hash, check_password_hash from website import db, app post_tags = db.Table( 'post_tags', db.Column('tag_id', db.Integer, db.ForeignKey('tags.id')), db.Column('post_id', db.Integer, db.ForeignKey('post.post_id'))) class Tags(db.Model): __tablename__ = 'tags' id = db.Column(db.Integer, primary_key=True) tagname = db.Column(db.String(100)) course_author = db.Table( 'course_author', db.Column('course_id', db.Integer, db.ForeignKey('course.course_id')), db.Column('author_id', db.Integer, db.ForeignKey('user.user_id'))) class User(db.Model, UserMixin): __tablename__ = 'user' user_id = db.Column(db.INTEGER, primary_key=True) user_name = db.Column(db.String(120), nullable=False) user_qq = db.Column(db.String(120)) user_mail = db.Column(db.String(120)) password = db.Column(db.String(120)) post = db.relationship('Post', backref='author', lazy='dynamic')
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from sqlalchemy import sql from website import db association_table = db.Table( "category_blog_association", db.Column("blogs_id", db.Integer(), db.ForeignKey("blogs.id")), db.Column("categories_id", db.Integer(), db.ForeignKey("categories.id")), ) class Category(db.Model): # type: ignore __tablename__ = "categories" id = db.Column(db.Integer(), primary_key=True) title = db.Column(db.String(100), index=True, unique=True, nullable=False) slug = db.Column(db.String(200), unique=True, nullable=False) description = db.Column(db.String(150), nullable=False) created_at = db.Column( db.DateTime(timezone=True), server_default=sql.func.current_timestamp(),
from datetime import datetime from hashlib import md5 from time import time from flask_login import UserMixin from werkzeug.security import generate_password_hash, check_password_hash import jwt from website import app, db, login marked = db.Table( 'marked', db.Column('user_id', db.Integer, db.ForeignKey('user.id')), db.Column('problem_id', db.Integer, db.ForeignKey('problem.id'))) class Problem(db.Model): id = db.Column(db.Integer, primary_key=True) problem_name = db.Column(db.String(64), index=True) problem_link = db.Column(db.String(64), index=True, unique=True) keywords = db.Column(db.String(140), index=True) class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(64), index=True, unique=True) email = db.Column(db.String(120), index=True, unique=True) password_hash = db.Column(db.String(128)) marked_problems = db.relationship( 'Problem', secondary=marked, primaryjoin=(marked.c.user_id == id), secondaryjoin="marked.c.problem_id==Problem.id",
from website import db tags_posts = db.Table( 'tags-posts', db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True), db.Column('post_id', db.Integer, db.ForeignKey('post.id'), primary_key=True)) class Tag(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False) class Category(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(120), nullable=False) posts = db.relationship('Post', backref='category', lazy='dynamic') class Slider(db.Model): id = db.Column(db.Integer, primary_key=True) post_id = db.Column(db.Integer, db.ForeignKey('post.id')) class Post(db.Model): id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
from website import db from flask_login import UserMixin from werkzeug.security import check_password_hash, generate_password_hash authorities_users = db.Table('authorities-users', db.Column('authority_id', db.Integer, db.ForeignKey( 'authority.id'), primary_key=True), db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True)) class Authority(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(30)) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) authorities = db.relationship('Authority', secondary=authorities_users, backref='user', lazy='dynamic') first_name = db.Column(db.String(120), nullable=False) last_name = db.Column(db.String(120), nullable=False) username = db.Column(db.String(120), nullable=False) password_hash = db.Column(db.String(120), nullable=False) img_url = db.Column(db.String(120), nullable=True) student_id = db.Column(db.Integer, db.ForeignKey('student.id')) professor_id = db.Column(db.Integer, db.ForeignKey('professor.id')) posts = db.relationship('Post', backref='user', lazy='dynamic') verify = db.Column(db.Boolean,nullable=False) def isAdmin(self): for auth in self.authorities: if auth.name == "Admin":
from website import db from website.mod_student.models import Student from website.mod_professor.models import Professor teachers_courses = db.Table( 'teachers-courses', db.Column('teacher_id', db.Integer, db.ForeignKey('professor.id'), primary_key=True), db.Column('course_id', db.Integer, db.ForeignKey('course.id'), primary_key=True)) students_courses = db.Table( 'students-courses', db.Column('student_id', db.Integer, db.ForeignKey('student.id'), primary_key=True), db.Column('course_id', db.Integer, db.ForeignKey('course.id'), primary_key=True)) class Slide(db.Model): id = db.Column(db.Integer, primary_key=True) url = db.Column(db.String(120), nullable=False) name = db.Column(db.String(120), nullable=False)
id = db.Column(db.Integer, primary_key=True) sender_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) text = db.Column(db.Text(200), nullable=False) chat_id = db.Column(db.Integer, db.ForeignKey('chat.id'), nullable=False) sender = db.relationship('User', backref='sent_messages', lazy=True) def __repr__(self): return "User ({}, {})".format(self.sender_id, self.text) chat_user = db.Table( 'tags', db.Column('chat_id', db.Integer, db.ForeignKey('chat.id'), primary_key=True), db.Column('user_id', db.Integer, db.ForeignKey('user.id'), primary_key=True)) class Chat(db.Model): id = db.Column(db.Integer, primary_key=True) users = db.relationship('User', secondary=chat_user, lazy='subquery', backref=db.backref('chats', lazy=True)) messages = db.relationship('Message', backref='chat', lazy=True)
from datetime import datetime from enum import Enum, unique from itsdangerous import TimedJSONWebSignatureSerializer as Serializer from math import ceil from website import db, login_manager, app from flask_login import UserMixin catalog_category = db.Table( "catalog_category", db.Column("catalog_id", db.Integer, db.ForeignKey("catalog.id"), primary_key=True), db.Column("category_id", db.Integer, db.ForeignKey("category.id"), primary_key=True)) catalog_item = db.Table( "catalog_item", db.Column("catalog_id", db.Integer, db.ForeignKey("catalog.id"), primary_key=True), db.Column("item_id", db.Integer, db.ForeignKey("item.id"), primary_key=True)) catalog_rule = db.Table( "catalog_rule",
class Address(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(120), nullable=False) person_id = db.Column(db.Integer, db.ForeignKey('person.id'), nullable=False) # Many-to-Many Relationship # http://flask-sqlalchemy.pocoo.org/2.3/models/#many-to-many-relationships tags = db.Table( 'tags', db.Column('tag_id', db.Integer, db.ForeignKey('tag.id'), primary_key=True), db.Column('page_id', db.Integer, db.ForeignKey('page.id'), primary_key=True)) class Page(db.Model): id = db.Column(db.Integer, primary_key=True) tags = db.relationship('Tag', secondary=tags, lazy='subquery', backref=db.backref('pages', lazy=True)) class Tag(db.Model): id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False) articles = db.relationship('Article', back_populates='category') class Tag(BaseModel): """Article tag (e.g., Python, cloud, Rust, etc.).""" name = db.Column(db.String, nullable=False) articles = db.relationship('Article', secondary='article_tags', back_populates='_tags') # TODO: write test in content update manager (03/2019) # @classmethod # def delete_orphans(cls) -> int: # """Delete tags not associated with any other documents. # :return: number of tags deleted. # """ # # Thanks to https://stackoverflow.com/a/18193592/2987526 # return db.session.query(Tag).having(func.count(Article.id) == 0).delete() # noqa: E501 # Many-to-Many Relationships tags = db.Table( 'article_tags', db.Column('article_id', db.Integer, db.ForeignKey('articles.id')), db.Column('tag_id', db.Integer, db.ForeignKey('tags.id')), )