vibe.review.web.decorators¶
Decorators for Review web routes.
Provides common setup patterns for review routes including: - Database session management - Review service instantiation - Session validation - Locale handling based on template config - Type-safe injection of validated objects
stream_with_locale ¶
stream_with_locale(generator: Iterator[str], locale: str) -> Iterator[str]
Wrap a generator to execute within a specific locale context.
SSE streaming generators run after the request handler returns, which means they execute outside the decorator's force_locale() context. This wrapper ensures translated strings use the correct locale.
Usage
Inside a route decorated with @review_route_setup¶
locale = str(get_locale()) # Capture locale while in context return Response( stream_with_context(stream_with_locale(my_generator(), locale)), mimetype="text/event-stream", )
| Parameters: |
|
|---|
| Yields: |
|
|---|
with_template_locale ¶
with_template_locale(f: Callable[Concatenate[str, Session, ReviewService, P], T]) -> Callable[Concatenate[str, P], ResponseReturnValue]
Decorate review routes that only need template locale (no session required).
Handle the common pattern of: 1. Getting db_session from request context 2. Creating ReviewService 3. Getting template locale 4. Calling the wrapped function with locale context
The decorated function must accept these positional parameters: - template_id: str (from URL) - db_session: Session (injected) - service: ReviewService (injected)
Usage
@review_bp.route("/
| Returns: |
|
|---|
with_template_info ¶
with_template_info(f: Callable[Concatenate[str, Session, ReviewService, TemplateInfo, P], T]) -> Callable[Concatenate[str, P], ResponseReturnValue]
Decorate review routes that need validated template info with locale.
Like with_template_locale but also: - Validates template exists (returns 404 if not) - Passes template_info to the decorated function
The decorated function must accept these positional parameters: - template_id: str (from URL) - db_session: Session (injected) - service: ReviewService (injected) - template_info: TemplateInfo (injected, guaranteed non-None)
Usage
@review_bp.route("/
| Returns: |
|
|---|
review_route_setup ¶
review_route_setup(f: Callable[Concatenate[str, int, Session, ReviewService, ReviewSessionModel, P], T]) -> Callable[Concatenate[str, int, P], ResponseReturnValue]
Decorate review routes that require a validated session.
Handle the common pattern of: 1. Getting db_session from request context 2. Creating ReviewService 3. Loading and validating review_session 4. Returning appropriate error response if validation fails 5. Injecting validated objects into the route handler
The decorated function must accept these positional parameters: - template_id: str (from URL) - session_id: int (from URL) - db_session: Session (injected) - service: ReviewService (injected) - review_session: ReviewSessionModel (injected, guaranteed non-None)
Usage
@review_bp.route("/
| Returns: |
|
|---|