Ejemplo n.º 1
0
def campus_gateways(campus_id):
    return render_template(
        'developer/console/campus/gateways.html',
        campus=Campus.objects(id=campus_id).get(),
        gateways=CampusGateway.objects(campus_id=campus_id),
        menu='gateways',
        gateway_method_ids=GATEWAY_METHOD_IDS,
        module_menus=modulemanager.get_manager_menus()
    )
Ejemplo n.º 2
0
def campus_save_state(campus_id):
    if not is_super_user():
        return abort(403)

    campus = Campus.objects(id=campus_id).get()
    campus.univ_name = request.form.get('univ_name')
    campus.domain = request.form.get('domain')
    campus.univ_type = request.form.get('univ_type')
    campus.campus_name = request.form.get('campus_name')
    campus.save()
    return redirect(url_for('console.campus_state', campus_id=campus_id))
Ejemplo n.º 3
0
    def decorated(*args, **kwargs):
        campus_id = kwargs.get('campus_id')

        try:
            request.campus = Campus.objects(id=campus_id).get()
        except Campus.DoesNotExist:
            return abort(404)

        if not is_super_user() and session.get_admin_account() not in request.campus.admins:
            return abort(403)

        return f(*args, **kwargs)
Ejemplo n.º 4
0
def lecture_sync(campus_id, year, term, code):
    try:
        lecture = Lecture.objects(campus_id=campus_id,
                                  year=year, term=Lecture.term_str_to_int(term), code=code).get()
    except Lecture.DoesNotExist:
        return jsonify({
            'error': {
                'code': 'lecture_not_exist'
            }
        }), 404

    campus = Campus.objects(id=campus_id).get()
    campus.get_gateway().sync_lecture(
        year=lecture.year,
        term=lecture.term_int_to_str(lecture.term),
        code=lecture.code
    )

    return jsonify({})
Ejemplo n.º 5
0
def create_campus():
    if not session.get_admin_account() in app.config.get('DEVCONSOLE_SUPER_USERS', []):
        return abort(403)

    if request.method == 'POST':
        campus = Campus.create_campus(
            univ_name=request.form.get('univ_name'),
            univ_type=request.form.get('univ_type'),
            campus_name=request.form.get('campus_name'),
            admins=[session.get_admin_account()]
        )

        import opencampus.module.lecture.searchengine
        opencampus.module.lecture.searchengine.init_index(str(campus.id))

        return jsonify({
            'id': str(campus.id)
        })

    return render_template('developer/console/campus/create.html')
Ejemplo n.º 6
0
def campus_save_gateway_apis(campus_id):
    campus = Campus.objects(id=campus_id).get()
    apis = json.loads(campus.gateway_apis) if campus.gateway_apis else {}

    for method in GATEWAY_METHOD_IDS:
        gateway_id = request.form.get(method + '_gateway')
        url = request.form.get(method + '_url')
        try:
            gateway = CampusGateway.objects(id=gateway_id, campus_id=campus_id).get()
        except CampusGateway.DoesNotExist:
            return abort(400)

        apis[method] = {
            'gateway_id': gateway_id,
            'url': url
        }

    campus.gateway_apis = json.dumps(apis)
    campus.save()
    return redirect(url_for('console.campus_gateways', campus_id=campus_id))
Ejemplo n.º 7
0
def campus_list():
    page = int(request.args.get('page', 1))
    projects = []

    if is_super_user():
        objects = Campus.objects.skip((page-1)*10).limit(10)
    else:
        objects = Campus.objects(admins__in=[session.get_admin_account()]).skip((page-1)*10).limit(10)

    for campus in objects:
            projects.append({
                'project_id': str(campus.id),
                'project_type': 'campus',
                'project_name': '%s%s %s' % (campus.univ_name, campus.univ_type, campus.campus_name)
            })

    if page != 1 and len(projects) < 1:
        return abort(404)

    return render_template('developer/console/main.html', projects=projects, view_create=is_super_user(),
                           next_page=page+1)
Ejemplo n.º 8
0
def campus_menus(campus_id):
    if request.method == 'POST':
        menus = json.loads(request.form.get('menus'))
        request.campus.menus = json.dumps(menus)
        request.campus.save()

    def encode_menu(data):
        data = data.copy()
        del data['children']
        import json
        import urllib.parse
        return urllib.parse.quote(json.dumps(data).encode('utf-8'))

    return render_template(
        'developer/console/campus/menus.html',
        campus=Campus.objects(id=campus_id).get(),
        menu='menus',
        module_menus=modulemanager.get_manager_menus(),
        campus_service_menus=modulemanager.get_campus_service_menus(),
        encode_menu=encode_menu
    )
