Пример #1
0
class User(UserMixin, db.Model):
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key = True, autoincrement=True)
    name = db.Column(db.String(20))
    birth = db.Column(db.String(10), nullable = False)
    username = db.Column(db.String(64), unique=True, index=True)
    password = db.Column(db.String(128))
    recipes = db.relationship('Recipe', backref='users', lazy=True)
    liked = db.relationship('LikePost', foreign_keys='LikePost.user_id', backref='users', lazy='dynamic')


    def __init__(self,name,birth,username,password):
        self.name = name
        self.birth = birth
        self.username = username
        self.password = password

    def __repr__(self):
        return '<User %r>' % self.username

    def like(self, recipe):
        if  LikePost.query.filter(LikePost.user_id == self.id, LikePost.recipe_id == recipe.id).count() > 0:
            LikePost.query.filter_by(user_id=self.id, recipe_id=recipe.id).delete()
            recipe.removeLike()
            db.session.commit()
        else:
            like = LikePost(user_id=self.id, recipe_id=recipe.id)
            db.session.add(like)
            recipe.addLike()
            db.session.commit()
Пример #2
0
class Driver(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(255), nullable=False)
    last_name = db.Column(db.String(255), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship("User", back_populates="driver")
    trips = db.relationship("Trip", backref="driver", lazy=True)
Пример #3
0
class Order(Model):
    __tablename__ = 'order'

    order_id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    buyer_id = db.Column(db.Integer,
                         db.ForeignKey('buyer.buyer_id'),
                         nullable=True)
    buyer = db.relationship('Buyer', backref=db.backref('orders', lazy=True))

    supplier_id = db.Column(db.Integer,
                            db.ForeignKey('supplier.supplier_id'),
                            nullable=True)
    supplier = db.relationship('Supplier',
                               backref=db.backref('orders', lazy=True))

    date_created = db.Column(db.Date)
    time_created = db.Column(db.Time)

    accepted = db.Column(db.Boolean)
    status = db.Column(db.String(45))

    price = db.Column(db.Float)
    rate = db.Column(db.Integer)

    comment = db.Column(db.String(255))
    ship_price_buyer = db.Column(db.Float)
    ship_price_supplier = db.Column(db.Float)
    ship_price = db.Column(db.Float)

    def __init__(self,
                 buyer_id=None,
                 supplier_id=None,
                 date_created=None,
                 time_created=None,
                 accepted=None,
                 status=None,
                 price=None,
                 rate=None,
                 comment=None,
                 ship_price_buyer=None,
                 ship_price_supplier=None,
                 ship_price=None):
        self.buyer_id = buyer_id
        self.supplier_id = supplier_id
        self.date_created = date_created
        self.time_created = time_created

        self.accepted = accepted
        self.status = status
        self.price = price
        self.rate = rate

        self.comment = comment
        self.ship_price_buyer = ship_price_buyer
        self.ship_price_supplier = ship_price_supplier
        self.ship_price = ship_price
Пример #4
0
class Category(db.Model):
    __tablename__ = 'categories'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    product = db.relationship('Product', backref='categories')
    supplier = db.relationship('Supplier', backref='categories')

    def __str__(self):
        return self.name
Пример #5
0
class Presentation(db.Model):
    __tablename__ = 'presentations'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text, nullable=False)
    text = db.Column(db.Text)
    author = db.relationship('Author', backref='presentation')
    schedule = db.relationship('Schedule', backref='presentation')

    def __str__(self):
        return self.name
Пример #6
0
class Test(db.Model):
    """Create a test table."""
    __tablename__ = 'test'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), index=True, unique=True)
    test_type = db.Column(db.String(60))
    data = db.Column(db.Text())
    execute_date = db.Column(db.DateTime())
    scenario_id = db.Column(db.Integer, db.ForeignKey('scenario.id'))
    result = db.relationship("Result")
    group = db.relationship('Group')
Пример #7
0
class User(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))
    rider = db.relationship("Rider", uselist=False, back_populates="user") 
    driver = db.relationship("Driver", uselist=False, back_populates="user") 

    def set_password(self, password):
        self.password_hash = bcrypt.generate_password_hash(password).decode('UTF-8')

    def check_password(self, password):
        return bcrypt.check_password_hash(self.password_hash, password)
