Ejemplo n.º 1
0
class HistoryModel(db.Model):

    # Specifying table
    __tablename__ = "history"
    __table_args__ = {"extend_existing": True}

    id = db.Column(db.Integer, primary_key=True)
    donor_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    donor = db.relationship(
        UserModel,
        backref="history",
        primaryjoin="HistoryModel.donor_id == UserModel.id",
    )
    recipient_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    recipient = db.relationship(
        UserModel,
        backref="history",
        primaryjoin="HistoryModel.recipient_id == UserModel.id",
    )
    application_id = db.Column(db.Integer, db.ForeignKey("application.id"))
    application = db.relationship(
        ApplicationModel,
        backref="history",
        primaryjoin="HistoryModel.application_id == ApplicationModel.id",
    )
    institution_id = db.Column(db.Integer, db.ForeignKey("institution.id"))
    institution = db.relationship(
        InstitutionModel,
        backref="history",
        primaryjoin="HistoryModel.institution_id == InstitutionModel.id",
    )

    amount = db.Column(db.String(15))

    def save_to_db(self) -> None:
        '''Add history to database'''
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self) -> None:
        '''Deletes history from the database.'''
        db.session.delete(self)
        db.session.commit()
class ModeratorRequestModel(db.Model):

    # Specifying table
    __tablename__ = "moderator_request"
    __table_args__ = {"extend_existing": True}

    id = db.Column(db.Integer, primary_key=True)
    donor_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    donor = db.relationship(
        UserModel,
        backref="moderator_request",
        primaryjoin="ModeratorRequestModel.donor_id == UserModel.id",
    )
    application_id = db.Column(db.Integer, db.ForeignKey("application.id"))
    application = db.relationship(
        ApplicationModel,
        backref="moderator_request",
        primaryjoin=
        "ModeratorRequestModel.application_id == ApplicationModel.id",
    )
    accepted = db.Column(db.Boolean)
    mod_email = db.Column(db.String(70))

    def __init__(self, donor, invitee_email, unique_code):
        self.invitee_email = invitee_email
        self.unique_code = unique_code
        self.donor = donor

    @classmethod
    def find_by_mod_email(cls, invitee_email: str) -> 'InvitesModel':
        return cls.query.filter_by(invitee_email=invitee_email).first()

    def save_to_db(self) -> None:
        '''Add invite details to database'''
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self) -> None:
        '''Deletes invite details from the database.'''
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 3
0
class TaskModel(db.Model):
    # Specifying database table used for GoalModel
    __tablename__ = "tasks"
    __table_args__ = {"extend_existing": True}

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(30))
    stage_id = db.Column(db.Integer,
                         db.ForeignKey('stages.id'),
                         nullable=False)

    def __init__(self, stage_id, title='mystage'):
        """Initialises userModel class with name. """
        self.title = title
        self.stage_id = stage_id

    def json(self):
        """Returns Usermodel object in json format."""
        return {"id": self.id, "title": self.title, "stage_id": self.stage_id}

    def __repr__(self):
        """Returns the user's name and username. """
        return f"Task {self.title}"

    @classmethod
    def find_by_id(cls, _id: int) -> 'TaskModel':
        """Returns the goal that has the id we searched for. """
        return cls.query.filter_by(id=_id).first()

    @classmethod
    def is_empty(cls) -> bool:
        """Returns a boolean if the GoalModel is empty or not. """
        return cls.query.first() is None

    def save_to_db(self) -> int:
        """Adds a goal to the database. """
        db.session.add(self)
        db.session.flush()
        id = self.id
        db.session.commit()
        return id

    def delete_from_db(self) -> None:
        """Deletes a user from the database. """
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 4
0
class PreferredLocationModel(db.Model):

    # Specifying table
    __tablename__ = "preferred_location"
    __table_args__ = {"extend_existing": True}

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    user = db.relationship(
        UserModel,
        backref=db.backref('preferred_location', uselist=False),
        primaryjoin="PreferredLocationModel.user_id == UserModel.id",
    )
    state = db.Column(db.String(50))
    district = db.Column(db.String(50))
    sub_district = db.Column(db.String(50))
    area = db.Column(db.String(50))

    def __init__(self, user_id, state, district, sub_district, area):
        self.user_id = user_id
        self.state = state
        self.district = district
        self.sub_district = sub_district
        self.area = area

    def json(self):
        '''Preferred Location object in json format.'''
        return {
            "state": self.state,
            "district": self.district,
            "sub_district": self.sub_district,
            "area": self.area
        }

    @classmethod
    def find_by_user_id(cls, _user_id: int) -> 'PreferredLocationModel':
        '''Returns user preferred location of given user id.'''
        return cls.query.filter_by(user_id=_user_id).first()

    def save_to_db(self) -> None:
        """Saves the model to the database."""
        db.session.add(self)
        db.session.commit()
