Beispiel #1
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
Beispiel #2
0
 def modified_projects_after_hidden(conn):
     """Check modified projects after hidden
     Param:
     conn -- database connection
     Return:
     list of MaH projects
     """
     query = "SELECT * FROM project WHERE is_hidden = 1 and is_modified_after_hidden = 1 order by last_update ASC;"
     print(query)
     result = conn.execute(query)
     if result.rowcount == 0:
         return None
     project_list = []
     for i in range(result.rowcount):
         row = result.fetchone()
         proj = Project(row['project_title'],
                        row['description'],
                        row['dreamerID'],
                        row['category'],
                        status=row['project_status'],
                        hidden=row['is_hidden'],
                        hidden_reason=row['hidden_reason'])
         proj.id = row['ID']
         proj.is_modified_after_hidden = row['is_modified_after_hidden']
         proj.roles = Role.get_text_by_proj_id(conn, proj.id)
         proj.create_time = row['create_time']
         proj.last_update = row['last_update']
         project_list.append(proj.text_info())
     return project_list
Beispiel #3
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
Beispiel #4
0
 def get_object_by_id(conn, proj_id):
     """Get project info by project id
     Param:
     conn -- database connection
     proj_id -- project digit id
     Return:
     Project info
     """
     query = "SELECT * FROM project WHERE ID = " + str(proj_id) + ";"
     result = conn.execute(query)
     if result.rowcount == 0:
         return None
     row = result.fetchone()
     proj = Project(row['project_title'],
                    row['description'],
                    row['dreamerID'],
                    row['category'],
                    status=row['project_status'],
                    hidden=row['is_hidden'],
                    hidden_reason=row['hidden_reason'])
     proj.id = row['ID']
     proj.is_modified_after_hidden = row['is_modified_after_hidden']
     proj.roles = Role.get_by_proj_id(conn, proj_id)
     proj.create_time = row['create_time']
     proj.last_update = row['last_update']
     return proj
Beispiel #5
0
 def active_projects(conn):
     """Get all active projects
     Param:
     conn -- database connection
     Return:
     list of active projects
     """
     query = "SELECT * FROM project WHERE project_status = 1 AND is_hidden = 0 order by last_update DESC;"
     result = conn.execute(query)
     project_list = []
     for i in range(result.rowcount):
         row = result.fetchone()
         proj = Project(row['project_title'],
                        row['description'],
                        row['dreamerID'],
                        row['category'],
                        status=row['project_status'],
                        hidden=row['is_hidden'],
                        hidden_reason=row['hidden_reason'])
         proj.id = row['ID']
         proj.is_modified_after_hidden = row['is_modified_after_hidden']
         proj.roles = Role.get_text_by_proj_id(conn, proj.id)
         proj.create_time = row['create_time']
         proj.last_update = row['last_update']
         project_list.append(proj.text_info())
     return project_list
Beispiel #6
0
 def get_by_title(conn, project_title):
     """Get project info by project title
     Param:
     conn -- database connection
     proj_title -- title text
     Return:
     Project info
     """
     query = "SELECT * FROM project WHERE project_title = " + project_title.replace(
         "'", "\\\'") + ";"
     result = conn.execute(query)
     if result.rowcount == 0:
         return None
     row = result.fetchone()
     proj = Project(row['project_title'],
                    row['description'],
                    row['dreamerID'],
                    row['category'],
                    status=row['project_status'],
                    hidden=row['is_hidden'],
                    hidden_reason=row['hidden_reason'])
     proj.id = row['ID']
     proj.is_modified_after_hidden = row['is_modified_after_hidden']
     proj.roles = Role.get_by_proj_id(conn, proj.id)
     proj.create_time = row['create_time']
     proj.last_update = row['last_update']
     return proj.info()