Пример #8
0
class StoreModel(db.Model):
    __tablename__ = 'stores'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))

    items = db.relationship('ItemModel', lazy='dynamic')

    def __init__(self, name):
        self.name = name

    def json(self):
        return {'name': self.name, 'items': [item.json() for item in self.items.all()]}

    @classmethod
    def find_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
Пример #9
0
class Person(db.Model):
    """Modelo Persona

    Person(id_person, name_person, last_name_person, telephone_person,
    email_person, name_profile_img)

    Relaciones:
        - Persona tendrá referencias de varias Mascotas

    Nota: lazy(perezosa) = True define como SQLAlchemy cargará los datos
    """
    id_person = db.Column(db.Integer, primary_key = True)
    name_person = db.Column(db.String(25), nullable = False)
    last_name_person = db.Column(db.String(25), nullable = False)
    telephone_person = db.Column(db.Integer(), nullable = False)
    email_person = db.Column(db.String(25), unique = True, nullable = False)

    name_profile_img = db.Column(db.String, default = 'default.jpg' , nullable = True)
    url_profile_img = db.Column(db.String, default = 'http://localhost:5000/static/profile_img/default.jpg' , nullable = True)

    # Relacion uno a muchos con la clase Mascota
    pets = db.relationship('Pet', backref = 'owner', lazy = True)

    def __repr__(self):
        return self.name_person
Пример #10
0
class User(Base):
    __tablename__ = 'user'

    # User Name
    name = db.Column(db.String(128), nullable=False)

    # Identification Data: email & password
    orcid = db.Column(db.String(128), nullable=False, unique=True)
    token = db.Column(db.String(192), nullable=False)
    aka = db.Column(db.String(1000), nullable=True)
    role = db.Column(db.String(128), nullable=True)
    repos = db.relationship('Repository', backref='user', lazy=True)

    def __init__(self, name, orcid, aka, token):

        self.name = name
        self.orcid = orcid
        self.token = token
        self.aka = aka

    def __repr__(self):
        return '<User %r>' % self.name

    def as_dict(self):
        # return {c.name: getattr(self, c.name) for c in self.__table__.columns}
        return {
            c.name: str(getattr(self, c.name))
            for c in self.__table__.columns
        }  # to support datetime
Пример #11
0
class ItemModel(db.Model):
    __tablename__ = 'items'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(80))
    price = db.Column(db.Float(precision=2))

    store_id = db.Column(db.Integer, db.ForeignKey('stores.id'))
    store = db.relationship('StoreModel')

    def __init__(self, name, price, store_id):
        self.name = name
        self.price = price
        self.store_id = store_id

    def json(self):
        return {'name': self.name, 'price': self.price}

    @classmethod
    def find_by_name(cls, name):
        return cls.query.filter_by(name=name).first()

    def save_to_db(self):
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        db.session.delete(self)
        db.session.commit()
Пример #12
0
class Trip(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    start_location = db.Column(db.String(255), nullable=False)
    end_location = db.Column(db.String(255), nullable=False)
    departure_date = db.Column(db.DateTime(timezone=True), nullable=False)
    return_date = db.Column(db.DateTime(timezone=True), nullable=False)
    available_seats = db.Column(db.Integer, nullable=False)
    driver_id = db.Column(db.Integer,
                          db.ForeignKey('driver.id'),
                          nullable=False)
    riders = db.relationship('Rider',
                             secondary=trip_riders,
                             lazy='subquery',
                             back_populates='trips')

    def remove_rider_from_trip(self, rider_id):
        new_riders = [rider for rider in self.riders if rider.id != rider_id]
        self.riders = new_riders
        self.available_seats = self.available_seats + 1
        db.session.commit()

    def add_rider_to_trip(self, rider_id):
        self.riders.append(rider_id)
        self.available_seats = self.available_seats - 1
        db.session.commit()
Пример #13
0
class History(Model):
    __tablename__ = "history"
    history_id = db.Column(db.Integer, primary_key=True, autoincrement=True)

    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.user_id'),
                        nullable=False)
    user = db.relationship('User', backref=db.backref('histories', lazy=True))

    description = db.Column(db.String, nullable=False)
    date_created = db.Column(db.Date, nullable=False)
    time_created = db.Column(db.Time, nullable=False)

    def __init__(self,
                 user_id,
                 description,
                 date_created=None,
                 time_created=None):
        self.user_id = user_id
        self.description = description
        if date_created is None:
            date_created = datetime.datetime.today().date()
        if time_created is None:
            time_created = datetime.datetime.now().time()
        self.date_created = date_created
        self.time_created = time_created
