Skip to content

Commit

Permalink
Feat: Add BIT personal background to MS schema
Browse files Browse the repository at this point in the history
Add new migration script
  • Loading branch information
mtreacy002 committed May 3, 2021
1 parent f25a0b8 commit 231b3be
Show file tree
Hide file tree
Showing 4 changed files with 377 additions and 1 deletion.
135 changes: 135 additions & 0 deletions app/database/models/personal_background.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
from sqlalchemy import null
from app.database.sqlalchemy_extension import db
from app.database.db_types.JsonCustomType import JsonCustomType
from app.utils.bitschema_utils import Gender, Age, Ethnicity, SexualOrientation, Religion, PhysicalAbility, MentalAbility, SocioEconomic, HighestEducation, YearsOfExperience


class PersonalBackgroundModel(db.Model):
"""Defines attributes for user's personal background.
Attributes:
user_id: An integer for storing the user's id.
gender: A string for storing the user's gender.
age: A string for storing the user's age.
ethnicity: A string for storing the user's wthnicity.
sexual_orientation: A string for storing the user's sexual orientation.
religion: A string for storing the user's religion.
physical_ability: A string for storing the user's physical ability.
mental_ability: A string for storing the user's mental ability.
socio_economic: A string for storing the user's socio economic level.
highest_education: A string for storing the user's highest education level.
years_of_experience: A string for storing the user's length of expeprience in the It related area.
others: A JSON data type for storing users descriptions of 'other' fields.
is_public: A boolean indicating if user has agreed to display their personal background information publicly to other members.
"""

# Specifying database table used for PersonalBackgroundModel
__tablename__ = "personal_backgrounds"
__table_args__ = {"extend_existing": True}

id = db.Column(db.Integer, primary_key=True)

# User's personal background data
user_id = db.Column(
db.Integer,
db.ForeignKey("users.id", ondelete="CASCADE"),
nullable=False,
unique=True,
)
gender = db.Column(db.Enum(Gender))
age = db.Column(db.Enum(Age))
ethnicity = db.Column(db.Enum(Ethnicity))
sexual_orientation = db.Column(db.Enum(SexualOrientation))
religion = db.Column(db.Enum(Religion))
physical_ability = db.Column(db.Enum(PhysicalAbility))
mental_ability = db.Column(db.Enum(MentalAbility))
socio_economic = db.Column(db.Enum(SocioEconomic))
highest_education = db.Column(db.Enum(HighestEducation))
years_of_experience = db.Column(db.Enum(YearsOfExperience))
others = db.Column(JsonCustomType)
is_public = db.Column(db.Boolean)

def __init__(
self,
user_id,
gender,
age,
ethnicity,
sexual_orientation,
religion,
physical_ability,
mental_ability,
socio_economic,
highest_education,
years_of_experience,
):
"""Initialises PersonalBackgroundModel class."""
## required fields
self.user_id = user_id
self.gender = gender
self.age = age
self.ethnicity = ethnicity
self.sexual_orientation = sexual_orientation
self.religion = religion
self.physical_ability = physical_ability
self.mental_ability = mental_ability
self.socio_economic = socio_economic
self.highest_education = highest_education
self.years_of_experience = years_of_experience

# default values
self.others = None
self.is_public = False

def json(self):
"""Returns PersonalBackgroundModel object in json format."""
return {
"id": self.id,
"user_id": self.user_id,
"age": self.age,
"ethnicity": self.ethnicity,
"sexual_orientation": self.sexual_orientation,
"religion": self.religion,
"physical_ability": self.physical_ability,
"mental_ability": self.mental_ability,
"socio_economic": self.socio_economic,
"highest_education": self.highest_education,
"years_of_experience": self.years_of_experience,
"others": self.others,
"is_public": self.is_public,
}

def __repr__(self):
"""Returns user's background."""

return (
f"User's id is {self.user_id}.\n"
f"User's age is: {self.age}\n"
f"User's ethnicity is: {self.ethnicity}\n"
f"User's sexual orientation is: {self.sexual_orientation}\n"
f"User's religion is: {self.religion}\n"
f"User's physical ability is: {self.physical_ability}\n"
f"User's mental ability is: {self.mental_ability}\n"
f"User's socio economic category is: {self.socio_economic}\n"
f"User's highest level of education is: {self.highest_education}\n"
f"User's length of experience is: {self.years_of_experience}\n"
)