Beispiel #7
0
 def get_by_pid_rid_skill(conn, proj_id, role_id, skill):
     """Get another format of project info by project id and specific role with specific skill
     Param:
     conn -- database connection
     proj_id -- project digit id
     role_id -- role digit id
     skill -- skill digit id
     Return:
     Project text info
     """
     query = "SELECT * FROM project WHERE ID = " + str(proj_id) + ";"
     result = conn.execute(query)
     if result.rowcount == 0:
         return None
     row = result.fetchone()
     proj = Project(row['project_title'],
                    row['description'],
                    row['dreamerID'],
                    row['category'],
                    status=row['project_status'],
                    hidden=row['is_hidden'],
                    hidden_reason=row['hidden_reason'])
     proj.id = row['ID']
     proj.is_modified_after_hidden = row['is_modified_after_hidden']
     proj.roles = Role.get_text_by_id(conn, role_id)
     proj.create_time = row['create_time']
     proj.last_update = row['last_update']
     return proj.info()
Beispiel #8
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']
     }
Beispiel #9
0
 def search_list(conn, description, category, order_by, order):
     """Search project list by limits
     Param:
     conn -- database connection
     description -- search description
     category -- search project category
     order_by -- search order item
     order -- search order
     Return:
     Matched project list
     """
     if description != '' and category != -1:
         query = "SELECT * FROM project WHERE description LIKE \'%%" + description + "%%\' AND category = " + str(
             category
         ) + " AND project_status > 0 ORDER BY " + order_by + " " + order + ";"
     elif description != '':
         query = "SELECT * FROM project WHERE description LIKE \'%%" + description + "%%\' AND project_status > 0 ORDER BY " + order_by + " " + order + ";"
     elif category != -1:
         query = "SELECT * FROM project WHERE category = " + str(
             category
         ) + " AND project_status > 0 ORDER BY " + order_by + " " + order + ";"
     else:
         query = "SELECT * FROM project WHERE project_status > 0 ORDER BY " + order_by + " " + order + ";"
     result = conn.execute(query)
     if result.rowcount == 0:
         return None
     project_list = []
     for i in range(result.rowcount):
         row = result.fetchone()
         proj = Project(row['project_title'],
                        row['description'],
                        row['dreamerID'],
                        row['category'],
                        status=row['project_status'],
                        hidden=row['is_hidden'],
                        hidden_reason=row['hidden_reason'])
         proj.id = row['ID']
         proj.is_modified_after_hidden = row['is_modified_after_hidden']
         proj.roles = Role.get_by_proj_id(conn, proj.id)
         proj.create_time = row['create_time']
         proj.last_update = row['last_update']
         project_list.append(proj.info())
     project_list.sort(key=lambda p: p['status'])
     return {'projects': project_list, 'amount': result.rowcount}
Beispiel #10
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}
Beispiel #11
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
Beispiel #12
0
 def get_by_owner(conn, owner_id):
     """Get projects info by project owner
     Param:
     conn -- database connection
     owner_id -- dreamer digit id
     Return:
     list of Project info
     """
     query = "SELECT * FROM project WHERE dreamerID = " + str(
         owner_id) + ";"
     result = conn.execute(query)
     if result.rowcount == 0:
         return None
     project_list = []
     for i in range(result.rowcount):
         row = result.fetchone()
         proj = Project(row['project_title'],
                        row['description'],
                        row['dreamerID'],
                        row['category'],
                        status=row['project_status'],
                        hidden=row['is_hidden'],
                        hidden_reason=row['hidden_reason'])
         proj.id = row['ID']
         proj.is_modified_after_hidden = row['is_modified_after_hidden']
         proj.roles = Role.get_by_proj_id(conn, proj.id)
         proj.create_time = row['create_time']
         proj.last_update = row['last_update']
         info = proj.info()
         info['follow'] = False
         project_list.append(info)
     own_id_list = [proj['id'] for proj in project_list]
     from users.dreamer import Dreamer
     follow_list = Dreamer.get_followed_projects(conn, owner_id)
     for proj in follow_list:
         if proj['id'] in own_id_list:
             follow_list.remove(proj)
     project_list.extend(follow_list)
     # Move finished projects to tail of the list
     project_list.sort(key=lambda p: p['status'])
     return project_list
Beispiel #13
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
Beispiel #14
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
Beispiel #15
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
Beispiel #16
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}