Ejemplo n.º 5
0
class DocumentsModel(db.Model):

    # Specifying table
    __tablename__ = "documents"
    __table_args__ = {"extend_existing": True}

    id = db.Column(db.Integer, primary_key=True)
    application_id = db.Column(db.Integer, db.ForeignKey("application.id"))
    application = db.relationship(
        ApplicationModel,
        backref="documents",
        primaryjoin="DocumentsModel.application_id == ApplicationModel.id",
    )

    offer_letter = db.Column(db.Text())
    fee_structure = db.Column(db.Text())
    bank_statement = db.Column(db.Text())
    affiliation_letter = db.Column(db.Text())
    scholarship_letter = db.Column(db.Text())
    additional_doc1 = db.Column(db.Text())
    additional_doc2 = db.Column(db.Text())
    additional_doc3 = db.Column(db.Text())

    def __init__(self, offer_letter, fee_structure, bank_statement):
        self.offer_letter = offer_letter
        self.fee_structure = fee_structure
        self.bank_statement = bank_statement

    def save_to_db(self) -> None:
        '''Add document details to database'''
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self) -> None:
        '''Deletes document details from the database.'''
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 6
0
class TaskCommentModel(db.Model):
    """Defines attributes for the task comment.

    Attributes:
        task_id: An integer for storing the task's id.
        user_id: An integer for storing the user's id.
        relation_id: An integer for storing the relation's id.
        creation_date: A float indicating comment's creation date.
        modification_date: A float indicating the modification date.
        comment: A string indicating the comment.
    """

    # Specifying database table used for TaskCommentModel
    __tablename__ = "tasks_comments"
    __table_args__ = {"extend_existing": True}

    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    task_id = db.Column(db.Integer, db.ForeignKey("tasks_list.id"))
    relation_id = db.Column(db.Integer,
                            db.ForeignKey("mentorship_relations.id"))
    creation_date = db.Column(db.Float, nullable=False)
    modification_date = db.Column(db.Float)
    comment = db.Column(db.String(COMMENT_MAX_LENGTH), nullable=False)

    def __init__(self, user_id, task_id, relation_id, comment):
        # required fields
        self.user_id = user_id
        self.task_id = task_id
        self.relation_id = relation_id
        self.comment = comment

        # default fields
        self.creation_date = datetime.now().timestamp()

    def json(self):
        """Returns information of task comment as a JSON object."""
        return {
            "id": self.id,
            "user_id": self.user_id,
            "task_id": self.task_id,
            "relation_id": self.relation_id,
            "creation_date": self.creation_date,
            "modification_date": self.modification_date,
            "comment": self.comment,
        }

    def __repr__(self):
        """Returns the task and user ids, creation date and the comment."""
        return (f"User's id is {self.user_id}. Task's id is {self.task_id}. "
                f"Comment was created on: {self.creation_date}\n"
                f"Comment: {self.comment}")

    @classmethod
    def find_by_id(cls, _id):
        """Returns the task comment that has the passed id.
           Args:
                _id: The id of the task comment.
        """
        return cls.query.filter_by(id=_id).first()

    @classmethod
    def find_all_by_task_id(cls, task_id, relation_id):
        """Returns all task comments that has the passed task id.
           Args:
                task_id: The id of the task.
                relation_id: The id of the relation.
        """
        return cls.query.filter_by(task_id=task_id,
                                   relation_id=relation_id).all()

    @classmethod
    def find_all_by_user_id(cls, user_id):
        """Returns all task comments that has the passed user id.
           Args:
                user_id: The id of the user.
        """
        return cls.query.filter_by(user_id=user_id).all()

    def modify_comment(self, comment):
        """Changes the comment and the modification date.
           Args:
                comment: New comment.
        """
        self.comment = comment
        self.modification_date = datetime.now().timestamp()

    @classmethod
    def is_empty(cls):
        """Returns a boolean if the TaskCommentModel is empty or not."""
        return cls.query.first() is None

    def save_to_db(self):
        """Adds a comment task to the database."""
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self):
        """Deletes a comment task from the database."""
        db.session.delete(self)
        db.session.commit()
