From b270d10826d9792e3cd9dfca691025a1ce9ad3fb Mon Sep 17 00:00:00 2001 From: Brody Wilton <brodywilton@hotmail.com> Date: Fri, 22 Mar 2024 01:13:56 +0000 Subject: [PATCH] Change navbar to display different things based on logged in or not --- myproject/myapp/templates/_base.html | 28 ++++++++++++++------ myproject/myapp/templates/index2.html | 2 +- myproject/myapp/urls.py | 3 ++- myproject/myapp/views.py | 37 +++++++++++++++++---------- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/myproject/myapp/templates/_base.html b/myproject/myapp/templates/_base.html index c7cc36d..c9ba994 100644 --- a/myproject/myapp/templates/_base.html +++ b/myproject/myapp/templates/_base.html @@ -56,34 +56,46 @@ >Home</a > </li> + + {% if user.is_authenticated %} <li> <a - href="{% url 'user_login' %}" + href="{% url 'pricing' %}" class="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent" - >Login</a + >Pricing</a > </li> <li> <a - href="{% url 'register' %}" + href="{% url 'users' %}" class="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent" - >Register</a + >Dashboard</a > </li> + <li> <a - href="{% url 'pricing' %}" + href="#" class="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent" - >Pricing</a + >Logout</a > </li> + {% else %} <li> <a - href="{% url 'users' %}" + href="{% url 'user_login' %}" class="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent" - >Dashboard</a + >Login</a + > + </li> + <li> + <a + href="{% url 'register' %}" + class="block py-2 px-3 text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 md:p-0 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent" + >Register</a > </li> + {% endif %} </ul> </div> </div> diff --git a/myproject/myapp/templates/index2.html b/myproject/myapp/templates/index2.html index 7cf84cd..443f7f2 100644 --- a/myproject/myapp/templates/index2.html +++ b/myproject/myapp/templates/index2.html @@ -24,7 +24,7 @@ </h2> <p class="mb-8 font-light text-gray-500 lg:mb-16 sm:text-xl dark:text-gray-400"> <a href="{% url 'register' %}" class="inline-flex items-center font-medium text-primary-600 hover:text-primary-800 dark:text-primary-500 dark:hover:text-primary-700">Sign up</a> - or <a href="{% url 'login' %}" class="inline-flex items-center font-medium text-primary-600 hover:text-primary-800 dark:text-primary-500 dark:hover:text-primary-700">Login!</a> + or <a href="{% url 'user_login' %}" class="inline-flex items-center font-medium text-primary-600 hover:text-primary-800 dark:text-primary-500 dark:hover:text-primary-700">Login!</a> Choose one of our exceptionally well priced payment offers and enjoy our service to it's fullest! </p> </div> diff --git a/myproject/myapp/urls.py b/myproject/myapp/urls.py index 304d047..a900d2e 100644 --- a/myproject/myapp/urls.py +++ b/myproject/myapp/urls.py @@ -22,5 +22,6 @@ urlpatterns = [ path('admin_table/', admin_table, name='admin_table'), path('instrument_detection/', InstrumentDetectionView.as_view(), name='instrument_detection'), path('password_change/', auth_views.PasswordChangeView.as_view(template_name='password_change_form.html'), name='password_change'), - path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(template_name='password_change_done.html'), name='password_change_done') + path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(template_name='password_change_done.html'), name='password_change_done'), + path('logout/', auth_views.LogoutView.as_view(next_page=index), name='logout') ] diff --git a/myproject/myapp/views.py b/myproject/myapp/views.py index b90b29a..f4b3cd1 100644 --- a/myproject/myapp/views.py +++ b/myproject/myapp/views.py @@ -104,18 +104,6 @@ def index(request): # Handle authenticated users if request.user.is_authenticated: - if request.method == 'POST': - # Assuming you want to do something specific with the file if it's uploaded - uploaded_file = request.FILES.get('audio_file') - if uploaded_file: - # Process the uploaded file as needed - pass - # For now, just render the main page again, potentially after handling the uploaded file - # For GET requests or if POST doesn't involve a file, just show the main page - return render(request, 'index1.html') - - # Handle unauthenticated users - else: if request.method == 'POST': form = InstrumentDetectionForm(request.POST, request.FILES) if form.is_valid() and 'audio_file' in request.FILES: @@ -130,7 +118,22 @@ def index(request): else: context['form'] = form # For GET requests or if form is not valid, render the page with the default or updated context - return render(request, 'index1.html', context) + return render(request, 'index1.html', context) + + # Handle unauthenticated users + else: + if request.method == 'POST': + # Assuming you want to do something specific with the file if it's uploaded + uploaded_file = request.FILES.get('audio_file') + if uploaded_file: + # Process the uploaded file as needed + pass + # For now, just render the main page again, potentially after handling the uploaded file + # For GET requests or if POST doesn't involve a file, just show the main page + return render(request, 'index2.html') + + + def users(request): @@ -270,3 +273,11 @@ class InstrumentDetectionView(APIView): formatted_scores = "<br>".join([f"{instruments[i]} - {score:.2f}" for i, score in enumerate(prediction)]) formatted_predictions.append(f"{formatted_window}{formatted_scores}") return formatted_predictions + + +def user_has_credits(): + has_credits = False + + + + return has_credits \ No newline at end of file -- GitLab