Ejemplo n.º 9
0
def app_embedded(app_id):
    try:
        embedded_info = ApplicationEmbedded.objects(application_id=request.app.id).get()
    except ApplicationEmbedded.DoesNotExist:
        embedded_info = None

    if request.method == 'POST':
        use_embedded = request.form.get('use') is not None
        embedded_iframe_uri = request.form.get('uri')
        campus_ids = request.form.getlist('campus')

        from elasticsearch import Elasticsearch
        es = Elasticsearch(hosts=app.config.get('ELASTICSEARCH_HOSTS'))

        if not use_embedded and embedded_info:
            es.delete(index='embedded_app_list', doc_type='embedded_app', id=str(embedded_info.id))
            embedded_info.delete()
            embedded_info = None
        elif use_embedded:
            if not embedded_info:
                embedded_info = ApplicationEmbedded()
                embedded_info.application_id = request.app.id

            embedded_info.iframe_uri = embedded_iframe_uri
            embedded_info.campus_ids = campus_ids
            embedded_info.save()
            embedded_info = ApplicationEmbedded.objects(application_id=request.app.id).get()

            es.index(index='embedded_app_list', doc_type='embedded_app', id=str(embedded_info.id), body={
                'app_id': str(request.app.id),
                'name': request.app.name,
                'description': request.app.description,
                'campus_ids': campus_ids
            })

    return render_template('developer/console/app/embedded.html',
                           campuses=Campus.objects(), use_embedded=embedded_info is not None,
                           embedded_iframe_uri=embedded_info.iframe_uri if embedded_info else '',
                           use_campus_ids=embedded_info.campus_ids if embedded_info else [])
Ejemplo n.º 10
0
        def decorated(*args, **kwargs):
            campus_id = kwargs.get('campus_id', None)
            if campus_id:
                try:
                    request.campus = Campus.objects(id=campus_id).get()
                except Campus.DoesNotExist:
                    return abort(404)

            # check access token
            access_token = None
            auth_header = request.headers.get('Authorization')
            if auth_header and auth_header.startswith('Bearer '):
                access_token = auth_header[7:]
            elif request.args.get('access_token'):
                access_token = request.args.get('access_token')

            request.access_token = None
            if access_token:
                try:
                    request.access_token = OAuth2AccessToken.objects(access_token=access_token).get()
                except OAuth2AccessToken.DoesNotExist:
                    pass

                if not request.access_token:
                    return jsonify({
                        'error': {
                            'code': 'token_not_exist'
                        }
                    }), 403

            result = f(*args, **kwargs)

            callback = request.args.get('callback', None)
            if callback:
                return app.response_class(callback + '(' + result.data.decode('utf8') + ')',
                                          mimetype='application/javascript')

            return result
Ejemplo n.º 11
0
        analogue_obj = LectureAnalogue(
            campus_id=campus_id,
            student_id=student_id1
        )

    analogue_obj.point = analogue
    analogue_obj.target = student_id2
    analogue_obj.save()

    print('%s-%s %s' % (student_id1, student_id2, analogue))


campus_page = 0

while True:
    campuses = Campus.objects().skip(20*campus_page).limit(20)

    if len(campuses) < 1:
        break

    campus_page += 1

    for campus in campuses:
        campus_student_ids = load_student_ids(campus.id)

        for student_id1 in campus_student_ids:
            lecture1 = Lecture.objects(students__in=[student_id1], campus_id=campus.id)
            for student_id2 in campus_student_ids:
                lecture2 = Lecture.objects(students__in=[student_id2], campus_id=campus.id)

                check_data(campus.id, student_id1, lecture1, student_id2, lecture2)
Ejemplo n.º 12
0
def get_campus():
    try:
        return Campus.objects(domain=request.host).get()
    except Campus.DoesNotExist:
        return None
Ejemplo n.º 13
0
def campus_state(campus_id):
    return render_template('developer/console/campus/state.html',
                           campus=Campus.objects(id=campus_id).get(),
                           menu='state',
                           is_super_user=is_super_user(),
                           module_menus=modulemanager.get_manager_menus())