Exemplo n.º 1
0
def create_app():
    if not session.get_admin_account():
        return abort(403)

    if request.method == 'POST':
        application = Application()
        application.name = request.form.get('app_name')
        application.created_at = datetime.utcnow()
        application.admins = [session.get_admin_account()]
        application.save()

        return redirect(url_for('console.app_state', app_id=application.id))

    return render_template('developer/console/app/create.html', is_super_user=is_super_user())
Exemplo n.º 2
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')
Exemplo 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)
Exemplo n.º 4
0
    def decorated(*args, **kwargs):
        app_id = kwargs.get('app_id')

        try:
            request.app = Application.objects(id=app_id).get()
        except Application.DoesNotExist:
            return abort(404)

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

        return f(*args, **kwargs)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def app_list():
    page = int(request.args.get('page', 1))
    projects = []

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

    for app in objects:
        projects.append({
            'project_id': str(app.id),
            'project_type': 'app',
            'project_name': '%s' % app.name
        })

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

    return render_template('developer/console/main.html', projects=projects, view_create=True,
                           next_page=page+1)
Exemplo n.º 7
0
def is_super_user():
    return session.get_admin_account() in app.config.get('DEVCONSOLE_SUPER_USERS', [])