예제 #1
0
def competencies():
    # Look for comp args, if none display all comps
    d = {}
    uri = request.args.get('uri', None)
    mb = request.args.get('mb', False)

    if uri:
        if current_user.is_authenticated():
            user = User(current_user.id)
            comps = user.getAllComps()
            d['registered'] = str(hash(uri)) in comps.keys()

        d['uri'] = uri
        comp = models.getCompetency(uri, objectid=True)
        d['cid'] = comp.pop('_id')
        d['comp'] = comp
        # If medbiq comp display xml if so since it's the original and not lossy internal one
        if mb:
            if not comp.get('edited', False) and competency.isMB(comp):
                try:
                    thexml = requests.get(competency.addXMLSuffix(
                        comp['uri'])).text
                except:
                    thexml = mbc.toXML(comp)
            else:
                thexml = mbc.toXML(comp)
            return Response(thexml, mimetype='application/xml')
        else:
            compuri = d['uri']
            if 'adlnet' in d['uri']:
                compuri = compuri[:7] + 'www.' + compuri[7:]
            url = "https://node01.public.learningregistry.net/slice?any_tags=%s" % compuri
            resp = requests.get(url)
            ids = []
            if resp.status_code == 200:
                lrresults = json.loads(resp.content)
                ids = [s['doc_ID'] for s in lrresults['documents']]
                for d_id in ids:
                    models.updateCompetencyLR(
                        d['cid'],
                        current_app.config['LR_NODE'] + d_id + '&by_doc_ID=T')
                updated_comp = models.getCompetency(uri, objectid=True)
                d['comp'] = updated_comp

            return render_template('comp-details.html', **d)

    d['comps'] = models.findCompetencies()
    return render_template('competencies.html', **d)
예제 #2
0
def quiz():
    uri = request.args.get('uri', None)
    user = User(current_user.id)
    comp = models.getCompetency(uri)

    if request.method == 'GET':
        return render_template('quiz.html',
                               uri=uri,
                               title=comp['title'],
                               data=comp['quiz'])
    else:
        questions = []
        answers = []
        types = []
        responses = []

        for x in range(1, 6):
            questions.append(request.form.get('questionasked' + str(x)))
            answers.append(request.form.get('answer' + str(x)))
            types.append(request.form.get('type' + str(x)))
            responses.append(request.form.get('question' + str(x)))

        actor = user.getFullAgent()
        actor_name = "%s %s" % (user.first_name, user.last_name)
        quiz_name = "adl_xci:%s" % urllib.quote_plus(comp['title'])
        display_name = comp['title'] + ' quiz'

        wrong, data = models.get_result_statements(responses, answers, types,
                                                   questions, actor,
                                                   actor_name, quiz_name,
                                                   display_name, uri)
        score = 5 - wrong

        lrs_list = []
        for prof in user.profile['lrsprofiles']:
            lrs_result_info = {'name': prof['name']}
            headers = {
                'Authorization': prof['auth'],
                'content-type': 'application/json',
                'X-Experience-API-Version': '1.0.0'
            }

            post_resp = requests.post(prof['endpoint'] + "statements",
                                      data=json.dumps(data),
                                      headers=headers,
                                      verify=False)
            lrs_result_info['status'] = post_resp.status_code
            lrs_result_info['content'] = post_resp.content

            lrs_result_info['stmts'], lrs_result_info[
                'sens'] = models.retrieve_statements(
                    lrs_result_info['status'], lrs_result_info['content'],
                    prof['endpoint'] + "statements", headers)
            lrs_list.append(lrs_result_info)

        return render_template('quiz_results.html',
                               title=comp['title'],
                               uri=comp['uri'],
                               score=score,
                               lrs_list=lrs_list)
예제 #3
0
파일: views.py 프로젝트: adlnet/xci
def competencies():
    # Look for comp args, if none display all comps
    d = {}
    uri = request.args.get('uri', None)
    mb = request.args.get('mb', False)
    
    if uri:      
        if current_user.is_authenticated():
            user = User(current_user.id)
            comps = user.getAllComps()            
            d['registered'] = str(hash(uri)) in comps.keys()

        d['uri'] = uri
        comp = models.getCompetency(uri, objectid=True)
        d['cid'] = comp.pop('_id')
        d['comp'] = comp
        # If medbiq comp display xml if so since it's the original and not lossy internal one
        if mb:
            if not comp.get('edited', False) and competency.isMB(comp):
                try:
                    thexml = requests.get(competency.addXMLSuffix(comp['uri'])).text
                except:
                    thexml = mbc.toXML(comp)
            else:
                thexml = mbc.toXML(comp)
            return Response(thexml, mimetype='application/xml')
        else:
            compuri = d['uri']
            if 'adlnet' in d['uri']:
                compuri = compuri[:7] + 'www.' + compuri[7:]
            url = "https://node01.public.learningregistry.net/slice?any_tags=%s" % compuri
            resp = requests.get(url)
            ids = []
            if resp.status_code == 200:
                lrresults = json.loads(resp.content)
                ids = [s['doc_ID'] for s in lrresults['documents']]
                for d_id in ids:
                    models.updateCompetencyLR(d['cid'], current_app.config['LR_NODE'] + d_id + '&by_doc_ID=T')
                updated_comp = models.getCompetency(uri, objectid=True)
                d['comp'] = updated_comp

            return render_template('comp-details.html', **d)

    d['comps'] = models.findCompetencies()
    return render_template('competencies.html', **d)
