-
-
Notifications
You must be signed in to change notification settings - Fork 313
Implement Dark Mode feature with Tailwind #4412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a561e64
9ab8392
5c87cc9
5e777c4
74a0db0
8b997f0
863d1db
976492c
8daf1f1
1d3a476
60594b0
a5f73ac
13992a3
0ace789
46b6350
a937c1e
27f259f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,4 @@ | ||||||||||||||
| import ipaddress | ||||||||||||||
| import logging | ||||||||||||||
|
|
||||||||||||||
| from django.core.cache import cache | ||||||||||||||
| from django.db import models, transaction | ||||||||||||||
|
|
@@ -9,12 +8,10 @@ | |||||||||||||
|
|
||||||||||||||
| MAX_COUNT = 2147483647 | ||||||||||||||
|
|
||||||||||||||
| logger = logging.getLogger(__name__) | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class IPRestrictMiddleware: | ||||||||||||||
| """ | ||||||||||||||
| Middleware to restrict access based on client IP addresses and user agent. | ||||||||||||||
| Middleware to restrict access based on client IP addresses and user agents. | ||||||||||||||
| """ | ||||||||||||||
|
|
||||||||||||||
| def __init__(self, get_response): | ||||||||||||||
|
|
@@ -48,8 +45,8 @@ def blocked_ip_network(self): | |||||||||||||
| try: | ||||||||||||||
| network = ipaddress.ip_network(range_str, strict=False) | ||||||||||||||
| blocked_ip_network.append(network) | ||||||||||||||
| except ValueError as e: | ||||||||||||||
| logger.error(f"Invalid IP network {range_str}: {str(e)}") | ||||||||||||||
| except ValueError: | ||||||||||||||
| # Log the error or handle it as needed, but skip invalid networks | ||||||||||||||
| continue | ||||||||||||||
|
|
||||||||||||||
| return blocked_ip_network | ||||||||||||||
|
|
@@ -73,12 +70,7 @@ def ip_in_range(self, ip, blocked_ip_network): | |||||||||||||
| """ | ||||||||||||||
| Check if the IP address is within any of the blocked IP networks. | ||||||||||||||
| """ | ||||||||||||||
| try: | ||||||||||||||
| ip_obj = ipaddress.ip_address(ip) | ||||||||||||||
| except ValueError as e: | ||||||||||||||
| logger.error(f"Invalid IP address {ip}: {str(e)}") | ||||||||||||||
| return False | ||||||||||||||
|
|
||||||||||||||
| ip_obj = ipaddress.ip_address(ip) | ||||||||||||||
|
||||||||||||||
| ip_obj = ipaddress.ip_address(ip) | |
| try: | |
| ip_obj = ipaddress.ip_address(ip) | |
| except ValueError: | |
| # Invalid IP address, cannot be in any blocked range | |
| return False |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* Custom scrollbar for WebKit browsers */ | ||
| .scrollbar-hide::-webkit-scrollbar { | ||
| width: 8px; | ||
| } | ||
| .scrollbar-hide::-webkit-scrollbar-track { | ||
| background: transparent; | ||
| } | ||
| .scrollbar-hide::-webkit-scrollbar-thumb { | ||
| background-color: rgba(156, 163, 175, 0.5); | ||
| border-radius: 4px; | ||
| } | ||
| .scrollbar-hide::-webkit-scrollbar-thumb:hover { | ||
| background-color: rgba(156, 163, 175, 0.7); | ||
| } | ||
| .dark .scrollbar-hide::-webkit-scrollbar-thumb { | ||
| background-color: rgba(107, 114, 128, 0.5); | ||
| } | ||
| .dark .scrollbar-hide::-webkit-scrollbar-thumb:hover { | ||
| background-color: rgba(107, 114, 128, 0.7); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| document.addEventListener("DOMContentLoaded", () => { | ||
| const htmlElement = document.documentElement; | ||
|
|
||
| // Use event delegation to handle clicks on the theme toggle button, | ||
| // wherever it may be in the DOM. | ||
| document.addEventListener("click", (event) => { | ||
| const toggleButton = event.target.closest("#theme-toggle"); | ||
| if (toggleButton) { | ||
| const isDark = htmlElement.classList.toggle("dark"); | ||
| const newTheme = isDark ? "dark" : "light"; | ||
|
|
||
| // Save user preference | ||
| localStorage.setItem("theme", newTheme); | ||
|
|
||
| // Send theme preference to server if CSRF token is available | ||
| const csrfToken = document.querySelector("[name=csrfmiddlewaretoken]")?.value; | ||
| if (csrfToken) { | ||
| fetch("/set-theme/", { | ||
| method: "POST", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| "X-CSRFToken": csrfToken, | ||
| }, | ||
| body: JSON.stringify({ theme: newTheme }), | ||
| }).catch(error => console.error("Error saving theme preference:", error)); | ||
| } | ||
| } | ||
| }); | ||
| }); |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert