コード例 #1
0
ファイル: handlers.py プロジェクト: qbx2/opencampus
def app_run(app_id):
    try:
        embeded = ApplicationEmbedded.objects(application_id=app_id).get()
    except ApplicationEmbedded.DostNotFound:
        return abort(404)

    return render_template('module/app/run.html', embeded=embeded)
コード例 #2
0
ファイル: handler.py プロジェクト: qbx2/opencampus
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 [])
コード例 #3
0
ファイル: handlers.py プロジェクト: qbx2/opencampus
def app_search():
    query = request.args.get('q', '')
    page = int(request.args.get('page', 1)) - 1
    size = 20
    results = []

    if query == '':
        results = [Application.objects(id=embedded.application_id).get() for embedded in ApplicationEmbedded.objects(
            campus_ids__in=[request.campus.id]).skip(page*size).limit(size)]
    else:
        es = Elasticsearch(hosts=app.config.get('ELASTICSEARCH_HOSTS'))

        search_body = {
            'from': page*size,
            'size': size,
            'sort': ['_score'],
            'query': {
                'bool': {
                    'must': [
                        {
                            'term': {
                                'embedded_app.campus_ids': str(request.campus.id)
                            }
                        },
                        {
                            'query_string': {
                                "default_field": "_all",
                                "query": query
                            }
                        }
                    ]
                }
            }
        }

        res = es.search(index='embedded_app_list', body=search_body)

        for result_app in res.get('hits').get('hits'):
            results.append({
                'id': result_app.get('_source').get('app_id'),
                'name': result_app.get('_source').get('name'),
                'description': result_app.get('_source').get('description'),
            })

    if page > 1 and len(results) < 1:
        return abort(404)

    return render_template('module/app/search.html', results=results, next_page=page+2, query=query)