class User(db.Model): def randomPasswords(stringLength=8): """Generate a random string of letters and digits """ lettersAndDigits = string.ascii_letters + string.digits return ''.join( random.choice(lettersAndDigits) for i in range(stringLength)) def hash_password(self, password): self.password_hash = pwd_context.encrypt(password) def verify_password(self, password): return pwd_context.verify(password, self.password_hash) __tablename__ = 'users' user_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) email = db.Column(db.String(100), unique=True, nullable=False, index=True) password_hash = db.Column(db.String(128), nullable=False) category = db.Column(db.String(30), nullable=False) account_status = db.Column(db.String(75), nullable=False) # blocks = db.relationship('Block', backref='users', lazy=True) # rental = db.relationship('Rental', backref='users', lazy=True) # complaints = db.relationship('Complaint', backref='users', lazy=True) def __init__(self, email, category, account_status, public_id): self.public_id = public_id self.category = category self.email = email self.account_status = account_status
class Users(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(60)) password = db.Column(db.String(60)) arc = db.Boolean() zid = db.Column(db.String(8)) registered = db.Column(db.Integer, db.ForeignKey("registered.id"))
class User(db.Model): __tablename__ = 'users' # Serial Number sno = db.Column(db.Integer, primary_key=True) # Organisation organisation = db.Column(db.String(128), nullable=False) # User Name name = db.Column(db.String(128), nullable=False) # Github username github_username = db.Column(db.String(128), nullable=False) # New instance instantiation procedure def __init__(self, organisation, name, github_username): self.organisation = organisation self.name = name self.github_username = github_username def __repr__(self): return json.dumps([self.name, self.github_username])
class User(db.Model): __tablename__ = "users" id = db.Column('user_id', db.Integer, primary_key=True) username = db.Column('username', db.String(20), unique=True, index=True) password = db.Column('password', db.String(10)) email = db.Column('email', db.String(50), unique=True, index=True) def __init__(self, username, password, email): self.username = username self.password = password self.email = password self.email = email def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False def get_id(self): return unicode(self.id) def __repr__(self): return '<User %r>' % (self.username)
class Statement(db.Model): __tablename__ = 'statements' statement_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) tenant_name = db.Column(db.String(75), nullable=False) tenant_id = db.Column(db.Integer, db.ForeignKey('tenants.tenant_id'), nullable=False) unit_id = db.Column(db.Integer, db.ForeignKey('units.unit_id'), nullable=False) transaction_type = db.Column(db.String(75), nullable=False) transaction_amount = db.Column(db.Float, nullable=False) transaction_date = db.Column(db.Date, nullable=False) net_amount = db.Column(db.Float, nullable=False) def __init__(self, tenant_id, unit_id, tenant_name, transaction_type, transaction_amount, net_amount, transaction_date, public_id): self.public_id = public_id self.tenant_id = tenant_id self.unit_id = unit_id self.tenant_name = tenant_name self.transaction_type = transaction_type self.transaction_amount = transaction_amount self.transaction_date = transaction_date self.net_amount = net_amount
class User(db.Model): id = db.Column(db.Integer, primary_key=True) #id is a built-in!!! username = db.Column(db.String(32), index=True, unique=True) #email = db.Column(db.String(64), index=True, unique=True) #really needed? psw_hash = db.Column(db.String(128)) def __repr__(self): return f'User {self.username}'
class Movie(db.Model): __tablename__ = 'Movie' id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80)) year = db.Column(db.Integer) description = db.Column(db.String()) actors = db.relationship('Role', back_populates='movie')
class TrackChange(db.Model): id = db.Column(db.Integer, primary_key=True) currentTrack = db.Column(db.String(100)) endTime = db.Column(db.Float) pattern = db.Column(db.String(10)) nextTrack = db.Column(db.String(100)) startTime = db.Column(db.Float) timeOfChange = db.Column(db.DateTime) user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
class Song(db.Model): def __repr__(self): return str(self) id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) seconds = db.Column(db.Integer) path = db.Column(db.String(200), unique=True) file = db.Column(db.LargeBinary)
class Events(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(100)) location = db.Column(db.String(30)) #starttime = db.Column(db.Time) #date = db.Column(db.Date) secret_code = db.String(6) registered_users = db.relationship("Registered", backref="event") society = db.Column(db.Integer, db.ForeignKey("societies.id"))
class Actor(db.Model): __tablename__ = 'Actor' id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(80), nullable=False) birthdate = db.Column(db.String(30)) movies = db.relationship('Role', back_populates='actor') def __str__(self): return self.name
class PaymentType(db.Model): __tablename__ = 'payment_types' type_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) type_code = db.Column(db.String(12), nullable=False, unique=True) type_meaning = db.Column(db.String(75), nullable=False, unique=True) def __init__(self, public_id, type_code, type_meaning): self.public_id = public_id self.type_code = type_code self.type_meaning = type_meaning
class User(db.Model, UserMixin): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) image_file = db.Column(db.String(20), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) posts = db.relationship('Post', backref='author', lazy=True) def __repr__(self): return f"User('{self.username}', '{self.email}', '{self.image_file}')"
class Record(db.Model): __tablename__ = 'records' id = db.Column(db.Integer, primary_key=True) artist_name = db.Column(db.String(20), index=True) record_name = db.Column(db.String(20), index=True) def __init__(self, artist_name, record_name): self.artist_name = artist_name self.record_name = record_name
class Status(db.Model): __tablename__ = 'status' status_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) status_code = db.Column(db.Integer, nullable=False, unique=True) status_meaning = db.Column(db.String(75), nullable=False, unique=True) def __init__(self, status_code, status_meaning, public_id): self.public_id = public_id self.status_code = status_code self.status_meaning = status_meaning
class Image(db.Model): __tablename__ = 'complaints_images' image_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) image_name = db.Column(db.String(75), nullable=False) complaint_id = db.Column(db.Integer, db.ForeignKey('complaints.complaint_id'), nullable=False) def __init__(self, image_name, complaint_id, public_id): self.public_id = public_id self.image_name = image_name self.complaint_id = complaint_id
class Rental(db.Model): __tablename__ = 'rentals' rental_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) tenant_name = db.Column(db.String(75), nullable=False) unit_number = db.Column(db.String(25), nullable=False) lease_end_date = db.Column(db.Date, nullable=False) def __init__(self, tenant_name, unit_number, lease_end_date, public_id): self.public_id = public_id self.tenant_name = tenant_name self.unit_number = unit_number self.lease_end_date = lease_end_date
class Email(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(100), index=True, unique=True) user_id = db.Column(db.Integer, db.ForeignKey('user.id')) def __repr__(self): return '<Email %r>' % (self.email)
class Debt(db.Model): __tablename__ = 'debts' debt_id = db.Column(db.Integer, nullable=False, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) bill_amount = db.Column(db.Float, nullable=False) paid_amount = db.Column(db.Float, nullable=False, default=0) debt_status = db.Column(db.String(75), nullable=False) debt_date = db.Column(db.Date, nullable=False) #Relationships payments = db.relationship('Payment', backref='debts', lazy=True) def __init__(self, bill_amount, paid_amount, debt_status, public_id): self.public_id = public_id self.bill_amount = bill_amount self.paid_amount = paid_amount self.debt_status = debt_status self.debt_date = datetime.utcnow()
class Notification(db.Model): __tablename__ = 'notifications' notification_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) notification_message = db.Column(db.Text, nullable=False) recipient_id = db.Column(db.Integer, nullable=False) notification_date = db.Column(db.Date, nullable=False) notification_type = db.Column(db.String(75), nullable=False) def __int__(self, notification_message, recipient_id, notification_date, notification_type, public_id): self.public_id = public_id self.notification_message = notification_message self.recipient_id = recipient_id self.notification_date = notification_date self.notification_type = notification_type
class Role(db.Model): __tablename__ = 'Role' id = db.Column(db.Integer, primary_key=True) movie_id = db.Column(db.Integer, db.ForeignKey('Movie.id'), nullable=False) actor_id = db.Column(db.Integer, db.ForeignKey('Actor.id'), nullable=False) role = db.Column(db.String(80), nullable=False) actor = db.relationship('Actor', back_populates='movies') movie = db.relationship('Movie', back_populates='actors')
class ServiceProviders(db.Model): __tablename__ = 'service_providers' provider_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) provider_name = db.Column(db.String(75), nullable=False) provider_contact = db.Column(db.String(15), nullable=False, unique=True) #Relationships services = db.relationship('Services', backref='service_providers', lazy=True) def __init__(self, provider_name, provider_contact, public_id): self.public_id = public_id self.provider_name = provider_name self.provider_contact = provider_contact
class Caretaker(db.Model): __tablename__ = 'caretakers' caretaker_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) property_id = db.Column(db.Integer, db.ForeignKey('property.property_id'), nullable=False) first_name = db.Column(db.String(75), nullable=False) last_name = db.Column(db.String(75), nullable=False) email = db.Column(db.String(100), nullable=False, unique=True) phone = db.Column(db.String(15), nullable=False, unique=True) def __init__(self, property_id, first_name, last_name, email, phone, public_id): self.public_id = public_id self.property_id = property_id self.first_name = first_name self.last_name = last_name self.email = email self.phone = phone
class Block(db.Model): __tablename__ = 'blocks' block_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) property_id = db.Column(db.Integer, db.ForeignKey('property.property_id'), nullable=False) block_name = db.Column(db.String(35), nullable=False) number_of_units = db.Column(db.Integer, nullable=False) # Relationships units = db.relationship('Unit', backref='blocks', lazy=True) def __init__(self, property_id, block_name, number_of_units, public_id): self.number_of_units = number_of_units self.public_id = public_id self.property_id = property_id self.block_name = block_name
class User(db.Model): __tablename__ = 'users' uid = db.Column(db.Integer, primary_key = True) firstname = db.Column(db.String(100)) lastname = db.Column(db.String(100)) email = db.Column(db.String(100), unique = True) pwdhash = db.Column(db.String(256)) def __init__(self, firstname, lastname, email, password): self.firstname = firstname.title() self.lastname = lastname.title() self.email = email.lower() self.set_password(password) def set_password(self, password): self.pwdhash = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.pwdhash, password)
class Landlord(db.Model): __tablename__ = 'landlords' landlord_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) first_name = db.Column(db.String(75), nullable=False) last_name = db.Column(db.String(75), nullable=False) email = db.Column(db.String(100), nullable=False, unique=True) phone = db.Column(db.String(15), nullable=False, unique=True) # Relationships properties = db.relationship('Property', backref='landlords', lazy=True) def __init__(self, first_name, last_name, email, phone, public_id): self.public_id = public_id self.first_name = first_name self.last_name = last_name self.email = email self.phone = phone
class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) def __repr__(self): return f"Post('{self.title}', '{self.date_posted}')"
class Tenant(db.Model): __tablename__ = 'tenants' tenant_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) first_name = db.Column(db.String(75), nullable=False) last_name = db.Column(db.String(75), nullable=False) email = db.Column(db.String(100), nullable=False, unique=True) phone = db.Column(db.String(15), nullable=False, unique=True) #Relationships leases = db.relationship('Lease', backref='tenants', lazy=True) def __init__(self, first_name, last_name, email, phone, public_id): self.public_id = public_id self.first_name = first_name self.last_name = last_name self.email = email self.phone = phone
class UserModel(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key = True) username = db.Column(db.String(120), unique = True, nullable = False) password = db.Column(db.String(120), nullable = False) 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() @classmethod def return_all(cls): def to_json(x): return { 'username': x.username, 'password': x.password } return {'users': list(map(lambda x: to_json(x), UserModel.query.all()))} @classmethod def delete_all(cls): try: num_rows_deleted = db.session.query(cls).delete() db.session.commit() return {'message': '{} row(s) deleted'.format(num_rows_deleted)} except: return {'message': 'Something went wrong'} @staticmethod def generate_hash(password): return sha256.hash(password) @staticmethod def verify_hash(password, hash): return sha256.verify(password, hash)
class Company(db.Model): __tablename__ = 'companies' company_id = db.Column(db.Integer, primary_key=True) public_id = db.Column(db.String(70), nullable=False, unique=True) company_name = db.Column(db.String(50), nullable=False, unique=True) company_code = db.Column(db.String(70), nullable=False, unique=True) company_head = db.Column(db.String(70), nullable=False) company_size = db.Column(db.Integer, nullable=False) created_at = db.Column(db.Date, nullable=False) # Relationships surveys = db.relationship('Survey', backref='companies', lazy=True) def __init__(self, public_id, company_name, company_code, company_head, company_size): self.company_name = company_name self.public_id = public_id self.company_code = company_code self.company_head = company_head self.company_size = company_size self.created_at = datetime.datetime.today()