Пример #14
0
class Rider(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    first_name = db.Column(db.String(255), nullable=False)
    last_name = db.Column(db.String(255), nullable=False)
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship("User", back_populates="rider")
    trips = db.relationship("Trip",
                            secondary=trip_riders,
                            lazy='subquery',
                            back_populates="riders")
    #eventually add in a photo column, perhaps make this come from a photos table joined on rider/driver id
    #photo
    #rating. eventually add in this column, make it come from the ratings table


# adding a construct here will better show each indiviudal rider object
Пример #15
0
class Show(db.Model):
    __tablename__ = 'Show'

    venue_id = db.Column(db.Integer,
                         db.ForeignKey('Venue.id'),
                         primary_key=True)
    artist_id = db.Column(db.Integer,
                          db.ForeignKey('Artist.id'),
                          primary_key=True)
    starttime = db.Column(db.DateTime, primary_key=True)

    artist = db.relationship('Artist', lazy='joined')

    @property
    def info(self):
        return {
            'venue_id': self.venue.id,
            'venue_name': self.venue.name,
            'artist_id': self.artist.id,
            'artist_name': self.artist.name,
            'artist_image_link': self.artist.image_link,
            'start_time': self.starttime.isoformat() + 'Z'
        }

    def __init__(self, venue=None, artist=None, starttime=None):
        self.venue = venue
        self.artist = artist
        self.starttime = starttime

    def __repr__(self):
        return f'<{self.artist.name} @ {self.venue.name}: {self.starttime}>'
Пример #16
0
class Role(db.Model):
    __tablename__ = 'roles'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(30), nullable=False)
    user = db.relationship('User', backref='roles')

    def __str__(self):
        return self.name
Пример #17
0
class Room(db.Model):
    __tablename__ = 'rooms'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Text)
    schedule = db.relationship('Schedule', backref='room')

    def __str__(self):
        return 'Room #' + str(self.id)
Пример #18
0
class Resource(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(64), index=True, unique=True)
    home_page = db.Column(db.String(120), index=True, unique=True)
    news = db.relationship('News', backref='source', lazy='dynamic')

    def __repr__(self):
        return f'<Resource {self.title}>'
Пример #19
0
class Specification(db.Model):
    """Create a user table."""
    __tablename__ = 'specification'

    id = db.Column(db.Integer, primary_key=True)
    spec_name = db.Column(db.String(60), index=True, unique=True)
    url = db.Column(db.Text())
    group = db.relationship('Group')
Пример #20
0
class Role(db.Model):
    __tablename__ = 'roles'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), unique=True)
    users = db.relationship('User', backref='role')

    def __str__(self):
        return self.name
Пример #21
0
class User(db.Model):
    """This class defines the users table """

    __tablename__ = 'users'

    # Define the columns of the users table, starting with the primary key
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.String(256), nullable=False, unique=True)
    password = db.Column(db.String(256), nullable=False)
    bucketlists = db.relationship('Bucketlist',
                                  order_by='Bucketlist.id',
                                  cascade="all, delete-orphan")

    def hash_password(self, entered_password):
        '''
        function for hashing a password
        '''
        self.password = pwd_context.encrypt(entered_password)

    def verify_password(self, entered_password):
        '''
        function for verifying a hashed a password
        '''
        return pwd_context.verify(entered_password, self.password)

    def generate_token(self, user_id):
        '''
        Generates the access token to be used as the Authorization header
        '''
        try:
            # set up a payload with an expiration time
            payload = {
                'exp': datetime.utcnow() + timedelta(minutes=10),
                'iat': datetime.utcnow(),
                'sub': user_id
            }
            # encode the payload to get an byte string token
            jwt_string = jwt.encode(payload,
                                    current_app.config.get('SECRET'),
                                    algorithm='HS256')
            return jwt_string

        except Exception as e:
            # return an error in string format if an exception occurs
            return str(e)

    @staticmethod
    def decode_token(token):
        '''
        Decode the access token from the Authorization header
        '''
        try:
            payload = jwt.decode(token, current_app.config.get('SECRET'))
            return payload['sub']
        except jwt.ExpiredSignatureError:
            return "Expired token. Please log in to get a new token"
        except jwt.InvalidTokenError:
            return "Invalid token. Please register or login"
