Exemplo n.º 1
0
def init_campus_index():
    if not is_super_user():
        return abort(403)

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

    try:
        es.indices.close(index='campus_list')
    except:
        pass
    try:
        es.indices.put_settings(index='campus_list', body={
            "index": {
                "analysis": {
                    "analyzer": {
                        "korean": {
                            "type": "custom",
                            "tokenizer": "mecab_ko_standard_tokenizer"
                        }
                    }
                }
            }
        })
    except:
        es.indices.create(index='campus_list', body={
            "settings": {
                "index": {
                    "analysis": {
                        "analyzer": {
                            "korean": {
                                "type": "custom",
                                "tokenizer": "mecab_ko_standard_tokenizer"
                            }
                        }
                    }
                }
            }
        })

    es.indices.open(index='campus_list')

    try:
        es.indices.delete_mapping(index='campus_list', doc_type='campus')
    except:
        pass

    es.indices.put_mapping(index='campus_list', doc_type='campus', body={
        "_all": {
            "analyzer": "korean"
        }
    })

    return redirect(url_for('console.project_list'))
Exemplo 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))
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 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.º 6
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.º 7
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.º 8
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())