class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True, autoincrement=True) fname = db.Column(db.String(50), nullable=False) lname = db.Column(db.String(50), nullable=False) email = db.Column(db.String(80), unique=True, nullable=False) password = db.Column(db.VARCHAR(255), nullable=False) phone = db.Column(db.String(20), nullable=True) phone2 = db.Column(db.String(20), nullable=True) date_created = db.Column(db.Date, nullable=False) last_logged = db.Column(db.Date, nullable=True) role_id = db.Column(db.Integer, db.ForeignKey('roles.id')) social = db.Column(db.Integer, db.ForeignKey('socialmedia.id'), nullable=True) def __init__(self, fname, lname, email, password, phone, phone2, role_id, social): self.fname = fname self.lname = lname self.email = email self.password = bcrypt.generate_password_hash( password, current_app.config.get('BCRYPT_LOG_ROUNDS')).decode() self.phone = phone self.phone2 = phone2 self.date_created = datetime.now() self.last_logged = datetime.now() self.role_id = role_id #self.reporter = reporter #self.owner = owner self.social = social def encode_auth_token(self, user_id, user_role_id): try: payload = { 'exp': datetime.utcnow() + timedelta(days=1), 'iat': datetime.utcnow(), 'identity': user_id, 'role': user_role_id } return jwt.encode(payload, current_app.secret_key, algorithm='HS256') except Exception as e: return e @staticmethod def decode_auth_token(auth_token): try: payload = jwt.decode(auth_token, current_app.secret_key) return payload except jwt.ExpiredSignatureError: return 'Signature expired. Please log in again.' except jwt.InvalidTokenError: return 'Invalid token. Please log in again.'
class SocialMedia(db.Model): __tablename__ = 'socialmedia' id = db.Column(db.Integer, primary_key=True, autoincrement=True) fb = db.Column(db.String(150), nullable=True) twitter = db.Column(db.String(150), nullable=True) insta = db.Column(db.String(150), nullable=True) def __init__(self, fb, twitter, insta): self.fb = fb self.twitter = twitter self.insta = insta
class OwnerRequest(db.Model): __tablename__ = 'ownerrequest' id = db.Column(db.Integer, primary_key=True, autoincrement=True) feeder = db.Column(db.String(120), nullable=True) fieldcrew = db.Column(db.String(120), nullable=True) notes = db.Column(db.String(200), nullable=True) propertyinfo = db.Column(db.Integer, db.ForeignKey('propertyinfo.id')) def __init__(self, feeder, fieldcrew, notes, propertyinfo): self.feeder = feeder self.fieldcrew = fieldcrew self.notes = notes self.propertyinfo = propertyinfo
class Location(db.Model): __tablename__ = 'location' id = db.Column(db.Integer, primary_key =True, autoincrement=True) street_name = db.Column(db.String(50), nullable = True) house_number = db.Column(db.String(20), nullable = True) city = db.Column(db.String(50), nullable=False) state = db.Column(db.String(20), nullable = False) zipcode = db.Column(db.String(20), nullable = True) def __init__(self, street_name, house_number, city, state, zipcode): self.street_name = street_name self.house_number = house_number self.city = city self.state = state self.zipcode = zipcode
class PetImage(db.Model): __tablename__ = 'petimage' id = db.Column(db.Integer, primary_key = True, autoincrement = True) image_url =db.Column(db.String(200), nullable = False) def __init__ (self, image_url): self.image_url = image_url
class Role(db.Model): __tablename__ = 'roles' id = db.Column(db.Integer, primary_key=True, autoincrement=True) role_name = db.Column(db.String(50), nullable=False) def __init__(self, role_name): self.role_name = role_name
class Gender(db.Model): __tablename__ = 'gender' id = db.Column(db.Integer, primary_key=True, autoincrement=True) gender = db.Column(db.String(10)) def __init__(self, gender): self.gender = gender
class Breeds(db.Model): __tablename__ = 'breeds' id = db.Column(db.Integer, primary_key=True, autoincrement=True) breed = db.Column(db.String(50), nullable=False) def __init__(self, breed): self.breed = breed
class PetStatus(db.Model): __tablename__ = 'petstatus' id = db.Column(db.Integer, primary_key=True, autoincrement=True) status = db.Column(db.String(20)) def __init__(self, status): self.status = status
class AlteredStatus(db.Model): __tablename__ = 'alteredstatus' id = db.Column(db.Integer, primary_key=True, autoincrement=True) status = db.Column(db.String(50), unique=True, nullable=False) def __init__(self, status): self.status = status
class Animals(db.Model): __tablename__ = 'animals' id = db.Column(db.Integer, primary_key=True, autoincrement=True) animal = db.Column(db.String(50), unique=True, nullable=False) pet = db.relationship('Pets') def __init__(self, animal): self.animal = animal
class PropertyInfo(db.Model): __tablename__ = 'propertyinfo' id = db.Column(db.Integer, primary_key=True, autoincrement=True) permission = db.Column(db.Boolean, nullable=False) notes = db.Column(db.String(200), nullable=True) def __init__(self, permission, notes): self.permission = permission self.notes = notes
class ReporterInfo(db.Model): __tablename__ = "reporter" id = db.Column(db.Integer, primary_key=True, autoincrement=True) spottedlocation = db.Column(db.Integer, db.ForeignKey("locationjoin.id")) spottedimage = db.Column(db.Integer, db.ForeignKey("petimage.id"), nullable=True) userid = db.Column(db.Integer, db.ForeignKey('users.id')) notes = db.Column(db.String(100), nullable=True)
class Pets(db.Model): __tablename__ = 'pets' id = db.Column(db.Integer, primary_key=True, autoincrement=True) pet_name = db.Column(db.String(50), nullable=True) animal_type = db.Column(db.Integer, db.ForeignKey('animals.id'), nullable=True) animal = db.relationship("Animals", uselist=False, lazy='select') primary_breed = db.Column(db.Integer, db.ForeignKey('breeds.id'), nullable=True) secondary_breed = db.Column(db.Integer, db.ForeignKey('breeds.id'), nullable=True) pbreed = db.relationship("Breeds", uselist=False, lazy='select', foreign_keys=[primary_breed]) sbreed = db.relationship("Breeds", uselist=False, lazy='select', foreign_keys=[secondary_breed]) gender = db.Column(db.Integer(), db.ForeignKey("gender.id"), nullable=False) sex = db.relationship("Gender", uselist=False, lazy='select') altered_status = db.Column(db.Integer, db.ForeignKey('alteredstatus.id'), nullable=True) alteredstat = db.relationship("AlteredStatus", uselist=False, lazy='select') pet_status = db.Column(db.Integer, db.ForeignKey('petstatus.id'), nullable=True) petstatus = db.relationship("PetStatus", uselist=False, lazy='select') trapper_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True) date_created = db.Column(db.Date, nullable=False) lost = db.Column(db.Integer, db.ForeignKey('losttable.id')) found = db.Column(db.Integer, db.ForeignKey('foundtable.id')) def __init__(self, pet_name, animal_type, gender, primary_breed, secondary_breed, altered_status, trapper_id, pet_status): self.pet_name = pet_name self.animal_type = animal_type self.gender = gender self.primary_breed = primary_breed self.secondary_breed = secondary_breed self.altered_status = altered_status self.pet_status = pet_status self.date_created = datetime.now()
class UniqueFeature(db.Model): __tablename__ = 'uniquefeature' id = db.Column(db.Integer, primary_key=True, autoincrement=True) breed = db.Column(db.Integer, db.ForeignKey('breeds.id')) animal = db.Column(db.Integer, db.ForeignKey('animals.id')) feature = db.Column(db.String(50)) def __init__(self, breed, animal, feature): self.breed = breed self.animal = animal self.feature = feature
class Disaster(db.Model): __tablename__ = 'disaster' id = db.Column(db.Integer, primary_key=True, autoincrement=True) disaster_name = db.Column(db.String(50), nullable=False) start_date = db.Column(db.Date, nullable=False) end_date = db.Column(db.Date, nullable=False) disaster_location = db.Column(db.Integer, db.ForeignKey('location.id')) def __init__(self, disaster_name, start_date, end_date, disaster_location): self.disaster_name = disaster_name self.start_date = start_date self.end_date = end_date self.disaster_location = disaster_location