diff --git a/prediction_service/__pycache__/views.cpython-310.pyc b/prediction_service/__pycache__/views.cpython-310.pyc index e773b4cf329949ded3792bd435c8f73da9ce5895..e0c1dfb4935d4d1280f68d0091410579733f81cb 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/templates/prediction_service/home-Admin.html b/prediction_service/templates/prediction_service/home-Admin.html new file mode 100644 index 0000000000000000000000000000000000000000..2d5671c3214ab61568ec1aade6a88e9357e3b9b9 --- /dev/null +++ b/prediction_service/templates/prediction_service/home-Admin.html @@ -0,0 +1,54 @@ +{% include "prediction_service/base.html" %} +{% include "prediction_service/navbar.html" %} + +{% block content %} + + <br> + + <div class="container"> + <h1>Admin Dashboard!</h1> + <div class="row col-sm-12"> + {% for post in posts %} + <div class="card" style="width: 18rem; margin-right: 15px;"> + <div class="card-body"> + <h5 class="card-title">{{post.title}} ID: {{post.mlmodel.id}}</h5> + <h6 class="card-subtitle mb-2 text-muted">By {{ post.author }} on {{ post.date_posted }}</h6> + <p class="card-text">{{ post.content }}</p> + <a href="/mlmodel/{{post.mlmodel.id}}" class="card-link">Ml-Model</a> + <a href="#" class="card-link">Inspect Model</a> + </div> + </div> + {% endfor %} + + <form method="POST" action="/home/"> + {% csrf_token %} + {% for account in pending %} + <div class="card" style="width: 18rem; margin-right: 15px;"> + <div class="card-body"> + <h5 class="card-title">Username: {{ account.user.user }}</h5> + <h6 class="card-subtitle mb-2 text-muted">AI Engineer Request</h6> + <label class="checkbox-label" for="approve-checkbox-{{ account.user }}">Approve</label> + <input type="checkbox" id="{{ account.user }}" name="approved_accounts" value="{{ account.user.id }}"> + </div> + </div> + {% endfor %} + <button type="submit" class="btn btn-primary">Submit</button> + </form> + + + </div> + + + </div> + + <!-- Square plus button --> + <div style="position: fixed; bottom: 20px; right: 20px;"> + <a href="{% url 'MLAAS-create_post' %}"> + <button style="width: 50px; height: 50px; border-radius: 50%; background-color: #007bff; color: white; font-size: 24px; border: none;">+</button> + </a> + </div> + + + + +{% endblock content %} \ No newline at end of file diff --git a/prediction_service/views.py b/prediction_service/views.py index 53d04fa815057fe0bceb080202906ca3c1b065c0..0e636cbf804e459fac6cc61da3cd5b6f6e1fa4fa 100644 --- a/prediction_service/views.py +++ b/prediction_service/views.py @@ -32,10 +32,34 @@ def home(request): return render(request, 'prediction_service/home.html',context) else: return render(request, 'prediction_service/home-AI.html',context) + elif user.userprofile.role == "Administrator": + # to do: + # 1. we need to get all AI Engineer table data + # 2. filter all the rows that have approved as false + pending_engineers = AIEngineer.objects.filter(is_authorized=False) + # 3. pass them into the context of the page + # 3.1 - use html majix to list them out (Like how posts are) + context['pending'] = pending_engineers + # 4. we need a form for them to submit with the approved selections + # 4.1 - therefore we need a view for handaling the process for changing the status to approved + return render(request, 'prediction_service/home-Admin.html',context) else: # if the account is not an AI Engineer return render(request, 'prediction_service/home.html',context) - + elif request.user.is_authenticated and request.method == "POST": + approved_accounts = request.POST.getlist('approved_accounts') + + for account in approved_accounts: + # Process each approved account ID + ai_engineer = AIEngineer.objects.get(user=account) + + ai_engineer.is_authorized = True + + ai_engineer.save() + + messages.success(request, f'{ai_engineer.user.user} approved as AI Engineer!') + + return redirect('MLAAS-home') else: return HttpResponse("<h1> you are not authenticated but are logged in? </h1>")