def get_entity_projects(request): """ """ logger.debug('***get_entity_projects method starts ***') entity_id = request.matchdict.get('id', -1) entity = Entity.query.filter_by(id=entity_id).first() logger.debug('entity.projects count :%s', entity.projects) return [ { 'id': project.id, 'name': project.name, 'lead_id': project.lead.id, 'lead_name': project.lead.name, 'date_created': milliseconds_since_epoch(project.date_created), 'created_by_id': project.created_by.id, 'created_by_name': project.created_by.name, 'thumbnail_full_path': project.thumbnail.full_path if project.thumbnail else None, 'status': project.status.name, 'users_count': len(project.users), 'percent_complete': project.percent_complete } for project in entity.projects ]
def get_entity_notes(request): """RESTful version of getting all notes of a task """ logger.debug('get_entity_notes is running') entity_id = request.matchdict.get('id', -1) entity = Entity.query.filter(Entity.id == entity_id).first() if not entity: transaction.abort() return Response('There is no entity with id: %s' % entity_id, 500) sql_query = """select "User_SimpleEntities".id as user_id, "User_SimpleEntities".name, "Users_Thumbnail_Links".full_path, "Notes_SimpleEntities".id as note_id, "Notes_SimpleEntities".description, "Notes_SimpleEntities".date_created, "Notes_Types_SimpleEntities".id, "Notes_Types_SimpleEntities".name, "Notes_Types_SimpleEntities".html_class from "Notes" join "SimpleEntities" as "Notes_SimpleEntities" on "Notes_SimpleEntities".id = "Notes".id left outer join "SimpleEntities" as "Notes_Types_SimpleEntities" on "Notes_Types_SimpleEntities".id = "Notes_SimpleEntities".type_id join "SimpleEntities" as "User_SimpleEntities" on "Notes_SimpleEntities".created_by_id = "User_SimpleEntities".id join "Links" as "Users_Thumbnail_Links" on "Users_Thumbnail_Links".id = "User_SimpleEntities".thumbnail_id where "Notes".entity_id = %(entity_id)s order by "Notes_SimpleEntities".date_created desc""" sql_query = sql_query % {'entity_id': entity_id} result = DBSession.connection().execute(sql_query) return_data = [ { 'created_by_id': r[0], 'created_by_name': r[1], 'created_by_thumbnail': r[2], 'note_id': r[3], 'content': r[4], 'created_date': milliseconds_since_epoch(r[5]), 'note_type_id': r[6], 'note_type_name': r[7], 'note_type_color': r[8] } for r in result.fetchall() ] return return_data
def get_project_sequences(request): """returns the related sequences of the given project as a json data """ entity_id = request.matchdict.get('id', -1) entity = Entity.query.filter_by(id=entity_id).first() return [ { 'thumbnail_full_path': sequence.thumbnail.full_path if sequence.thumbnail else None, 'code': sequence.code, 'id': sequence.id, 'name': sequence.name, 'status': sequence.status.name, 'status_color': sequence.status.html_class if sequence.status.html_class else 'grey', 'created_by_id': sequence.created_by.id, 'created_by_name': sequence.created_by.name, 'description': sequence.description, 'date_created': milliseconds_since_epoch(sequence.date_created), 'percent_complete': sequence.percent_complete } for sequence in entity.sequences ]
def get_entity_events(request): if not multi_permission_checker( request, ['Read_User', 'Read_TimeLog', 'Read_Vacation']): return HTTPForbidden(headers=request) logger.debug('get_user_events is running') keys = get_multi_string(request,'keys') logger.debug('keys: %s'% keys) entity_id = request.matchdict.get('id', -1) entity = Entity.query.filter_by(id=entity_id).first() logger.debug('entity_id : %s' % entity_id) events = [] # if entity.time_logs: if 'time_log' in keys: for time_log in entity.time_logs: # logger.debug('time_log.task.id : %s' % time_log.task.id) # assert isinstance(time_log, TimeLog) events.append({ 'id': time_log.id, 'entity_type': time_log.plural_class_name.lower(), 'title': '%s (%s)' % ( time_log.task.name, ' | '.join( [parent.name for parent in time_log.task.parents])), 'start': milliseconds_since_epoch(time_log.start), 'end': milliseconds_since_epoch(time_log.end), 'className': 'label-success', 'allDay': False, 'status': time_log.task.status.name }) if 'vacation' in keys: vacations = Vacation.query.filter(Vacation.user == None).all() if isinstance(entity, User): vacations.extend(entity.vacations) for vacation in vacations: events.append({ 'id': vacation.id, 'entity_type': vacation.plural_class_name.lower(), 'title': vacation.type.name, 'start': milliseconds_since_epoch(vacation.start), 'end': milliseconds_since_epoch(vacation.end), 'className': 'label-yellow', 'allDay': True, 'status': '' }) if 'task' in keys: today = datetime.datetime.today() for task in entity.tasks: if today < task.end: events.append({ 'id': task.id, 'entity_type': 'tasks', 'title': '%s (%s)' % ( task.name, ' | '.join([parent.name for parent in task.parents])), 'start': milliseconds_since_epoch(task.start), 'end': milliseconds_since_epoch(task.end), 'className': 'label', 'allDay': False, 'status': task.status.name }) return events
def get_tickets(request): """returns all the tickets related to an entity or not """ entity_id = request.matchdict.get('id') #entity = Entity.query.filter_by(id=entity_id).first() entity_type = None if entity_id: # get the entity type sql_query = \ 'select entity_type from "SimpleEntities" where id=%s' % entity_id data = DBSession.connection().execute(sql_query).fetchone() entity_type = data[0] if data else None logger.debug('entity_id : %s' % entity_id) logger.debug('entity_type: %s' % entity_type) sql_query = """select "SimpleEntities_Ticket".id, "SimpleEntities_Ticket".name, "Tickets".number, "Tickets".summary, "Tickets".project_id, "SimpleEntities_Project".name as project_name, "Tickets".owner_id as owner_id, "SimpleEntities_Owner".name as owner_name, "SimpleEntities_Ticket".date_created, "SimpleEntities_Ticket".date_updated, "SimpleEntities_Ticket".created_by_id, "SimpleEntities_CreatedBy".name as created_by_name, "SimpleEntities_Ticket".updated_by_id, "SimpleEntities_UpdatedBy".name as updated_by_name, "SimpleEntities_Status".name as status_name, "Tickets".priority, "SimpleEntities_Type".name as type_name from "Tickets" join "SimpleEntities" as "SimpleEntities_Ticket" on "Tickets".id = "SimpleEntities_Ticket".id join "SimpleEntities" as "SimpleEntities_Project" on "Tickets".project_id = "SimpleEntities_Project".id left outer join "SimpleEntities" as "SimpleEntities_Owner" on "Tickets".owner_id = "SimpleEntities_Owner".id left outer join "SimpleEntities" as "SimpleEntities_CreatedBy" on "SimpleEntities_Ticket".created_by_id = "SimpleEntities_CreatedBy".id left outer join "SimpleEntities" as "SimpleEntities_UpdatedBy" on "SimpleEntities_Ticket".updated_by_id = "SimpleEntities_UpdatedBy".id join "SimpleEntities" as "SimpleEntities_Status" on "Tickets".status_id = "SimpleEntities_Status".id left outer join "SimpleEntities" as "SimpleEntities_Type" on "SimpleEntities_Ticket".type_id = "SimpleEntities_Type".id """ if entity_type: if entity_type == u"Project": sql_query += """where "Tickets".project_id = %s""" % entity_id elif entity_type == u"User": sql_query += """where "Tickets".owner_id = %s""" % entity_id else: sql_query += \ """join "Ticket_SimpleEntities" on "Tickets".id = "Ticket_SimpleEntities".ticket_id where "Ticket_SimpleEntities".simple_entity_id = %s """ % entity_id sql_query += 'order by "Tickets".number' start = time.time() result = DBSession.connection().execute(sql_query) data = [ { 'id': r[0], 'name': r[1], 'number': r[2], 'summary': r[3], 'project_id': r[4], 'project_name': r[5], 'owner_id': r[6], 'owner_name': r[7], 'date_created': milliseconds_since_epoch(r[8]), 'date_updated': milliseconds_since_epoch(r[9]), 'created_by_id': r[10], 'created_by_name': r[11], 'updated_by_id': r[12], 'updated_by_name': r[13], 'status': r[14], 'priority': r[15], 'type': r[16] } for r in result.fetchall() ] end = time.time() logger.debug('get_entity_tickets took : %s seconds for %s rows' % ( end - start, len(data))) return data