Example #1
0
def index(app=None):
    db_manager = SqlrMongoManager(
        host=current_app.config['MONGO_HOST'],
        port=current_app.config['MONGO_PORT'],
        db=current_app.config['DB'])
    if request.method == 'POST':
        #request.args
        filters = {}
        if app is not None and app != 'All':
            filters['app'] = app
        if 'from' in request.args:
            filters['from'] = request.args['from']
        if 'to' in request.args:
            filters['to'] = request.args['to']
        if 'type' in request.args:
            filters['etype'] = request.args['type']
        events_list = db_manager.get_events(session['user']['token'],
                                            **filters)
        types_list = db_manager.get_types(session['user']['token'])
        apps_list = db_manager.get_apps(session['user']['token'])
        return jsonify({
            'events': events_list,
            'apps': apps_list,
            'types': types_list
        })

    # todo: refactor for use one mongo session
    return render_template('index.html')
Example #2
0
def get():
    """
    JSON params:
    Required:
    token - string
    Optional:
    app - str or list
    date_interval - list with to elems. 0 is min, 1 is max. If you don't need
    max - set it to 0;
    type - string.

    Response:
    result: bool;
    reason: string(returned if result is False;
    events: list; returned if result is True;
    """
    db_manager = SqlrMongoManager(host=current_app.config['MONGO_HOST'],
                                  port=current_app.config['MONGO_PORT'],
                                  db=current_app.config['DB'])
    user = db_manager.validate_token(request.json['token'])
    if not user:
        return jsonify({'result': False, 'reason': 'Wrong token'})

    params = {'app': ['app:default'] if not 'app' in request.json
              else request.json['app']
              if isinstance(request.json['app'], list)
              else [request.json['app']],

              'date_interval': tuple(request.json['date_interval'])
              if 'date_interval' in request.json
              and isinstance(request.json['data_interval'], list) else (),
              'etype': request.json['type'] if 'type' in request.json else None
              }
    # todo: return id
    events = db_manager.get_events(request.json['token'], **params)
    events = list(events)
    return jsonify({'result': True, 'events': events})