from app.database.sqlalchemy_extension import db

application_moderator = db.Table(
    'application_moderator',
    db.Column('application_id', db.Integer, db.ForeignKey('application.id')),
    db.Column('moderator_id', db.Integer, db.ForeignKey('user.id')))
Ejemplo n.º 8
0
from app.database.sqlalchemy_extension import db

section_video = db.Table(
    "section_video",
    db.Column("video_id", db.Integer, db.ForeignKey("videos.id")),
    db.Column("section_id", db.Integer, db.ForeignKey("section.id")),
)
Ejemplo n.º 9
0
from app.database.sqlalchemy_extension import db

category_section = db.Table('category_section',
    db.Column('category_id', db.Integer, db.ForeignKey('category.id')),
    db.Column('section_id', db.Integer, db.ForeignKey('section.id'))
    )
Ejemplo n.º 10
0
from app.database.sqlalchemy_extension import db

section_video = db.Table('section_video',
    db.Column('video_id', db.Integer, db.ForeignKey('videos.id')),
    db.Column('section_id', db.Integer, db.ForeignKey('section.id'))
    )
Ejemplo n.º 11
0
class MentorshipRelationModel(db.Model):
    """Data Model representation of a mentorship relation.
    
    Attributes:
        id: integer primary key that defines the mentorships.
        mentor_id: integer indicates the id of the mentor.
        mentee_id: integer indicates the id of the mentee.
        action_user_id: integer indicates id of action user.
        mentor: relationship between UserModel and mentorship_relation.
        mentee: relationship between UserModel and mentorship_relation.
        creation_date: float that defines the date of creation of the mentorship.
        accept_date: float that indicates the date of acceptance of mentorship.
        start_date: float that indicates the starting date of mentorship.
        end_date: float that indicates the ending date of mentorship.
        state: enumeration that indicates state of mentorship.
        notes: string that indicates any notes.
        tasks_list_id: integer indicates the id of the tasks_list
        tasks_list: relationship between TasksListModel and mentorship_relation.
    """

    # Specifying database table used for MentorshipRelationModel
    __tablename__ = "mentorship_relations"
    __table_args__ = {"extend_existing": True}

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

    # personal data
    mentor_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    mentee_id = db.Column(db.Integer, db.ForeignKey("users.id"))
    action_user_id = db.Column(db.Integer, nullable=False)
    mentor = db.relationship(
        UserModel,
        backref="mentor_relations",
        primaryjoin="MentorshipRelationModel.mentor_id == UserModel.id",
    )
    mentee = db.relationship(
        UserModel,
        backref="mentee_relations",
        primaryjoin="MentorshipRelationModel.mentee_id == UserModel.id",
    )

    creation_date = db.Column(db.Float, nullable=False)
    accept_date = db.Column(db.Float)
    start_date = db.Column(db.Float)
    end_date = db.Column(db.Float)

    state = db.Column(db.Enum(MentorshipRelationState), nullable=False)
    notes = db.Column(db.String(400))

    tasks_list_id = db.Column(db.Integer, db.ForeignKey("tasks_list.id"))
    tasks_list = db.relationship(TasksListModel,
                                 uselist=False,
                                 backref="mentorship_relation")

    def __init__(
        self,
        action_user_id,
        mentor_user,
        mentee_user,
        creation_date,
        end_date,
        state,
        notes,
        tasks_list,
    ):

        self.action_user_id = action_user_id
        self.mentor = mentor_user
        self.mentee = mentee_user  # same as mentee_user.mentee_relations.append(self)
        self.creation_date = creation_date
        self.end_date = end_date
        self.state = state
        self.notes = notes
        self.tasks_list = tasks_list

    def json(self):
        """Returns information of mentorship as a json object."""
        return {
            "id": self.id,
            "action_user_id": self.action_user_id,
            "mentor_id": self.mentor_id,
            "mentee_id": self.mentee_id,
            "creation_date": self.creation_date,
            "accept_date": self.accept_date,
            "start_date": self.start_date,
            "end_date": self.end_date,
            "state": self.state,
            "notes": self.notes,
        }

    # def __repr__(self):
    #     return f"Mentorship Relation with id = {self.id}, Mentor has id = {self.mentor_id} and Mentee has id = {self.mentee_id}"

    @classmethod
    def find_by_id(cls, _id) -> 'MentorshipRelationModel':
        """Returns the mentorship that has the passed id.
           Args:
                _id: The id of a mentorship.
        """
        return cls.query.filter_by(id=_id).first()

    @classmethod
    def is_empty(cls) -> bool:
        """Returns True if the mentorship model is empty, and False otherwise."""
        return cls.query.first() is None

    def save_to_db(self) -> None:
        """Saves the model to the database."""
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self) -> None:
        """Deletes the record of mentorship relation from the database."""
        self.tasks_list.delete_from_db()
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 12
0
from app.database.sqlalchemy_extension import db

