Exemple #1
0
    def notify_result(self, conn, smtp, accept=True):
        """Notify application result to applicant through email
        Param:
        conn -- database connection
        smtp -- smtp server
        accept -- application approved or not
        Return:
        smtp send result
        """
        proj = Project.get_by_id(conn, self.project_id)
        role = Role.get_by_id(conn, self.role_apply)
        col = Collaborator.get_by_id(conn, self.applicant)
        dre = Dreamer.get_by_id(conn, proj['owner'])
        subject = '[DreamMatchmaker]You have an application status update'
        if accept:
            acceptance = 'accepted'
        else:
            acceptance = 'declined'
        content = f'''<p>Hello {col['name']},</p>
<p>   Your application to join project <b>"{proj['title']}"</b> as <b>"{role['title']}"</b></p>
<p>   has been {acceptance}.</p>
<p>Dream Matchmaker Team</p>
'''
        result = smtp.send_email_html(col['email'], content, subject)
        return result
Exemple #2
0
    def notify_invitor(self, conn, smtp, accept=True):
        """Send an email to invitor for notification
        Param:
        conn -- database connection
        smtp -- smtp server object
        accept -- boolean if invitation is accepted
        Return:
        Smtp send result
        """
        proj = Project.get_by_id(conn, self.project_id)
        role = Role.get_by_id(conn, self.role_invite)
        col = Collaborator.get_by_id(conn, self.invitee)
        dre = Dreamer.get_by_id(conn, self.invitor)
        subject = '[DreamMatchmaker]You have a invitation status update'
        if accept:
            acceptance = 'accepted'
        else:
            acceptance = 'declined'
        content = f'''<p>Hello {dre['name']},</p>
<p>   Your invitation to <b>{col['name']}</b> for project <b>"{proj['title']}"</b>, role <b>"{role['title']}"</b></p>
<p>   has been <b>{acceptance}</b>.</p>
<p>Dream Matchmaker Team</p>
'''
        result = smtp.send_email_html(dre['email'], content, subject)
        return result
Exemple #3
0
 def info(self, conn):
     """Return invitation info
     Param:
     conn -- database connection
     Return:
     invitation info
     """
     return {
         'id': self.id,
         'project_id': self.project_id,
         'role_invite': self.role_invite,
         'invitor': self.invitor,
         'invitee': self.invitee,
         'general_text': self.general_text,
         'status': self.status,
         'Role_information': Role.get_text_by_id(conn, self.role_invite),
         'Project_title': Project.get_by_id(conn, self.project_id)['title']
     }
Exemple #4
0
 def get_by_invitee(conn, user_id):
     """Get all invitations for a collaborator's
     Param:
     conn -- database connection
     user_id -- collaborator digit id
     Return:
     list of invitations info
     """
     # IMPORTANT: Avoid corss import
     # This import cannot be moved up or it will cause infinite recursive import
     from projects.role import Role
     query = "SELECT * FROM invitation where invitee = " + str(
         user_id) + " order by ID desc;"
     result = conn.execute(query)
     invitations = []
     for i in range(result.rowcount):
         row = result.fetchone()
         if row['status'] == -1:
             invitation_status = 'Pending'
         if row['status'] == 0:
             invitation_status = 'Declined'
         if row['status'] == 1:
             invitation_status = 'Approved'
         if row['status'] == 9:
             invitation_status = 'Finished'
         invi = {
             'InvitationID': row['ID'],
             'projectID': row['projectID'],
             'Role_invited': row['role_invited'],
             'Invitor': row['invitor'],
             'Invitor_name': Dreamer.get_by_id(conn,
                                               row['invitor'])['name'],
             'Invitee': row['invitee'],
             'Invitation_status': invitation_status,
             'General_text': row['general_text'],
             'Role_information':
             Role.get_text_by_id(conn, row['role_invited']),
             'Project_title': Project.get_by_id(conn,
                                                row['projectID'])['title']
         }
         invitations.append(invi)
     return {'invitations': invitations, 'amount': result.rowcount}
Exemple #5
0
    def notify_invitee_auto_decline(self, conn, smtp):
        """Send an email to invitees for auto decline notification
        Param:
        conn -- database connection
        smtp -- smtp server object
        Return:
        Smtp send result
        """
        proj = Project.get_by_id(conn, self.project_id)
        role = Role.get_by_id(conn, self.role_invite)
        col = Collaborator.get_by_id(conn, self.invitee)
        dre = Dreamer.get_by_id(conn, self.invitor)
        subject = '[DreamMatchmaker]You have a invitation status update'
        content = f'''<p>Hello {col['name']},</p>
<p>   Your invitation from <b>{dre['name']}</b> for project <b>"{proj['title']}"</b>, role <b>"{role['title']}"</b></p>
<p>   has been automaticlly cancelled due to "Role is fullfilled".</p>
<p>Dream Matchmaker Team</p>
'''
        result = smtp.send_email_html(col['email'], content, subject)
        return result
 def get_followed_projects(conn, id):
     """Get projects user followed by user id
     Param:
     conn -- database connection
     id -- dreamer digital id
     Return:
     followed project info list
     """
     # query subscription table
     query = f"SELECT * FROM subscription WHERE is_dreamer=1 AND d_subscriber={id};"
     result = conn.execute(query)
     project_list = []
     for i in range(result.rowcount):
         # fetch project information
         row = result.fetchone()
         pid = row['projectID']
         proj_info = Project.get_by_id(conn, pid)
         proj_info['follow'] = True
         project_list.append(proj_info)
     return project_list
