def _create_learning_plan_view_model(plan, email): planned_items = [] for item in load_learning_plan_items(plan['object']['id']): records = load_learning_plan_item_learning_records( email, item['statementId']) verb_name = item['verb']['display']['en'] info_lines = [] resource_type = Statement.get_resource_type( item.get('object').get('definition').get('type')) if resource_type: resource_type = resource_type.get('name', '') info_lines.append(resource_type) duration = item.get('result', {}).get('duration') if duration: duration = 'Average time: ' + mls_dates.convert_duration(duration) info_lines.append(duration) actions = [{ 'title': verb_name.capitalize() + (' again' if records else ' now'), 'url': item['object']['id'] }] # taking the last one to display, done like this as who knows what they are going to come up with # all records may be required later if records: records = [records[-1]] planned_item = { 'statementId': item['statementId'], 'records': records, 'title': '%s %s' % (verb_name.capitalize(), item['object']['definition']['name']['en']), 'required': item.get('result', {}).get('completion', False), 'descriptionLines': [], 'infoLines': info_lines, 'actions': actions } planned_items.append(planned_item) return { 'statementId': plan['statementId'], 'title': plan['object']['definition']['name']['en'], 'addedBy': 'diagnostic', 'descriptionLines': [], 'sections': [], 'items': planned_items }
def _create_learning_plan_view_model(plan, email): planned_items = [] for item in load_learning_plan_items(plan['object']['id']): records = load_learning_plan_item_learning_records(email, item['statementId']) verb_name = item['verb']['display']['en'] info_lines = [] resource_type = Statement.get_resource_type(item.get('object').get('definition').get('type')) if resource_type: resource_type = resource_type.get('name', '') info_lines.append(resource_type) duration = item.get('result', {}).get('duration') if duration: duration = 'Average time: ' + mls_dates.convert_duration(duration) info_lines.append(duration) actions = [{ 'title': verb_name.capitalize() + (' again' if records else ' now'), 'url': item['object']['id'] }] # taking the last one to display, done like this as who knows what they are going to come up with # all records may be required later if records: records = [records[-1]] planned_item = { 'statementId': item['statementId'], 'records': records, 'title': '%s %s' % (verb_name.capitalize(), item['object']['definition']['name']['en']), 'required': item.get('result', {}).get('completion', False), 'descriptionLines': [], 'infoLines': info_lines, 'actions': actions } planned_items.append(planned_item) return { 'statementId': plan['statementId'], 'title': plan['object']['definition']['name']['en'], 'addedBy': 'diagnostic', 'descriptionLines': [], 'sections': [], 'items': planned_items }
def format_duration(duration): try: return mls_dates.convert_duration(duration) except Exception as e: logger.exception('Error while formatting duration:' + str(e)) return ''