Skip to content

Commit

Permalink
Trying to make functionality with darkmode using cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBanzon committed Nov 17, 2023
1 parent b85cca9 commit 5aaa07d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ACMAS/app/ACMAS_Web/templates/_base.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!-- templates/_base.html -->
{% load static %}
{% load component_tags %}
{% with mode="light" %}
<!DOCTYPE html>
<html lang="en" class={{mode}}>

Expand Down Expand Up @@ -153,6 +152,7 @@
<li><a class="block py-2 pl-3 pr-4 text-gray-900 rounded md:hover:bg-gray-100 md:hover:bg-transparent md:border-0 hover:text-gray-500" href="/login">Login</a></li>
{% endblock %}
{% endif %}
<li><a class="block py-2 pl-3 pr-4 text-gray-900 rounded md:hover:bg-gray-100 md:hover:bg-transparent md:border-0 hover:text-gray-500" href="/dark-mode">Change theme (currently {{ mode }})</a></li>
</ul>
</div>
</div>
Expand All @@ -175,5 +175,4 @@
</ul>
</footer>
{% endblock body %}
{% endwith %}
</html>
14 changes: 13 additions & 1 deletion ACMAS/app/ACMAS_Web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def generateContext(request):
+ os.getenv("GOOGLE_ANALYTICS_ID", default=""),
"CANONICAL_PATH": request.build_absolute_uri(request.path),
}
if 'mode' in request.COOKIES:
context['mode'] = request.COOKIES.get('mode')
else:
request.COOKIES['mode'] = 'light'
context['mode'] = "light"
return context


Expand Down Expand Up @@ -234,5 +239,12 @@ def profile(request):


def darkmode(request):
if 'mode' in request.COOKIES:
mode = request.COOKIES.get('mode')
if mode == 'dark':
request.COOKIES['mode'] = 'light'
else:
request.COOKIES['mode'] = 'dark'
context = generateContext(request)
return render(request, "darkmode.html", context)

return render(request, "index.html", context)

0 comments on commit 5aaa07d

Please sign in to comment.