category_section = db.Table(
    "category_section",
    db.Column("category_id", db.Integer, db.ForeignKey("category.id")),
    db.Column("section_id", db.Integer, db.ForeignKey("section.id")),
)
Ejemplo n.º 13
0
from app.database.sqlalchemy_extension import db

video_author = db.Table('video_author',
    db.Column('author_id', db.Integer, db.ForeignKey('author.id')),
    db.Column('video_id', db.Integer, db.ForeignKey('videos.id'))
    )
class ReservedApplicationModel(db.Model):

    # Specifying table
    __tablename__ = "reserved_application"
    __table_args__ = {"extend_existing": True}

    id = db.Column(db.Integer, primary_key=True)
    application_id = db.Column(db.Integer, db.ForeignKey("application.id"))
    application = db.relationship(
        ApplicationModel,
        backref='reserved',
        primaryjoin=
        "ReservedApplicationModel.application_id == ApplicationModel.id",
    )
    donor_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    donor = db.relationship(
        UserModel,
        backref="reserved_as_donor",
        primaryjoin="ReservedApplicationModel.donor_id == UserModel.id",
    )
    moderator_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    moderator = db.relationship(
        UserModel,
        backref="reserved_as_moderator",
        primaryjoin="ReservedApplicationModel.moderator_id == UserModel.id",
    )

    is_active = db.Column(db.Boolean)
    verified = db.Column(db.Boolean)
    verification_date = db.Column(db.String(20))
    donation_date = db.Column(db.String(20))
    amount = db.Column(db.Integer)

    def save_to_db(self) -> None:
        '''Add application to database'''
        db.session.add(self)
        db.session.commit()

    def delete_from_db(self) -> None:
        '''Deletes application from the database.'''
        db.session.delete(self)
        db.session.commit()

    @classmethod
    def find_by_id(cls, id: int) -> 'ReservedApplicationModel':
        '''Returns reserved application of given id.'''
        return cls.query.filter_by(id=id).first()

    @classmethod
    def find_by_application_id(
            cls, application_id: int) -> 'ReservedApplicationModel':
        '''Returns reserved application of given donor id.'''
        return cls.query.filter_by(application_id=application_id).first()

    @classmethod
    def find_by_donor_id(cls, donor_id: int) -> 'ReservedApplicationModel':
        '''Returns reserved application of given donor id.'''
        return cls.query.filter_by(donor_id=donor_id).first()

    @classmethod
    def find_by_moderator_id(cls,
                             moderator_id: int) -> 'ReservedApplicationModel':
        '''Returns reserved application of given moderator id.'''
        return cls.query.filter_by(moderator_id=moderator_id).first()

    @classmethod
    def find_reserved_application(
            cls, application_id: int, donor_id: int,
            moderator_id: int) -> 'ReservedApplicationModel':
        '''Returns reserved application of given moderator id.'''
        return cls.query.filter_by(application_id=application_id,
                                   donor_id=donor_id,
                                   moderator_id=moderator_id).first()
Ejemplo n.º 15
0
from app.database.sqlalchemy_extension import db

video_author = db.Table(
    "video_author",
    db.Column("author_id", db.Integer, db.ForeignKey("author.id")),
    db.Column("video_id", db.Integer, db.ForeignKey("videos.id")),
)