-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add docstring and typing on helper e util
- Loading branch information
Showing
2 changed files
with
102 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
from typing import Optional | ||
|
||
from django.shortcuts import redirect | ||
from django.contrib import messages | ||
|
||
|
||
def action_response(request, message=None, level=messages.INFO, keep_querystring=True): | ||
redirect_url = '.' | ||
def action_response( | ||
request: "HttpRequest", | ||
message: Optional[str] = None, | ||
level: int = messages.INFO, | ||
keep_querystring: bool = True, | ||
) -> "HttpResponseRedirect": | ||
""" | ||
Redirects the user to the current page with an optional message. | ||
Args: | ||
request: The current request. | ||
message: The message to display to the user. | ||
level: The level of the message. | ||
keep_querystring: Whether to keep the query string in the redirect URL. | ||
Returns: | ||
An HttpResponseRedirect object. | ||
""" | ||
redirect_url = "." | ||
if keep_querystring and request.GET: | ||
redirect_url = './?' + request.GET.urlencode() | ||
redirect_url = "./?" + request.GET.urlencode() | ||
if message: | ||
messages.add_message(request, level, message, fail_silently=True) | ||
return redirect(redirect_url) |