diff --git a/prediction_service/__pycache__/views.cpython-310.pyc b/prediction_service/__pycache__/views.cpython-310.pyc index 3be609cd08366637ea0675e461f00e21595e7ef4..be1d08de5a1c486bcfddb4c9560e6468db467560 100644 Binary files a/prediction_service/__pycache__/views.cpython-310.pyc and b/prediction_service/__pycache__/views.cpython-310.pyc differ diff --git a/prediction_service/views.py b/prediction_service/views.py index caf75993920ce173bd0233f1c9467dd7d79140af..7f5d93a853d3de9f5d2743720d5959ba9c867f95 100644 --- a/prediction_service/views.py +++ b/prediction_service/views.py @@ -15,34 +15,36 @@ from django.contrib.auth.models import User @login_required def home(request): + if request.user.is_authenticated and request.method == "GET": - context = { - 'posts':'', - } - - context['posts'] = Post.objects.all()#loads all posts from Post table into the context + context = {'posts':'',} - return render(request, 'prediction_service/home.html',context) + context['posts'] = Post.objects.all() #loads all posts from Post table into the context -@login_required -def homeAI(request): - if request.user.is_authenticated and request.method == "GET": user = request.user - #try: - if user.userprofile.role == 'AI Engineer': - context = {'posts':'',} - - context['posts'] = Post.objects.all()#loads all posts from Post table into the context - return render(request, 'prediction_service/home-AI.html',context) + # if account is an AI Engineer + if user.userprofile.role == 'AI Engineer': + # if the ai engineer is approved, then send them to the AI dashboard + ai_engineer = AIEngineer.objects.get(user=user.userprofile) + if not ai_engineer.is_authorized: + messages.error(request, 'You are not authorized to access the AI Dashboard system. Please wait for admin authorization.') + return render(request, 'prediction_service/home.html',context) + else: + return render(request, 'prediction_service/home-AI.html',context) + else: - return HttpResponse(f"<h1> You are logged in and not an AI engineer! you are a {user.userprofile.role}</h1>") - # except: - # return HttpResponse("<h1> youre in the except for some reason </h1>") + # if the account is not an AI Engineer + return render(request, 'prediction_service/home.html',context) else: return HttpResponse("<h1> you are not authenticated but are logged in? </h1>") +@login_required +def homeAI(request): + + pass + def about(request): @@ -92,18 +94,8 @@ def MLAAS_login(request): user = authenticate(request, username=username, password=password) if user is not None: - try: - if user.userprofile.role == 'AI Engineer': - ai_engineer = AIEngineer.objects.get(user=user.userprofile) - if not ai_engineer.is_authorized: - messages.error(request, 'You are not authorized to access the MLaaS system. Please wait for admin authorization.') - return redirect('MLAAS-login') # Redirect to login page - - login(request, user) - return redirect('MLAAS-home') - except: - messages.error(request, 'user has no userprofile.') - return redirect('MLAAS-login') # Redirect to login + login(request, user) + return redirect('MLAAS-home') else: messages.error(request, 'Invalid username or password.')