Exemple #7
0
 def search_list(self, conn, description, category, order_by, order):
     """Search whole project list with matching of collaborator's info
     Param:
     conn -- database connection
     description -- search for project description
     category -- project category
     order_by -- order item
     order -- order (ASC/DESC)
     Return:
     project list based on limits
     """
     skills = self.skill_dict
     edu = self.education
     project_list = []
     # match with each skill-exp pair
     for skill, exp in skills.items():
         # query project table
         if category == -1:
             query = "SELECT project.ID as pID, project_role.ID as rID, project_title, project.last_update as last_update FROM project, project_role, role_skill WHERE project.ID = projectID AND description LIKE \'%%" + description + "%%\' AND skill = " + str(
                 skill) + " AND experience <= " + str(
                     exp) + " AND education <= " + str(
                         edu) + " ORDER BY " + order_by + " " + order + ";"
         else:
             query = "SELECT project.ID as pID, project_role.ID as rID, project_title, project.last_update as last_update FROM project, project_role, role_skill WHERE project.ID = projectID AND description LIKE \'%%" + description + "%%\' AND category = " + str(
                 category
             ) + " AND skill = " + str(skill) + " AND experience <= " + str(
                 exp) + " AND education <= " + str(
                     edu) + " ORDER BY " + order_by + " " + order + ";"
         result = conn.execute(query)
         for i in range(result.rowcount):
             row = result.fetchone()
             # append info without duplicate
             proj = Project.get_by_id(conn, row['pID'])
             is_exist = False
             for project in project_list:
                 if project['id'] == proj['id']: is_exist = True
             if not is_exist:
                 project_list.append(proj)
     if len(project_list) == 0: return None
     project_list.sort(key=lambda p: p['status'])
     return {'projects': project_list, 'amount': result.rowcount}
Exemple #8
0
    def notify_invitee(self, conn, smtp):
        """Send an email to invitee for notification
        Param:
        conn -- database connection
        smtp -- smtp server object
        Return:
        Smtp send result
        """
        proj = Project.get_by_id(conn, self.project_id)
        role = Role.get_by_id(conn, self.role_invite)
        col = Collaborator.get_by_id(conn, self.invitee)
        dre = Dreamer.get_by_id(conn, self.invitor)
        subject = '[DreamMatchmaker]You have a new project invitation'
        content = f'''<p>Hello {col['name']},</p>
<p>   <b>{dre['name']}</b> has invited you to join project <b>"{proj['title']}"</b> as <b>"{role['title']}"</b>.</p>
<p>   The following message is from the invitor:</p>
<p>      {self.general_text}<p>
<p>   You can view the invitation in your dashboard.</p>
<p>Dream Matchmaker Team</p>
'''
        result = smtp.send_email_html(col['email'], content, subject)
        return result
Exemple #9
0
    def notify_applicant(self, conn, smtp):
        """Notify application to applicant through email
        Param:
        conn -- database connection
        smtp -- smtp server
        Return:
        smtp send result
        """
        proj = Project.get_by_id(conn, self.project_id)
        role = Role.get_by_id(conn, self.role_apply)
        col = Collaborator.get_by_id(conn, self.applicant)
        dre = Dreamer.get_by_id(conn, proj['owner'])
        subject = '[DreamMatchmaker]You have created a new project application'
        content = f'''<p>Hello {col['name']},</p>
<p>   You have applied to join project <b>"{proj['title']}"</b> as <b>"{role['title']}"</b>.</p>
<p>   The following message is leaved to project owner:</p>
<p>      {self.general_text}<p>
<p>   The project owner will view your application. The result will be notified through email.</p>
<p>Dream Matchmaker Team</p>
'''
        result = smtp.send_email_html(col['email'], content, subject)
        return result
Exemple #10
0
    def notify_owner(self, conn, smtp):
        """Notify application to project owner through email
        Param:
        conn -- database connection
        smtp -- smtp server
        Return:
        smtp send result
        """
        proj = Project.get_by_id(conn, self.project_id)
        role = Role.get_by_id(conn, self.role_apply)
        col = Collaborator.get_by_id(conn, self.applicant)
        dre = Dreamer.get_by_id(conn, proj['owner'])
        subject = '[DreamMatchmaker]You have a new project application'
        content = f'''<p>Hello {dre['name']},</p>
<p>   <b>{col['name']}</b> has applied to join your project <b>"{proj['title']}"</b> as <b>"{role['title']}"</b></p>
<p>   The following message is from the applicant:</p>
<p>      {self.general_text}<p>
<p>   You can view and accept or decline the application on the website.</p>
<p>Dream Matchmaker Team</p>
'''
        result = smtp.send_email_html(dre['email'], content, subject)
        return result
Exemple #11
0
 def get_by_applicant(conn, user_ID):
     """Get all applications by a collaborator
     Param:
     conn -- database connection
     user_ID -- collaborator digit id
     Return:
     list of all application info for the collaborator
     """
     # query by applicant
     query = "SELECT * FROM application where applicant = " + str(
         user_ID) + " order by ID desc;"
     result = conn.execute(query)
     applications = []
     for i in range(result.rowcount):
         row = result.fetchone()
         # fetch information
         if row['status'] == -1:
             application_status = 'Pending'
         if row['status'] == 0:
             application_status = 'Declined'
         if row['status'] == 1:
             application_status = 'Approved'
         if row['status'] == 9:
             application_status = 'Finished'
         appli = {
             'ApplicationID': row['ID'],
             'projectID': row['projectID'],
             'project_title': Project.get_by_id(conn,
                                                row['projectID'])['title'],
             'Role_applied': row['role_applied'],
             'Role_title': Role.get_by_id(conn,
                                          row['role_applied'])['title'],
             'Applicant': row['applicant'],
             'Application_status': application_status,
             'General_text': row['general_text']
         }
         applications.append(appli)
     return {'applications': applications, 'amount': result.rowcount}