예제 #4
0
def frameworks():
    if request.method == 'GET':
        # Determine if requesting specific fwk or not
        uri = request.args.get('uri', None)
        if uri:
            d = {}
            if current_user.is_authenticated():
                d['registered'] = str(hash(uri)) in User(
                    current_user.id).profile['compfwks'].keys()

            d['uri'] = uri

            fwk = models.getCompetencyFramework(uri)
            for c in fwk['competencies']:
                compuri = c['uri']
                comp = models.getCompetency(compuri, objectid=True)
                if comp:
                    cid = comp['_id']
                    if 'adlnet' in compuri:
                        compuri = compuri[:7] + 'www.' + compuri[7:]
                        url = "https://node01.public.learningregistry.net/slice?any_tags=%s" % compuri
                        resp = requests.get(url)
                        ids = []
                        if resp.status_code == 200:
                            lrresults = json.loads(resp.content)
                            ids = [s['doc_ID'] for s in lrresults['documents']]
                            for d_id in ids:
                                models.updateCompetencyLR(
                                    cid, current_app.config['LR_NODE'] + d_id +
                                    '&by_doc_ID=T')

            d['fwk'] = models.getCompetencyFramework(uri)
            return render_template('compfwk-details.html', **d)

        return_dict = {'frameworks_form': FrameworksForm()}
    else:
        # Validate submitted fwk uri/parse/add to system
        ff = FrameworksForm(request.form)
        if ff.validate_on_submit():
            #add to system
            competency.parseComp(ff.framework_uri.data)
            return_dict = {'frameworks_form': FrameworksForm()}
        else:
            return_dict = {'frameworks_form': ff}

    return_dict['cfwks'] = models.findCompetencyFrameworks()
    return render_template('frameworks.html', **return_dict)
예제 #5
0
파일: views.py 프로젝트: adlnet/xci
def quiz():
    uri = request.args.get('uri', None)
    user = User(current_user.id)
    comp = models.getCompetency(uri)


    if request.method == 'GET':
        return render_template('quiz.html', uri=uri, title=comp['title'], data=comp['quiz'])
    else:    
        questions = []
        answers = []
        types = []
        responses = []

        for x in range(1,6):
            questions.append(request.form.get('questionasked' + str(x)))
            answers.append(request.form.get('answer' + str(x)))
            types.append(request.form.get('type' + str(x)))
            responses.append(request.form.get('question' + str(x)))

        actor = user.getFullAgent()
        actor_name = "%s %s" % (user.first_name, user.last_name)
        quiz_name = "adl_xci:%s" % urllib.quote_plus(comp['title'])
        display_name = comp['title'] + ' quiz'
       
        wrong, data = models.get_result_statements(responses, answers, types, questions, actor, actor_name, quiz_name, display_name, uri)
        score = 5 - wrong

        lrs_list = []
        for prof in user.profile['lrsprofiles']:
            lrs_result_info = {'name': prof['name']}
            headers = {
                    'Authorization': prof['auth'],
                    'content-type': 'application/json',        
                    'X-Experience-API-Version': '1.0.0'
            }

            post_resp = requests.post(prof['endpoint'] + "statements", data=json.dumps(data), headers=headers, verify=False)
            lrs_result_info['status'] = post_resp.status_code
            lrs_result_info['content'] = post_resp.content

            lrs_result_info['stmts'], lrs_result_info['sens'] = models.retrieve_statements(lrs_result_info['status'],
                lrs_result_info['content'], prof['endpoint'] + "statements", headers)    
            lrs_list.append(lrs_result_info)

        return render_template('quiz_results.html', title=comp['title'], uri=comp['uri'], score=score, lrs_list=lrs_list)
예제 #6
0
파일: views.py 프로젝트: creighton/xci
def frameworks():
    if request.method == 'GET':
        # Determine if requesting specific fwk or not
        uri = request.args.get('uri', None)
        if uri:
            d = {}
            if current_user.is_authenticated():
                username = current_user.id
                user = models.getUserProfile(username)            
                d['registered'] = str(hash(uri)) in user['compfwks'].keys()

            d['uri'] = uri
            
            fwk = models.getCompetencyFramework(uri)
            for c in fwk['competencies']:
                compuri = c['uri']
                comp = models.getCompetency(compuri, objectid=True)
                if comp:
                    cid = comp['_id']
                    if 'adlnet' in compuri:
                        compuri = compuri[:7] + 'www.' + compuri[7:]
                        url = "https://node01.public.learningregistry.net/slice?any_tags=%s" % compuri
                        resp = requests.get(url)
                        ids = []
                        if resp.status_code == 200:
                            lrresults = json.loads(resp.content)
                            ids = [s['doc_ID'] for s in lrresults['documents']]
                            for d_id in ids:
                                models.updateCompetencyLR(cid, LR_NODE + d_id + '&by_doc_ID=T')

            d['fwk'] = models.getCompetencyFramework(uri)
            return render_template('compfwk-details.html', **d)

        return_dict = {'frameworks_form': FrameworksForm()}
    else:
        # Validate submitted fwk uri/parse/add to system
        ff = FrameworksForm(request.form)
        if ff.validate_on_submit():
            #add to system
            competency.parseComp(ff.framework_uri.data)
            return_dict = {'frameworks_form': FrameworksForm()}
        else:
            return_dict = {'frameworks_form': ff}

    return_dict['cfwks'] = models.findCompetencyFrameworks()
    return render_template('frameworks.html', **return_dict)