def assign_learning_plan(): post_data = json.loads(request.data.decode('utf-8')) # this is only for current user for now learner_email = current_user.email learning_plan = Statement.create_plan(plan_name='Actions from diagnostic', learner_actor=learner_email) for resource in post_data: tincan_data = resource.get('tincan', dict()) verb = tincan_data.get('verb') or 'read' statement_obj = tincan_data.get('object') or Statement.create_activity_obj( uri=resource.get('url'), name=resource.get('title')) tincan_result = tincan_data.get('result', dict()) required = tincan_result.get('completion', resource.get('required')) duration = tincan_result.get('duration', resource.get('duration')) planned_item = Statement( verb=verb, statement_obj=statement_obj, required=required, duration=duration) learning_plan.add_planned_item(planned_item) current_app.logger.info(learning_plan.to_json()) lrs_result = lrs_service.save_statement(learning_plan.to_json()) resp = jsonify({ 'postData': post_data, 'plan': learning_plan.to_json(), 'lrsResult': lrs_result }) resp.status_code = lrs_result.get('status', lrs_result.get('code', 200)) if type(lrs_result) is dict else 200 return resp
def assign_learning_plan(): post_data = json.loads(request.data.decode('utf-8')) # this is only for current user for now learner_email = current_user.email learning_plan = Statement.create_plan(plan_name='Actions from diagnostic', learner_actor=learner_email) for resource in post_data: tincan_data = resource.get('tincan', dict()) verb = tincan_data.get('verb') or 'read' statement_obj = tincan_data.get('object') or Statement.create_activity_obj( uri=resource.get('url'), name=resource.get('title')) tincan_result = tincan_data.get('result', dict()) required = tincan_result.get('completion', resource.get('required')) duration = tincan_result.get('duration', resource.get('duration')) planned_item = Statement( verb=verb, statement_obj=statement_obj, required=required, duration=duration) learning_plan.add_planned_item(planned_item) lrs_result = lrs_service.save_learning_plan(learning_plan) resp = jsonify({ 'postData': post_data, 'plan': learning_plan.to_json(), 'lrsResult': lrs_result }) resp.status_code = lrs_result.get('code', 200) if type(lrs_result) is dict else 200 return resp