コード例 #1
0
 def decorated_function(*args, **kwargs):
     anon = current_user.is_anonymous
     if anon or (not current_user.is_admin()):
         EventLogger.log_request(request,
                                 cuid="" if anon else current_user.id,
                                 msg=request.url)
     return f(*args, **kwargs)
コード例 #2
0
    def decorated_function(*args, **kwargs):
        event = {"msg": request.url}

        if not current_user.is_anonymous:
            if not current_user.is_admin():
                event.update({
                    "cuid": current_user.id,
                    "profile": current_user.profile
                })
            else:
                # if current user is admin we don't bother logging this event
                return f(*args, **kwargs)

        # If the user is anonymous or a regular user, we log the event
        EventLogger.log_request(request, **event)
        return f(*args, **kwargs)
コード例 #3
0
def query_activities(username, out_type):
    user = Users.get(username)
    if user:
        options = {
            k: toObj(request.args.get(k))
            for k in request.args if toObj(request.args.get(k))
        }
        if not options:
            options = {"limit": 10}

        anon = current_user.is_anonymous
        if anon or (not current_user.is_admin()):
            EventLogger.log_request(request,
                                    cuid="" if anon else current_user.id,
                                    msg="{} query for {}: {}".format(
                                        out_type, user.id, options))
    else:
        return

    if out_type == "json":
        return jsonify(list(user.query_activities(**options)))

    else:

        def go(user, pool, out_queue):
            options["pool"] = pool
            options["out_queue"] = out_queue
            user.query_activities(**options)
            pool.join()
            out_queue.put(None)
            out_queue.put(StopIteration)

        pool = gevent.pool.Pool(app.config.get("CONCURRENCY"))
        out_queue = gevent.queue.Queue()
        gevent.spawn(go, user, pool, out_queue)
        gevent.sleep(0)
        return Response((sse_out(a) if a else sse_out() for a in out_queue),
                        mimetype='text/event-stream')
コード例 #4
0
def robots_txt():
    EventLogger.log_request(request, cuid="bot", msg=request.user_agent.string)
    return send_from_directory(os.path.join(app.root_path, 'static'),
                               'robots.txt')