@classmethod
def find_by_user_id(cls, user_id) -> "PersonalBackgroundModel":

"""Returns the user's background that has the passed user id.
Args:
_id: The id of a user.
"""
return cls.query.filter_by(user_id=user_id).first()

def save_to_db(self) -> None:
"""Adds user's personal background to the database."""
db.session.add(self)
db.session.commit()

def delete_from_db(self) -> None:
"""Deletes user's personal background from the database."""
db.session.delete(self)
db.session.commit()
164 changes: 164 additions & 0 deletions app/utils/bitschema_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,167 @@ class Timezone(Enum):

def timezone(self):
return list(map(str, self))


# Enum related to personal background
@unique
class ProgramStatus(Enum):
DRAFT = "Draft"
OPEN = "Open"
IN_PROGRESS = "In_Progress"
COMPLETED = "Completed"
CLOSED = "Closed"

def programStatus(self):
return list(map(str, self))


@unique
class OrganizationStatus(Enum):
DRAFT = "Draft"
PUBLISH = "Publish"
ARCHIVED = "Archived"

def OrganizationStatus(self):
return list(map(str, self))


@unique
class Gender(Enum):
FEMALE = "Female"
MALE = "Male"
OTHER = "Other"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def gender(self):
return list(map(str, self))


@unique
class Age(Enum):
UNDER_18 = "Under 18"
AGE_18_TO_20 = "Between 18 to 20 yo"
AGE_21_TO_24 = "Between 21 to 24 yo"
AGE_25_TO_34 = "Between 25 to 34 yo"
AGE_35_TO_44 = "Between 35 to 44 yo"
AGE_45_TO_54 = "Between 45 to 54 yo"
AGE_55_TO_64 = "Between 55 to 64 yo"
ABOVE_65_YO = "Above 65 yo"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def age(self):
return list(map(str, self))


@unique
class Ethnicity(Enum):
AFRICAN_AMERICAN = "African-American/Black"
CAUCASIAN = "Caucasian/White"
HISPANIC = "Hispanic/Latinx"
NATIVE_AMERICAN = "Native American/Alaska Native/First Nations"
MIDDLE_EASTERN = "Middle Eastern/North African (MENA)"
ASIAN = "Asian"
OTHER = "Other"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def ethnicity(self):
return list(map(str, self))


@unique
class SexualOrientation(Enum):
HETEROSEXUAL = "Heterosexual/Straight"
LGBTIA = "LGBTIA+"
OTHER = "Other"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def sexualOrientation(self):
return list(map(str, self))


@unique
class Religion(Enum):
CHRISTIANITY = "Christianity"
JUDAISM = "Judaism"
ISLAM = "Islam"
HINDUISM = "Hinduism"
BUDDHISM = "Buddhism"
OTHER = "Other"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def religion(self):
return list(map(str, self))


@unique
class PhysicalAbility(Enum):
WITH_DISABILITY = "With/had limited physical ability (or with/had some type of physical disability/ies)"
WITHOUT_DISABILITY = "Without/have no limitation to physical ability/ies"
OTHER = "Other"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def physicalAbility(self):
return list(map(str, self))


@unique
class MentalAbility(Enum):
WITH_DISORDER = "With/previously had some type of mental disorders"
WITHOUT_DISORDER = "Without/have no mental disorders"
OTHER = "Other"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def mentalAbility(self):
return list(map(str, self))


@unique
class SocioEconomic(Enum):
UPPER = "Upper class/Elite"
UPPER_MIDDLE = "Upper Middle class (or High-level Professionals/white collars e.g. enginers/accountants/lawyers/architects/managers/directors"
LOWER_MIDDLE = "Lower Middle class (e.g. blue collars in skilled trades/Paralegals/Bank tellers/Sales/Clerical-Admin/other support workers)"
WORKING = "Working class (e.g. craft workers factory labourers restaurant/delivery services workers"
BELOW_POVERTY = "Underclass working but with wages under poverty line receiving Social Benefit from Government"
OTHER = "Other"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def socioEconomic(self):
return list(map(str, self))


