Example #1
0
def getRecommendationsByRequirementId(requirement_id):
    try:
        conn = mysql.connect()
        cursor = conn.cursor()
        query = u"SELECT * FROM recommendations_get_all " \
                u"WHERE requirement_a_id = {} ORDER BY {} ASC;".format(requirement_id, "distance")
        row_headers = [CamelEncoder.underscore_to_camel(x[0]) for x in cursor.description]
        data = cursor.fetchall()
        json_data = []
        for result in data:
            json_data.append(dict(zip(row_headers, result)))

        return simplejson.dumps(json_data, default=datetime_encoder, cls=DecimalEncoder, sort_keys=True, indent=4)
    except Exception as e:
        return jsonify({'error': str(e)})
Example #2
0
def getProject(project_id):
    try:
        conn = mysql.connect()
        cursor = conn.cursor()
        query = u"SELECT * FROM projects_get_all WHERE project_id = {};".format(project_id)
        cursor.execute(query)
        row_headers = [CamelEncoder.underscore_to_camel(x[0]) for x in cursor.description]
        data = cursor.fetchall()
        json_data = []
        for result in data:
            json_data.append(dict(zip(row_headers, result)))

        return simplejson.dumps(json_data, default=datetime_encoder, cls=DecimalEncoder, sort_keys=True, indent=4)
    except Exception as e:
        return {'error': str(e)}
Example #3
0
def getCategoriesByProjectId(project_id):
    try:
        conn = mysql.connect()
        cursor = conn.cursor()

        query = u"SELECT    c.* FROM {} p " \
                u"INNER JOIN {} c ON c.project_id = p.project_id " \
                u"WHERE     p.project_id = {} " \
                .format("projects", "categories", project_id)
        cursor.execute(query)
        row_headers = [CamelEncoder.underscore_to_camel(x[0]) for x in cursor.description]
        data = cursor.fetchall()
        json_data = []
        for result in data:
            json_data.append(dict(zip(row_headers, result)))

        return simplejson.dumps(json_data, default=datetime_encoder, cls=DecimalEncoder, sort_keys=True, indent=4)
    except Exception as e:
        return {'error': str(e)}