class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(150), unique=True) password = db.Column(db.String) name = db.Column(db.String(150)) role = db.Column(db.String(150)) nif = db.Column(db.Integer(), nullable=True) tel = db.Column(db.Integer(), nullable=True) tempo = db.Column(db.Integer(), default=0) tipo = db.Column(db.Integer(), default=0) campuser = db.relationship('CampUser') pais = db.Column(db.String(150), nullable=True) leads = db.Column(db.Integer, nullable=True)
class LocationModel(db.Model): __tablename__ = 'location' location_id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('user.user_id')) lon = db.Column(db.Float()) lat = db.Column(db.Float()) comments = db.Column(db.String()) def save_to_db(self): db.session.add(self) db.session.commit() def update_to_db(self): db.session.merge(self) db.session.commit() def delete_from_db(self): db.session.delete(self) db.session.commit() @classmethod def read_from_db(cls, user_id): return cls.query.join(UserModel).filter( UserModel.user_id == user_id).all() @classmethod def get_by_location_id(cls, location_id): return cls.query.filter(cls.location_id == location_id).one_or_none()
class Quotes(db.Model): __tablename__ = 'quotes' id = db.Column(db.Integer(), primary_key=True, nullable=False) quotes_text = db.Column(db.Text, nullable=False) def __repr__(self): return f"Essay {self.id}"
class Part(db.Model): __tablename__ = 'parts' no = db.Column(db.String(255), primary_key=True, nullable=False) set_no = db.Column(db.String(255), db.ForeignKey('sets.no'), primary_key=True, nullable=False) color_id = db.Column(db.String(255), primary_key=True, nullable=False) color_name = db.Column(db.String(255), nullable=False) color_code = db.Column(db.String(255), nullable=False) color_type = db.Column(db.String(255), nullable=False) name = db.Column(db.Text(150), nullable=False) type = db.Column(db.String(255), nullable=False) category_id = db.Column(db.String(255), nullable=False) owned_quantity = db.Column(db.Integer()) quantity = db.Column(db.Integer()) extra_quantity = db.Column(db.Integer()) is_alternate = db.Column(db.Boolean()) is_counterpart = db.Column(db.Boolean()) thumbnail_url = db.Column(db.String(255)) __table_args__ = ( db.UniqueConstraint("no", "set_no", "color_id"), ) def __init__(self, no, set_no, name, type, category_id, color_id, color_name, color_code, color_type, owned_quantity, quantity, extra_quantity, is_alternate, is_counterpart, thumbnail_url): self.no = no self.set_no = set_no self.name = name self.type = type self.category_id = category_id self.color_id = color_id self.color_name = color_name self.color_code = color_code self.color_type = color_type self.owned_quantity = owned_quantity self.quantity = quantity self.extra_quantity = extra_quantity self.is_alternate = is_alternate self.is_counterpart = is_counterpart self.thumbnail_url = thumbnail_url def __repr__(self): return '<Part %r>' % self.no # subclass JSONEncoder class PartEncoder(JSONEncoder): def default(self, o): return o.__dict__
class Classifier(db.Model): __tablename__ = 'classifier' id = db.Column(db.Integer(), primary_key=True, nullable=False) classifier = db.Column(db.PickleType()) vectorizer = db.Column(db.PickleType()) def __repr__(self): return f"News {self.id}"
class News(db.Model): __tablename__ = 'news' id = db.Column(db.Integer(), primary_key=True, nullable=False) news_title = db.Column(db.Text()) news_summarized = db.Column(db.Text()) searched_keyword = db.Column(db.Text()) url_link = db.Column(db.Text()) def __repr__(self): return f"News {self.id}"
class Essay(db.Model): __tablename__ = 'essay' id = db.Column(db.Integer(), primary_key = True, nullable = False) company_name = db.Column(db.Text()) essays = db.Column(db.Text()) url_link = db.Column(db.Text()) grade = db.Column(db.Float()) keyword = db.Column(db.Text()) def __repr__(self): return f"News {self.id}"
class Job(db.Model): __tablename__ = 'job' id = db.Column(db.Integer(), primary_key = True, nullable = False) job_title = db.Column(db.Text()) study_period = db.Column(db.Text()) experience = db.Column(db.Text()) money=db.Column(db.Text()) job_app = db.Column(db.Text()) area = db.Column(db.Text()) job_end = db.Column(db.Text()) field = db.Column(db.Text()) spec_work = db.Column(db.Text()) company_name = db.Column(db.Text()) keyword = db.Column(db.String()) links = db.Column(db.Text()) def __repr__(self): return f"Job {self.id}"
class UserModel(db.Model): __tablename__ = 'user' user_id = db.Column(db.Integer(), primary_key=True) username = db.Column(db.String(), unique=True, nullable=False) password = db.Column(db.String(), nullable=False) locations = db.relationship('LocationModel', backref='user') def save_to_db(self): db.session.add(self) db.session.commit() @classmethod def find_by_username(cls, username): return cls.query.filter_by(username=username).first() @staticmethod def generate_hash(password): return sha256.hash(password) @staticmethod def verify_hash(password, hash): return sha256.verify(password, hash)
class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255))
from flask_app import db, app from flask.ext.security import Security, SQLAlchemyUserDatastore, \ UserMixin, RoleMixin from flask_app.forms import ExtendedRegisterForm import json roles_users = db.Table('roles_users', db.Column('user_id', db.Integer(), db.ForeignKey('user.id')), db.Column('role_id', db.Integer(), db.ForeignKey('role.id'))) def date_serial(value): return value.strftime("%Y-%m-%d")+" "+value.strftime("%H:%M:%S") class Role(db.Model, RoleMixin): id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(80), unique=True) description = db.Column(db.String(255)) class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(255), unique=True) password = db.Column(db.String(255)) first_name = db.Column(db.String(255)) last_name = db.Column(db.String(255)) organization = db.Column(db.String(255)) active = db.Column(db.Boolean()) confirmed_at = db.Column(db.DateTime()) roles = db.relationship('Role', secondary=roles_users, backref=db.backref('users', lazy='dynamic'))