示例#1
0
    def addProjectRating(self, proj_id, user_id, rating):
        log = logging.getLogger('csdt')
        log.info("Project.addProjectRating()")

        # Checks if user has already submitted a rating to the given project. If not, it should return an empty set.
        sql = "SELECT pr.project_id AS project_id, pr.user_id AS user_id, pr.rating AS rating from projects p, project_ratings pr, users u WHERE p.id = pr.project_id AND u.id = pr.user_id AND pr.project_id = %s AND pr.user_id = %s AND u.active = 1 AND p.active = 1;" % (str(proj_id), str(user_id))
        result = database.executeSelectQuery(sql, "one")
        if result is None:
            if int(rating) == 0:
                log.warning("User has returned a 0 rating")
                return

            sql = "INSERT INTO project_ratings (project_id, user_id, rating) VALUES (%s, %s, %s);" % (str(proj_id), str(user_id), str(rating))
            result = database.executeInsertQuery(sql)
            return

        sql = "DELETE FROM project_ratings where project_id = %s AND user_id = %s;" % (str(proj_id), str(user_id))
        result = database.executeDeleteQuery(sql)

        if int(rating) == 0:
            log.warning("User has returned a 0 rating")
            return

        sql = "INSERT INTO project_ratings (project_id, user_id, rating) VALUES (%s, %s, %s);" % (str(proj_id), str(user_id), str(rating))
        result = database.executeInsertQuery(sql)

        return
    def removeProjectFromClass(self, proj_id, class_id): 
        log = logging.getLogger('csdt')
        log.info("AccountProject.removeProjectFromClass()")
    
        # Deletes the class that the project will be associated with
        sql = "DELETE FROM project_memberships WHERE project_id = %s AND class_id = %s;" % (str(proj_id), str(class_id))
        result = database.executeDeleteQuery(sql)

        return 
    def banComment(self, comment_id): 
        log = logging.getLogger('csdt')
        log.info("AccountComment.banComment()")

        # Removes the flag and the comment
        sql = "UPDATE project_comments SET flag = 0, active = 0 WHERE id = %s;" % (str(comment_id))
        result = database.executeUpdateQuery(sql)

        # Removes the flag for all users who flagged the specific comment
        sql = "DELETE FROM project_comments_ratings WHERE proj_comment_id = %s;" % (str(comment_id))
        result = database.executeDeleteQuery(sql)
        
        return