def get_assets_types(request): """returns the Asset Types """ sql_query = """select "Assets_Types_SimpleEntities".id, "Assets_Types_SimpleEntities".name from "Assets" join "SimpleEntities" as "Assets_SimpleEntities" on "Assets_SimpleEntities".id = "Assets".id join "SimpleEntities" as "Assets_Types_SimpleEntities" on "Assets_Types_SimpleEntities".id = "Assets_SimpleEntities".type_id group by "Assets_Types_SimpleEntities".name, "Assets_Types_SimpleEntities".id order by "Assets_Types_SimpleEntities".name """ result = DBSession.connection().execute(sql_query) return_data = [{ 'asset_type_id': r[0], 'asset_type_name': r[1] } for r in result.fetchall()] content_range = '%s-%s/%s' type_count = len(return_data) content_range = content_range % (0, type_count - 1, type_count) logger.debug('content_range : %s' % content_range) resp = Response(json_body=return_data) resp.content_range = content_range return resp
def get_shots_children_task_type(request): """returns the Task Types defined under the Shot container """ sql_query = """select "SimpleEntities".id as type_id, "SimpleEntities".name as type_name from "SimpleEntities" join "SimpleEntities" as "Task_SimpleEntities" on "SimpleEntities".id = "Task_SimpleEntities".type_id join "Tasks" on "Task_SimpleEntities".id = "Tasks".id join "Shots" on "Tasks".parent_id = "Shots".id group by "SimpleEntities".id, "SimpleEntities".name order by "SimpleEntities".name""" result = DBSession.connection().execute(sql_query) return_data = [{"id": r[0], "name": r[1]} for r in result.fetchall()] content_range = "%s-%s/%s" type_count = len(return_data) content_range = content_range % (0, type_count - 1, type_count) logger.debug("content_range : %s" % content_range) resp = Response(json_body=return_data) resp.content_range = content_range return resp
def get_assets_type_task_types(request): """returns the Task Types defined under the Asset container """ type_id = request.matchdict.get('t_id', None) logger.debug('type_id %s'% type_id) sql_query = """select "SimpleEntities".id as type_id, "SimpleEntities".name as type_name from "SimpleEntities" join "SimpleEntities" as "Task_SimpleEntities" on "SimpleEntities".id = "Task_SimpleEntities".type_id join "Tasks" on "Task_SimpleEntities".id = "Tasks".id join "Assets" on "Tasks".parent_id = "Assets".id join "SimpleEntities" as "Assets_SimpleEntities" on "Assets_SimpleEntities".id = "Assets".id %(where_condition)s group by "SimpleEntities".id, "SimpleEntities".name order by "SimpleEntities".name""" where_condition = '' if type_id: where_condition = 'where "Assets_SimpleEntities".type_id = %(type_id)s'%{'type_id': type_id} sql_query = sql_query %{'where_condition':where_condition} result = DBSession.connection().execute(sql_query) return_data = [ { 'id': r[0], 'name': r[1] } for r in result.fetchall() ] content_range = '%s-%s/%s' type_count = len(return_data) content_range = content_range % (0, type_count - 1, type_count) logger.debug('content_range : %s' % content_range) resp = Response( json_body=return_data ) resp.content_range = content_range return resp
def get_shots_simple(request): """returns all the Shots of the given Project """ entity_id = request.matchdict.get('id', -1) entity = Entity.query.filter_by(id=entity_id).first() shot_id = request.params.get('entity_id', None) logger.debug('get_shots starts ') sql_query = """select "Shot_SimpleEntities".id as id, "Shot_SimpleEntities".name as name from "Shots" join "Tasks" as "Shot_Tasks" on "Shot_Tasks".id = "Shots".id join "SimpleEntities" as "Shot_SimpleEntities" on "Shot_SimpleEntities".id = "Shots".id %(where_condition)s order by "Shot_SimpleEntities".name """ # set the content range to prevent JSONRest Store to query the data twice content_range = '%s-%s/%s' where_condition = '' if entity.entity_type == 'Sequence': where_condition = 'where "Shot_Sequences".sequence_id = %s' % entity_id elif entity.entity_type == 'Project': where_condition = 'where "Shot_Tasks".project_id = %s' % entity_id sql_query = sql_query % {'where_condition': where_condition} logger.debug('entity_id : %s' % entity_id) # convert to dgrid format right here in place result = DBSession.connection().execute(sql_query) return_data = [] for r in result.fetchall(): r_data = {'id': r[0], 'name': r[1]} return_data.append(r_data) shot_count = len(return_data) content_range = content_range % (0, shot_count - 1, shot_count) logger.debug('get_shots_simple ends ') resp = Response(json_body=return_data) resp.content_range = content_range return resp
def make_response(uri, environ): res = Response(conditional_response=True) # check if the host is online. If not raise an http error if not pingSMB( parseSMBuri(uri)["host"] ): return HTTPGatewayTimeout("Host is currently offline. You may try again at a later time.") try: f = c.open(uri) except smbc.NoEntryError: return HTTPNotFound("The file you requested is no longer available!") fs = f.fstat() filesize = fs[6] last_modified = fs[8] # mtime filename = uri.split("/")[-1] req = Request(environ) log.debug("Incoming request: \n" + str(req)) if req.range: log.debug("begin ranged transfer") res.status_int = 206 res.content_range = req.range.content_range(filesize) (start, stop) = req.range.range_for_length(filesize) log.debug("filesize: " + str(filesize)) log.debug("start: " + str(start) + " stop: " + str(stop)) log.debug("Content-Range: " + str(res.content_range)) res.app_iter = FileIterable(uri, start=start, stop=stop) res.content_length = stop - start else: log.debug("begin normal transfer") res.app_iter = FileIterable(uri) res.content_length = filesize log.debug("Content-Length: " + str(res.content_length)) res.server_protocol = "HTTP/1.1" # Make sure the file gets downloaded and not played live res.content_type = "application/octet-stream" res.last_modified = last_modified res.etag = '%s-%s-%s' % (fs[8], fs[6], hash(f)) res.headers.add("Content-Disposition", 'attachment; filename="%s"' % str(filename) ) res.headers.add("Accept-Ranges", "bytes") return res
def get_assets_type_task_types(request): """returns the Task Types defined under the Asset container """ type_id = request.matchdict.get('t_id', None) logger.debug('type_id %s' % type_id) sql_query = """select "SimpleEntities".id as type_id, "SimpleEntities".name as type_name from "SimpleEntities" join "SimpleEntities" as "Task_SimpleEntities" on "SimpleEntities".id = "Task_SimpleEntities".type_id join "Tasks" on "Task_SimpleEntities".id = "Tasks".id join "Assets" on "Tasks".parent_id = "Assets".id join "SimpleEntities" as "Assets_SimpleEntities" on "Assets_SimpleEntities".id = "Assets".id %(where_condition)s group by "SimpleEntities".id, "SimpleEntities".name order by "SimpleEntities".name""" where_condition = '' if type_id: where_condition = 'where "Assets_SimpleEntities".type_id = %(type_id)s' % { 'type_id': type_id } sql_query = sql_query % {'where_condition': where_condition} result = DBSession.connection().execute(sql_query) return_data = [{'id': r[0], 'name': r[1]} for r in result.fetchall()] content_range = '%s-%s/%s' type_count = len(return_data) content_range = content_range % (0, type_count - 1, type_count) logger.debug('content_range : %s' % content_range) resp = Response(json_body=return_data) resp.content_range = content_range return resp
def get_assets_types(request): """returns the Asset Types """ sql_query ="""select "Assets_Types_SimpleEntities".id, "Assets_Types_SimpleEntities".name from "Assets" join "SimpleEntities" as "Assets_SimpleEntities" on "Assets_SimpleEntities".id = "Assets".id join "SimpleEntities" as "Assets_Types_SimpleEntities" on "Assets_Types_SimpleEntities".id = "Assets_SimpleEntities".type_id group by "Assets_Types_SimpleEntities".name, "Assets_Types_SimpleEntities".id order by "Assets_Types_SimpleEntities".name """ result = DBSession.connection().execute(sql_query) return_data = [ { 'asset_type_id': r[0], 'asset_type_name': r[1] } for r in result.fetchall() ] content_range = '%s-%s/%s' type_count = len(return_data) content_range = content_range % (0, type_count - 1, type_count) logger.debug('content_range : %s' % content_range) resp = Response( json_body=return_data ) resp.content_range = content_range return resp
def get_shots(request): """returns all the Shots of the given Project """ entity_id = request.matchdict.get('id', -1) entity = Entity.query.filter_by(id=entity_id).first() shot_id = request.params.get('entity_id', None) logger.debug('get_shots starts ') sql_query = """select "Shots".id as shot_id, "Shot_SimpleEntities".name as shot_name, "Shot_SimpleEntities".description as shot_description, "Links".full_path as shot_full_path, "Distinct_Shot_Statuses".shot_status_code as shot_status_code, "Distinct_Shot_Statuses".shot_status_html_class as shot_status_html_class, array_agg("Distinct_Shot_Task_Types".type_name) as type_name, array_agg("Tasks".id) as task_id, array_agg("Task_SimpleEntities".name) as task_name, array_agg("Task_Statuses".code) as status_code, array_agg("Task_Statuses_SimpleEntities".html_class) as status_html_class, array_agg(coalesce( -- for parent tasks (case "Tasks".schedule_seconds when 0 then 0 else "Tasks".total_logged_seconds::float / "Tasks".schedule_seconds * 100 end ), -- for child tasks we need to count the total seconds of related TimeLogs (coalesce("Task_TimeLogs".duration, 0.0))::float / ("Tasks".schedule_timing * (case "Tasks".schedule_unit when 'min' then 60 when 'h' then 3600 when 'd' then 32400 when 'w' then 183600 when 'm' then 734400 when 'y' then 9573418 else 0 end)) * 100.0 )) as percent_complete, "Shot_Sequences".sequence_id as sequence_id, "Shot_Sequences_SimpleEntities".name as sequence_name, array_agg("Tasks".bid_timing) as bid_timing, array_agg("Tasks".bid_unit)::text[] as bid_unit, array_agg("Tasks".schedule_timing) as schedule_timing, array_agg("Tasks".schedule_unit)::text[] as schedule_unit, array_agg("Resources_SimpleEntities".name) as resource_name, array_agg("Resources_SimpleEntities".id) as resource_id, "Shots".cut_in as cut_in, "Shots".cut_out as cut_out from "Tasks" join "Shots" on "Shots".id = "Tasks".parent_id join "SimpleEntities" as "Shot_SimpleEntities" on "Shots".id = "Shot_SimpleEntities".id join "SimpleEntities" as "Task_SimpleEntities" on "Tasks".id = "Task_SimpleEntities".id left join "Links" on "Shot_SimpleEntities".thumbnail_id = "Links".id join( select "Shots".id as shot_id, "Statuses".code as shot_status_code, "SimpleEntities".html_class as shot_status_html_class, "Tasks".parent_id as shot_parent from "Tasks" join "Shots" on "Shots".id = "Tasks".id join "Statuses" on "Statuses".id = "Tasks".status_id join "SimpleEntities" on "SimpleEntities".id = "Statuses".id )as "Distinct_Shot_Statuses" on "Shots".id = "Distinct_Shot_Statuses".shot_id left join ( select "SimpleEntities".id as type_id, "SimpleEntities".name as type_name from "SimpleEntities" join "SimpleEntities" as "Task_SimpleEntities" on "SimpleEntities".id = "Task_SimpleEntities".type_id join "Tasks" on "Task_SimpleEntities".id = "Tasks".id join "Shots" on "Tasks".parent_id = "Shots".id group by "SimpleEntities".id, "SimpleEntities".name order by "SimpleEntities".id ) as "Distinct_Shot_Task_Types" on "Task_SimpleEntities".type_id = "Distinct_Shot_Task_Types".type_id join "Statuses" as "Task_Statuses" on "Tasks".status_id = "Task_Statuses".id join "SimpleEntities" as "Task_Statuses_SimpleEntities" on "Task_Statuses_SimpleEntities".id = "Tasks".status_id left join "Shot_Sequences" on "Shot_Sequences".shot_id = "Shots".id left join "SimpleEntities" as "Shot_Sequences_SimpleEntities" on "Shot_Sequences_SimpleEntities".id = "Shot_Sequences".sequence_id left outer join ( select "TimeLogs".task_id, extract(epoch from sum("TimeLogs".end::timestamp AT TIME ZONE 'UTC' - "TimeLogs".start::timestamp AT TIME ZONE 'UTC')) as duration from "TimeLogs" group by task_id ) as "Task_TimeLogs" on "Task_TimeLogs".task_id = "Tasks".id left outer join "Task_Resources" on "Tasks".id = "Task_Resources".task_id join "SimpleEntities" as "Resources_SimpleEntities" on "Resources_SimpleEntities".id = "Task_Resources".resource_id %(where_condition)s group by "Shots".id, "Shot_SimpleEntities".name, "Shot_SimpleEntities".description, "Links".full_path, "Distinct_Shot_Statuses".shot_status_code, "Distinct_Shot_Statuses".shot_status_html_class, "Shot_Sequences".sequence_id, "Shot_Sequences_SimpleEntities".name, "Shots".cut_in, "Shots".cut_out order by "Shot_SimpleEntities".name """ # set the content range to prevent JSONRest Store to query the data twice content_range = '%s-%s/%s' where_condition = '' if entity.entity_type == 'Sequence': where_condition = 'where "Shot_Sequences".sequence_id = %s' % entity_id elif entity.entity_type == 'Project': where_condition = 'where "Tasks".project_id = %s' % entity_id elif entity.entity_type == 'Task': if entity.type.name == 'Scene': where_condition = """join "Tasks" as "Parent_Tasks" on "Parent_Tasks".id = "Distinct_Shot_Statuses".shot_parent join "Tasks" as "Scene_Tasks" on "Scene_Tasks".id = "Parent_Tasks".parent_id where "Scene_Tasks".id = %s""" % entity_id if shot_id: where_condition = 'where "Shots".id = %(shot_id)s' % ({ 'shot_id': shot_id }) update_shot_permission = \ PermissionChecker(request)('Update_Shot') delete_shot_permission = \ PermissionChecker(request)('Delete_Shot') sql_query = sql_query % {'where_condition': where_condition} logger.debug('entity_id : %s' % entity_id) # convert to dgrid format right here in place result = DBSession.connection().execute(sql_query) return_data = [] for r in result.fetchall(): r_data = { 'id': r[0], 'name': r[1], 'description': r[2], 'thumbnail_full_path': r[3] if r[3] else None, 'status': r[4], 'status_color': r[5], 'sequence_id': r[12], 'sequence_name': r[13], 'cut_in': r[20], 'cut_out': r[21], 'update_shot_action': '/tasks/%s/update/dialog' % r[0] if update_shot_permission else None, 'delete_shot_action': '/tasks/%s/delete/dialog' % r[0] if delete_shot_permission else None } task_types_names = r[6] task_ids = r[7] task_names = r[8] task_statuses = r[9] task_statuses_color = r[10] task_percent_complete = r[11] task_bid_timing = r[14] task_bid_unit = r[15] task_schedule_timing = r[16] task_schedule_unit = r[17] task_resource_name = r[18] task_resource_id = r[19] r_data['nulls'] = [] for index1 in range(len(task_types_names)): if task_types_names[index1]: r_data[task_types_names[index1]] = [] for index in range(len(task_types_names)): task = { 'id': task_ids[index], 'name': task_names[index], 'status': task_statuses[index], 'percent': task_percent_complete[index], 'bid_timing': task_bid_timing[index], 'bid_unit': task_bid_unit[index], 'schedule_timing': task_schedule_timing[index], 'schedule_unit': task_schedule_unit[index], 'resource_name': task_resource_name[index], 'resource_id': task_resource_id[index] } if task_types_names[index]: r_data[task_types_names[index]].append(task) else: r_data['nulls'].append(task) return_data.append(r_data) shot_count = len(return_data) content_range = content_range % (0, shot_count - 1, shot_count) logger.debug('get_shots ends ') resp = Response(json_body=return_data) resp.content_range = content_range return resp
def get_shots(request): """returns all the Shots of the given Project """ entity_id = request.matchdict.get("id", -1) entity = Entity.query.filter_by(id=entity_id).first() shot_id = request.params.get("entity_id", None) logger.debug("get_shots function starts : ") sql_query = """select "Shots".id as shot_id, "Shot_SimpleEntities".name as shot_name, "Shot_SimpleEntities".description as shot_description, "Links".full_path as shot_full_path, "Distinct_Shot_Statuses".shot_status_code as shot_status_code, "Distinct_Shot_Statuses".shot_status_html_class as shot_status_html_class, array_agg("Distinct_Shot_Task_Types".type_name) as type_name, array_agg("Tasks".id) as task_id, array_agg("Task_SimpleEntities".name) as task_name, array_agg("Task_Statuses".code) as status_code, array_agg("Task_Statuses_SimpleEntities".html_class) as status_html_class, array_agg(coalesce( -- for parent tasks (case "Tasks".schedule_seconds when 0 then 0 else "Tasks".total_logged_seconds::float / "Tasks".schedule_seconds * 100 end ), -- for child tasks we need to count the total seconds of related TimeLogs (coalesce("Task_TimeLogs".duration, 0.0))::float / ("Tasks".schedule_timing * (case "Tasks".schedule_unit when 'min' then 60 when 'h' then 3600 when 'd' then 32400 when 'w' then 147600 when 'm' then 590400 when 'y' then 7696277 else 0 end)) * 100.0 )) as percent_complete, "Shot_Sequences".sequence_id as sequence_id, "Shot_Sequences_SimpleEntities".name as sequence_name from "Tasks" join "Shots" on "Shots".id = "Tasks".parent_id join "SimpleEntities" as "Shot_SimpleEntities" on "Shots".id = "Shot_SimpleEntities".id join "SimpleEntities" as "Task_SimpleEntities" on "Tasks".id = "Task_SimpleEntities".id left join "Links" on "Shot_SimpleEntities".thumbnail_id = "Links".id join( select "Shots".id as shot_id, "Statuses".code as shot_status_code, "SimpleEntities".html_class as shot_status_html_class from "Tasks" join "Shots" on "Shots".id = "Tasks".id join "Statuses" on "Statuses".id = "Tasks".status_id join "SimpleEntities" on "SimpleEntities".id = "Statuses".id )as "Distinct_Shot_Statuses" on "Shots".id = "Distinct_Shot_Statuses".shot_id left join ( select "SimpleEntities".id as type_id, "SimpleEntities".name as type_name from "SimpleEntities" join "SimpleEntities" as "Task_SimpleEntities" on "SimpleEntities".id = "Task_SimpleEntities".type_id join "Tasks" on "Task_SimpleEntities".id = "Tasks".id join "Shots" on "Tasks".parent_id = "Shots".id group by "SimpleEntities".id, "SimpleEntities".name order by "SimpleEntities".id ) as "Distinct_Shot_Task_Types" on "Task_SimpleEntities".type_id = "Distinct_Shot_Task_Types".type_id join "Statuses" as "Task_Statuses" on "Tasks".status_id = "Task_Statuses".id join "SimpleEntities" as "Task_Statuses_SimpleEntities" on "Task_Statuses_SimpleEntities".id = "Tasks".status_id left join "Shot_Sequences" on "Shot_Sequences".shot_id = "Shots".id left join "SimpleEntities" as "Shot_Sequences_SimpleEntities" on "Shot_Sequences_SimpleEntities".id = "Shot_Sequences".sequence_id left outer join ( select "TimeLogs".task_id, extract(epoch from sum("TimeLogs".end::timestamp AT TIME ZONE 'UTC' - "TimeLogs".start::timestamp AT TIME ZONE 'UTC')) as duration from "TimeLogs" group by task_id ) as "Task_TimeLogs" on "Task_TimeLogs".task_id = "Tasks".id %(where_condition)s group by "Shots".id, "Shot_SimpleEntities".name, "Shot_SimpleEntities".description, "Links".full_path, "Distinct_Shot_Statuses".shot_status_code, "Distinct_Shot_Statuses".shot_status_html_class, "Shot_Sequences".sequence_id, "Shot_Sequences_SimpleEntities".name order by "Shot_SimpleEntities".name """ # set the content range to prevent JSONRest Store to query the data twice content_range = "%s-%s/%s" where_condition = "" if entity.entity_type == "Sequence": where_condition = 'where "Shot_Sequences".sequence_id = %s' % entity_id elif entity.entity_type == "Project": where_condition = "" if shot_id: where_condition = 'where "Shots".id = %(shot_id)s' % ({"shot_id": shot_id}) update_shot_permission = PermissionChecker(request)("Update_Shot") delete_shot_permission = PermissionChecker(request)("Delete_Shot") sql_query = sql_query % {"where_condition": where_condition} logger.debug("entity_id : %s" % entity_id) # convert to dgrid format right here in place result = DBSession.connection().execute(sql_query) return_data = [] for r in result.fetchall(): r_data = { "id": r[0], "name": r[1], "description": r[2], "thumbnail_full_path": r[3] if r[3] else None, "status": r[4], "status_color": r[5], "sequence_id": r[12], "sequence_name": r[13], "update_shot_action": "/tasks/%s/update/dialog" % r[0] if update_shot_permission else None, "delete_shot_action": "/tasks/%s/delete/dialog" % r[0] if delete_shot_permission else None, } task_types_names = r[6] task_ids = r[7] task_names = r[8] task_statuses = r[9] task_statuses_color = r[10] task_percent_complete = r[11] logger.debug("task_types_names %s " % task_types_names) r_data["nulls"] = [] for index1 in range(len(task_types_names)): if task_types_names[index1]: r_data[task_types_names[index1]] = [] for index in range(len(task_types_names)): logger.debug("task_types_names[index]; %s " % task_types_names[index]) if task_types_names[index]: r_data[task_types_names[index]].append( [task_ids[index], task_names[index], task_statuses[index], task_percent_complete[index]] ) else: r_data["nulls"].append( [task_ids[index], task_names[index], task_statuses[index], task_percent_complete[index]] ) return_data.append(r_data) shot_count = len(return_data) content_range = content_range % (0, shot_count - 1, shot_count) resp = Response(json_body=return_data) resp.content_range = content_range return resp