@unique
class HighestEducation(Enum):
BELOW_HIGH_SCHOOL = "Have/did not completed High School"
HIGH_SCHOOL = "High School Diploma"
ASSOCIATE = "Associate Degree"
BACHELOR = "Bachelor's Degree"
MASTER = "Master's Degree"
PHD = "PhD or other Doctorate Degrees"
OTHER = "Other"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def highestEducation(self):
return list(map(str, self))


@unique
class YearsOfExperience(Enum):
UNDER_ONE = "Less than a year"
UP_TO_3 = "Between 1 to 3 years"
UP_TO_5 = "Between 3 to 5 years"
UP_TO_10 = "Between 5 to 10 year"
OVER_10 = "Over 10 years of experience"
DECLINED = "Prefer not to say"
NOT_APPLICABLE = "Not Applicable"

def yearsOfExperience(self):
return list(map(str, self))
47 changes: 47 additions & 0 deletions migrations/versions/0cfd533818e7_add_bit_personal_background.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Add BIT personal background
Revision ID: 0cfd533818e7
Revises: 1272e4b54a32
Create Date: 2021-05-03 11:36:51.484640
"""
from alembic import op
from app.database.db_types.JsonCustomType import JsonCustomType
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0cfd533818e7'
down_revision = '1272e4b54a32'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('personal_backgrounds',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('gender', sa.Enum('FEMALE', 'MALE', 'OTHER', 'DECLINED', 'NOT_APPLICABLE', name='gender'), nullable=True),
sa.Column('age', sa.Enum('UNDER_18', 'AGE_18_TO_20', 'AGE_21_TO_24', 'AGE_25_TO_34', 'AGE_35_TO_44', 'AGE_45_TO_54', 'AGE_55_TO_64', 'ABOVE_65_YO', 'DECLINED', 'NOT_APPLICABLE', name='age'), nullable=True),
sa.Column('ethnicity', sa.Enum('AFRICAN_AMERICAN', 'CAUCASIAN', 'HISPANIC', 'NATIVE_AMERICAN', 'MIDDLE_EASTERN', 'ASIAN', 'OTHER', 'DECLINED', 'NOT_APPLICABLE', name='ethnicity'), nullable=True),
sa.Column('sexual_orientation', sa.Enum('HETEROSEXUAL', 'LGBTIA', 'OTHER', 'DECLINED', 'NOT_APPLICABLE', name='sexualorientation'), nullable=True),
sa.Column('religion', sa.Enum('CHRISTIANITY', 'JUDAISM', 'ISLAM', 'HINDUISM', 'BUDDHISM', 'OTHER', 'DECLINED', 'NOT_APPLICABLE', name='religion'), nullable=True),
sa.Column('physical_ability', sa.Enum('WITH_DISABILITY', 'WITHOUT_DISABILITY', 'OTHER', 'DECLINED', 'NOT_APPLICABLE', name='physicalability'), nullable=True),
sa.Column('mental_ability', sa.Enum('WITH_DISORDER', 'WITHOUT_DISORDER', 'OTHER', 'DECLINED', 'NOT_APPLICABLE', name='mentalability'), nullable=True),
sa.Column('socio_economic', sa.Enum('UPPER', 'UPPER_MIDDLE', 'LOWER_MIDDLE', 'WORKING', 'BELOW_POVERTY', 'OTHER', 'DECLINED', 'NOT_APPLICABLE', name='socioeconomic'), nullable=True),
sa.Column('highest_education', sa.Enum('BELOW_HIGH_SCHOOL', 'HIGH_SCHOOL', 'ASSOCIATE', 'BACHELOR', 'MASTER', 'PHD', 'OTHER', 'DECLINED', 'NOT_APPLICABLE', name='highesteducation'), nullable=True),
sa.Column('years_of_experience', sa.Enum('UNDER_ONE', 'UP_TO_3', 'UP_TO_5', 'UP_TO_10', 'OVER_10', 'DECLINED', 'NOT_APPLICABLE', name='yearsofexperience'), nullable=True),
sa.Column('others', JsonCustomType, nullable=True),
sa.Column('is_public', sa.Boolean(), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('user_id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('personal_backgrounds')
# ### end Alembic commands ###
Loading

0 comments on commit 231b3be

Please sign in to comment.