Skip to content

Commit

Permalink
Test out cookies
Browse files Browse the repository at this point in the history
Trying to test out cookies for preferences
  • Loading branch information
JustinBanzon committed Nov 7, 2023
1 parent 714ec4d commit ab8be82
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ACMAS/app/ACMAS_Web/templates/_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% load component_tags %}

<!DOCTYPE html>
{% with mode="dark" %}
{% with mode="light" %}
<html lang="en" class={{ mode }}>
{% block head %}

Expand Down Expand Up @@ -278,7 +278,7 @@
</li>
<li><a class="block py-2 pl-3 pr-4 text-gray-900 dark:text-white rounded md:hover:bg-gray-100 md:hover:bg-transparent md:border-0 hover:text-gray-500" href="https://github.com/ACMAS/ACMAS-Frontend">Github</a></li>
<li>
<button href="/darkmode" class="block py-2 pl-3 pr-4 text-gray-900 dark:text-white rounded md:hover:bg-gray-100 md:hover:bg-transparent md:border-0 hover:text-gray-500">Toggle dark mode</button>
<button href="/dark-mode" class="block py-2 pl-3 pr-4 text-gray-900 dark:text-white rounded md:hover:bg-gray-100 md:hover:bg-transparent md:border-0 hover:text-gray-500">Toggle dark mode</button>
<!-- To do: add an event listener to "listen" for when this button is pressed and change the mode variable from light to dark or vice versa-->
</li>
</ul>
Expand Down
32 changes: 32 additions & 0 deletions ACMAS/app/ACMAS_Web/templates/darkmode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% extends '_base.html' %}
{% load component_tags %}

{% block title %}ACMAS Homepage{% endblock %}

{% block google_description %}ACMAS is the free homework and backtest helper created by students for students. Join our community of students anonymously today!{% endblock %}
{% block google_title %}ACMAS: Automated Course Material Archiving System{% endblock %}
{% block google_keywords %}homework, homework help, exam, exam help, student, free homework help, free school help, tutor, online tutor{% endblock %}

{% block twitter_title %}ACMAS: Automated Course Material Archiving System{% endblock %}
{% block twitter_description %}ACMAS is the free homework and backtest helper created by students for students. Join our community of students anonymously today!{% endblock %}

{% block facebook_title %}ACMAS: Automated Course Material Archiving System{% endblock %}
{% block facebook_description %}ACMAS is the free homework and backtest helper created by students for students. Join our community of students anonymously today!{% endblock %}
{% block facebook_url %}www.acmas.systems{% endblock %}


{% block content %}
<div class="flex mt-24">
<div class="text-7xl" style="color: #327796; font-family: Inter, serif;">Simplify <br> studying with</div>
<div class="">
<a href="/">
<img
alt="ACMAS logo"
class="w-96 h-auto pt-4 pl-5"
src="../static/img/ACMAS_Logo.svg"
/>
</a>
</div>
</div>
{% endblock content %}
<h1>This is a test of cookies</h1>
2 changes: 1 addition & 1 deletion ACMAS/app/ACMAS_Web/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
path("pdfReader", views.pdfReader, name="pdfReader"),
path("upload-file", views.uploadFile, name="uploadFile"),
path("upload-manually", views.uploadManually, name="uploadManually"),
path("darkmode",views.toggleDarkMode,name="darkmode"),
path("dark-mode", views.darkMode, name="darkMode"),
path("sitemap.xml", views.sitemap, name="sitemap"),
path("favicon.ico", views.favicon, name="favicon"),
path("robots.txt", views.robots, name="robots"),
Expand Down
17 changes: 12 additions & 5 deletions ACMAS/app/ACMAS_Web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def generateContext(request):
# ACMAS homepage
def index(request):
context = generateContext(request)
print("So this is where print messages go")
request.session.set_test_cookie()
return render(request, "index.html", context)

Expand All @@ -44,6 +45,9 @@ def favicon(request):

# Search by question page
def searchByQuestion(request):
if request.session.test_cookie_worked():
print("The test cookie works")
request.session.delete_test_cookie()
context = generateContext(request)
question = request.POST.get("question") # Check to see if a question was entered
if (
Expand Down Expand Up @@ -210,11 +214,14 @@ def uploadManually(request):
# Do manual question upload logic
createFacade().uploadText(school, course, question, answer, assignment_type)
return render(request, "upload-manually.html", context)
def toggleDarkMode(request):


def darkMode(request):
context = generateContext(request)
#There must be some way to detect which template the user is on.
current_template="index.html"
if request.session.test_cookie_worked():
print("The test cookie works")
print("The test cookie worked!!!")
request.session.delete_test_cookie()
return render(request,current_template,context)
# There must be some way to detect which template the user is on.
return render(request, "darkmode.html", context)


0 comments on commit ab8be82

Please sign in to comment.