Exemplo n.º 1
0
def get_events_backend(
    request: HttpRequest,
    user_profile: UserProfile,
    handler: BaseHandler,
    user_client: Optional[Client] = REQ(converter=get_client, default=None),
    last_event_id: Optional[int] = REQ(converter=int, default=None),
    queue_id: Optional[List[str]] = REQ(default=None),
    apply_markdown: bool = REQ(default=False, validator=check_bool),
    client_gravatar: bool = REQ(default=False, validator=check_bool),
    all_public_streams: bool = REQ(default=False, validator=check_bool),
    event_types: Optional[str] = REQ(default=None,
                                     validator=check_list(check_string)),
    dont_block: bool = REQ(default=False, validator=check_bool),
    narrow: Iterable[Sequence[str]] = REQ(default=[],
                                          validator=check_list(None)),
    lifespan_secs: int = REQ(default=0, converter=int)
) -> Union[HttpResponse, _RespondAsynchronously]:
    if user_client is None:
        valid_user_client = request.client
    else:
        valid_user_client = user_client

    events_query = dict(user_profile_id=user_profile.id,
                        user_profile_email=user_profile.email,
                        queue_id=queue_id,
                        last_event_id=last_event_id,
                        event_types=event_types,
                        client_type_name=valid_user_client.name,
                        all_public_streams=all_public_streams,
                        lifespan_secs=lifespan_secs,
                        narrow=narrow,
                        dont_block=dont_block,
                        handler_id=handler.handler_id)

    if queue_id is None:
        events_query['new_queue_data'] = dict(
            user_profile_id=user_profile.id,
            realm_id=user_profile.realm_id,
            user_profile_email=user_profile.email,
            event_types=event_types,
            client_type_name=valid_user_client.name,
            apply_markdown=apply_markdown,
            client_gravatar=client_gravatar,
            all_public_streams=all_public_streams,
            queue_timeout=lifespan_secs,
            last_connection_time=time.time(),
            narrow=narrow)

    result = fetch_events(events_query)
    if "extra_log_data" in result:
        request._log_data['extra'] = result["extra_log_data"]

    if result["type"] == "async":
        handler._request = request
        return RespondAsynchronously
    if result["type"] == "error":
        raise result["exception"]
    return json_success(result["response"])
Exemplo n.º 2
0
def get_events_backend(request: HttpRequest, user_profile: UserProfile, handler: BaseHandler,
                       user_client: Optional[Client]=REQ(converter=get_client, default=None),
                       last_event_id: Optional[int]=REQ(converter=int, default=None),
                       queue_id: Optional[List[str]]=REQ(default=None),
                       apply_markdown: bool=REQ(default=False, validator=check_bool),
                       client_gravatar: bool=REQ(default=False, validator=check_bool),
                       all_public_streams: bool=REQ(default=False, validator=check_bool),
                       event_types: Optional[str]=REQ(default=None, validator=check_list(check_string)),
                       dont_block: bool=REQ(default=False, validator=check_bool),
                       narrow: Iterable[Sequence[str]]=REQ(default=[], validator=check_list(None)),
                       lifespan_secs: int=REQ(default=0, converter=int)
                       ) -> Union[HttpResponse, _RespondAsynchronously]:
    if user_client is None:
        valid_user_client = request.client
    else:
        valid_user_client = user_client

    events_query = dict(
        user_profile_id = user_profile.id,
        user_profile_email = user_profile.email,
        queue_id = queue_id,
        last_event_id = last_event_id,
        event_types = event_types,
        client_type_name = valid_user_client.name,
        all_public_streams = all_public_streams,
        lifespan_secs = lifespan_secs,
        narrow = narrow,
        dont_block = dont_block,
        handler_id = handler.handler_id)

    if queue_id is None:
        events_query['new_queue_data'] = dict(
            user_profile_id = user_profile.id,
            realm_id = user_profile.realm_id,
            user_profile_email = user_profile.email,
            event_types = event_types,
            client_type_name = valid_user_client.name,
            apply_markdown = apply_markdown,
            client_gravatar = client_gravatar,
            all_public_streams = all_public_streams,
            queue_timeout = lifespan_secs,
            last_connection_time = time.time(),
            narrow = narrow)

    result = fetch_events(events_query)
    if "extra_log_data" in result:
        request._log_data['extra'] = result["extra_log_data"]

    if result["type"] == "async":
        handler._request = request
        return RespondAsynchronously
    if result["type"] == "error":
        raise result["exception"]
    return json_success(result["response"])
Exemplo n.º 3
0
def get_events_backend(request: HttpRequest, user_profile: UserProfile, handler: BaseHandler,
                       # user_client is intended only for internal Django=>Tornado requests
                       # and thus shouldn't be documented for external use.
                       user_client: Optional[Client]=REQ(converter=get_client, default=None,
                                                         intentionally_undocumented=True),
                       last_event_id: Optional[int]=REQ(converter=int, default=None),
                       queue_id: Optional[str]=REQ(default=None),
                       # apply_markdown, client_gravatar, all_public_streams, and various
                       # other parameters are only used when registering a new queue via this
                       # endpoint.  This is a feature used primarily by get_events_internal
                       # and not expected to be used by third-party clients.
                       apply_markdown: bool=REQ(default=False, validator=check_bool,
                                                intentionally_undocumented=True),
                       client_gravatar: bool=REQ(default=False, validator=check_bool,
                                                 intentionally_undocumented=True),
                       all_public_streams: bool=REQ(default=False, validator=check_bool,
                                                    intentionally_undocumented=True),
                       event_types: Optional[str]=REQ(default=None, validator=check_list(check_string),
                                                      intentionally_undocumented=True),
                       dont_block: bool=REQ(default=False, validator=check_bool),
                       narrow: Iterable[Sequence[str]]=REQ(default=[], validator=check_list(None),
                                                           intentionally_undocumented=True),
                       lifespan_secs: int=REQ(default=0, converter=to_non_negative_int,
                                              intentionally_undocumented=True)
                       ) -> Union[HttpResponse, _RespondAsynchronously]:
    if user_client is None:
        valid_user_client = request.client
    else:
        valid_user_client = user_client

    events_query = dict(
        user_profile_id = user_profile.id,
        user_profile_email = user_profile.email,
        queue_id = queue_id,
        last_event_id = last_event_id,
        event_types = event_types,
        client_type_name = valid_user_client.name,
        all_public_streams = all_public_streams,
        lifespan_secs = lifespan_secs,
        narrow = narrow,
        dont_block = dont_block,
        handler_id = handler.handler_id)

    if queue_id is None:
        events_query['new_queue_data'] = dict(
            user_profile_id = user_profile.id,
            realm_id = user_profile.realm_id,
            user_profile_email = user_profile.email,
            event_types = event_types,
            client_type_name = valid_user_client.name,
            apply_markdown = apply_markdown,
            client_gravatar = client_gravatar,
            all_public_streams = all_public_streams,
            queue_timeout = lifespan_secs,
            last_connection_time = time.time(),
            narrow = narrow)

    result = fetch_events(events_query)
    if "extra_log_data" in result:
        request._log_data['extra'] = result["extra_log_data"]

    if result["type"] == "async":
        handler._request = request
        return RespondAsynchronously
    if result["type"] == "error":
        raise result["exception"]
    return json_success(result["response"])