Пример #22
0
class Scenario(db.Model):
    __tablename__ = 'scenario'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(60), index=True, unique=True)
    description = db.Column(db.Text())
    creation_date = db.Column(db.DateTime())
    update_date = db.Column(db.DateTime())
    last_run = db.Column(db.DateTime())
    test = db.relationship("Test")
Пример #23
0
class Unit(db.Model):
    __tablename__ = 'units'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    abbreviation = db.Column(db.String(10))
    product = db.relationship('Product', backref='units')

    def __str__(self):
        return self.name
class PodcastShowModel(BaseModel, db.Model):
    __tablename__ = 'podcast_show'

    show_id = db.Column(db.Text, primary_key=True)
    title = db.Column(db.Text)
    description = db.Column(db.Text)
    episodes = db.relationship('PodcastEpisodeModel',
                               backref='podcast_show',
                               lazy=True)
Пример #25
0
class TypeOfService(db.Model):
    __tablename__ = 'types_of_service'
    id = db.Column(db.Integer(), primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    description = db.Column(db.Text(), nullable=False)
    id_service_form = db.relationship('ServiceForm',secondary='type_service_form',
                                      backref=db.backref('types_of_service', lazy='dynamic'))

    def __str__(self):
        return self.name
Пример #26
0
class Product(db.Model):
    __tablename__ = 'products'
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    shelf_life = db.Column(db.Date, nullable=False)
    trade_price = db.Column(db.Integer, nullable=False)

    id_unit = db.Column(db.Integer, db.ForeignKey('units.id'), nullable=False)
    id_category = db.Column(db.Integer,
                            db.ForeignKey('categories.id'),
                            nullable=False)
    id_supplier = db.Column(db.Integer,
                            db.ForeignKey('suppliers.id'),
                            nullable=False)

    sale = db.relationship('Sale', backref='products')
    warehouse = db.relationship('Warehouse', backref='products')

    def __str__(self):
        return self.name
Пример #27
0
class Restaurant(db.Model):
    __tablename__ = "restaurant"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64), index=True, unique=True)
    url = db.Column(db.String(255))
    want_to_go = db.Column(db.Boolean)
    ratings = db.relationship("Rating", backref="score", lazy="dynamic")

    def __repr__(self):
        return f"Restaurant {self.name}"
Пример #28
0
class User(db.Model, UserMixin):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(100), nullable=False, unique=True)
    password = db.Column(db.String(255), nullable=False, server_default="")
    active = db.Column(db.Boolean(), nullable=False, server_default="0")
    roles = db.relationship("Role", secondary="user_roles")

    def __repr__(self):
        return f"{self.username}"
Пример #29
0
class Employee(db.Model):
    """Model for an employee."""
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50), nullable=False)
    date_of_birth = db.Column(db.DateTime, nullable=False)
    salary = db.Column(db.Float, nullable=False)
    department_id = db.Column(db.Integer, db.ForeignKey("department.id"), nullable=False)
    department = db.relationship("Department", backref="department", lazy=True)

    def __repr__(self):
        return f"""
Пример #30
0
class User(db.Model):
    __tablename__ = 'users'

    id = db.Column(db.Integer, primary_key=True)
    user_name = db.Column(db.String(20))
    user_email = db.Column(db.String(60), unique=True, index=True)
    user_password = db.Column(db.String(80))
    create_date = db.Column(db.DateTime, default=datetime.now)
    last_login_date = db.Column(db.DateTime, default=datetime.utcnow())
    is_confirmed = db.Column(db.Boolean, default=False, nullable=False)
    role = db.Column(db.String(25), default='Guest', nullable=False)
    keys = db.relationship('Key', backref='user', lazy=True)