Example #1
0
def projects_for_user(user_id, cursor = None):

    cursor.execute("""
                SELECT  project.id as proj_id, 
                        project.designator as proj_designator, 
                        project.name as proj_name,
                        project_image.folder as image_folder, 
                        project_image.file_name as image_file_name,
                        project_image.file_type as image_file_type
                    from project
                    LEFT JOIN project_image ON project_image.project_id = project.id
                    WHERE project.id IN 
                        (
                            SELECT distinct project_id
                                from user_projects
                            where user_id = %(user_id)s
                        );""",
                {'user_id': user_id})

    results = cursor.fetchall() or {}

    projects = []
    for row in results:
        
        projects.append(Project.map_from_form(row))

    return projects
Example #2
0
def create_project(api_response = True):

    project_form = sanitize.form_keys(json.loads(request.form['payload']))
    project = Project.map_from_form(project_form)

    token_form = sanitize.form_keys(json.loads(request.form['token']))
    token = Token.map_from_form(token_form)

    project = project_insert.create_project(project, token.user_id)

    parent_url = "api/DAL/images/projects/"
    project.image.save_to_file_system(parent_url)

    return response.success(project.id)
Example #3
0
def project(project_id, cursor = None):

    cursor.execute("""
                SELECT distinct
                        project.id as proj_id, 
                        project.designator as proj_designator, 
                        project.name as proj_name,
                        project_image.folder as image_folder, 
                        project_image.file_name as image_file_name,
                        project_image.file_type as image_file_type
                    from project
                    LEFT JOIN project_image ON project_image.project_id = project.id
                WHERE project.id = %(project_id)s""",
                {'project_id': project_id})

    row = cursor.fetchone()
    
    project = Project.map_from_form(row)

    return project