-
-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Mypy type errors fix * Moved event_bridhe_scheduler inside fuction * Updated imports * Auth User moved to HtmxHttpRequest * HttpRequest replaced with authorized HtmxHttpRequest
- Loading branch information
Showing
44 changed files
with
184 additions
and
169 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
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
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
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
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
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,31 +1,32 @@ | ||
from django.contrib import messages | ||
from django.http import HttpRequest, HttpResponse | ||
from django.http import HttpResponse | ||
from django.shortcuts import render | ||
|
||
from backend.models import * | ||
from backend.types.htmx import HtmxHttpRequest | ||
|
||
|
||
def return_error_notif(request: HttpRequest, message: str): | ||
def return_error_notif(request: HtmxHttpRequest, message: str): | ||
messages.error(request, message) | ||
resp = render(request, "partials/messages_list.html", status=200) | ||
resp["HX-Trigger-After-Swap"] = "leave_team_error" | ||
return resp | ||
|
||
|
||
def leave_team_confirmed(request: HttpRequest, team_id): | ||
team: Team = Team.objects.filter(id=team_id).first() | ||
def leave_team_confirmed(request: HtmxHttpRequest, team_id): | ||
team: Team | None = Team.objects.filter(id=team_id).first() | ||
|
||
if not team: | ||
return return_error_notif(request, "Team not found") | ||
|
||
if team.leader == request.user: # may be changed in the future. If no members allow delete | ||
return return_error_notif(request, "You cannot leave your own team") | ||
|
||
if not request.user.teams_joined.filter(id=team_id).exists(): | ||
if request.user.teams_joined.filter(id=team_id).exists(): | ||
team.members.remove(request.user) | ||
messages.success(request, f"You have successfully left the team {team.name}") | ||
response = HttpResponse(status=200) | ||
response["HX-Refresh"] = "true" | ||
return response | ||
else: | ||
return return_error_notif(request, "You are not a member of this team") | ||
|
||
team.members.remove(request.user) | ||
messages.success(request, f"You have successfully left the team {team.name}") | ||
response = HttpResponse(status=200) | ||
response["HX-Refresh"] = "true" | ||
return response |
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
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
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
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,6 +1,14 @@ | ||
from django.contrib.auth.models import AnonymousUser | ||
from django.http import HttpRequest | ||
from django_htmx.middleware import HtmxDetails | ||
|
||
from backend.models import User | ||
|
||
|
||
class HtmxHttpRequest(HttpRequest): | ||
htmx: HtmxDetails | ||
user: User | ||
|
||
|
||
class UnauthorizedHttpRequest(HttpRequest): | ||
user: AnonymousUser |
Empty file.
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from backend.models import FeatureFlags | ||
from django.core.cache import cache | ||
from django.core.cache.backends.redis import RedisCacheClient | ||
|
||
cache: RedisCacheClient = cache | ||
|
||
|
||
def get_feature_status(feature, should_use_cache=True): | ||
if should_use_cache: | ||
key = f"myfinances:feature_flag:{feature}" | ||
cached_value = cache.get(key) | ||
if cached_value: | ||
return cached_value | ||
|
||
value = FeatureFlags.objects.filter(name=feature).first() | ||
if value: | ||
if should_use_cache: | ||
cache.set(key, value.value, timeout=300) | ||
return value.value | ||
else: | ||
return False | ||
|
||
|
||
def set_cache(key, value, timeout=300): | ||
cache.set(key, value, timeout=timeout) | ||
|
||
|
||
def get_cache(key): | ||
return cache.get(key) |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.http import HttpResponseRedirect | ||
|
||
|
||
def redirect_to_last_visited(request, fallback_url="dashboard"): | ||
""" | ||
Redirects user to the last visited URL stored in session. | ||
If no previous URL is found, redirects to the fallback URL. | ||
:param request: HttpRequest object | ||
:param fallback_url: URL to redirect to if no previous URL found | ||
:return: HttpResponseRedirect object | ||
""" | ||
try: | ||
last_visited_url = request.session.get("last_visited", fallback_url) | ||
return HttpResponseRedirect(last_visited_url) | ||
except KeyError: | ||
return HttpResponseRedirect(fallback_url) |
Oops, something went wrong.