Skip to content

Commit

Permalink
adding first draft of a big part of the templates and handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
ooemperor committed Nov 20, 2023
1 parent 5d50c45 commit 837890c
Show file tree
Hide file tree
Showing 15 changed files with 488 additions and 9 deletions.
3 changes: 2 additions & 1 deletion codeGrader/backend/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def subject(id_: int):
elif request.method == 'DELETE':
return SubjectHandler().delete(id_)


@app.route("/subjects", methods=['GET'])
def subjects():
"""
Expand Down Expand Up @@ -300,7 +301,6 @@ def uploadFile():
return FileHandler().post(data)



@app.route("/file/<int:id_>", methods=["GET", "DELETE"])
def file(id_: int):
"""
Expand Down Expand Up @@ -388,6 +388,7 @@ def testcases():
"""
return TestCaseHandler().get_all()


@app.route("/adminTypes")
def admin_types():
"""
Expand Down
79 changes: 78 additions & 1 deletion codeGrader/frontend/admin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
from codeGrader.frontend.config import config
from codeGrader.frontend.admin import templates
from codeGrader.frontend.admin.handlers import AdminUserLoginHandler, AdminUserSessionHandler, SessionAdminUser, \
UserListHandler, UserHandler, HomeHandler, AdminUserListHandler, AdminUserHandler, ProfileListHandler, ProfileHandler
UserListHandler, UserHandler, HomeHandler, AdminUserListHandler, AdminUserHandler, ProfileListHandler, \
ProfileHandler, SubjectListHandler, SubjectHandler, TaskHandler, TaskListHandler, ExerciseHandler, \
ExerciseListHandler

app = Flask(config.adminAppName, template_folder=templates.__path__[0])

Expand Down Expand Up @@ -154,5 +156,80 @@ def profiles():
return ProfileListHandler(request).get()


@app.route("/subject/<int:id_>", methods=['GET', 'POST'])
@login_required
def subject(id_):
"""
Site to display a single subject
@param id_: The id of the subject
@type id_: int
@return: The rendered Subject site
"""
if request.method == 'GET':
return SubjectHandler(request).get(id_)
elif request.method == 'POST':
return SubjectHandler(request).post(id_)


@app.route("/subjects")
@login_required
def subjects():
"""
Site for a list of all the subjects
@return: The rendered Subjects site
"""
return SubjectListHandler(request).get()


@app.route("/exercise/<int:id_>", methods=['GET', 'POST'])
@login_required
def exercise(id_):
"""
Site to display a single exercise
@param id_: The id of the exercise
@type id_: int
@return: The rendered exercise site
"""
if request.method == 'GET':
return ExerciseHandler(request).get(id_)
elif request.method == 'POST':
return ExerciseHandler(request).post(id_)


@app.route("/exercises")
@login_required
def exercises():
"""
Site for a list of all the exercises
@return: The rendered exercises site
"""
return ExerciseListHandler(request).get()


@app.route("/task/<int:id_>", methods=['GET', 'POST'])
@login_required
def task(id_):
"""
Site to display a single task
@param id_: The id of the task
@type id_: int
@return: The rendered task site
"""
if request.method == 'GET':
return TaskHandler(request).get(id_)
elif request.method == 'POST':
return TaskHandler(request).post(id_)


@app.route("/tasks")
@login_required
def tasks():
"""
Site for a list of all the tasks
@return: The rendered tasks site
"""
return TaskListHandler(request).get()


if __name__ == "__main__":
app.run(port=config.adminPort)
68 changes: 68 additions & 0 deletions codeGrader/frontend/admin/handlers/Exercise.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Handlers for the rendering of exercise
@author: mkaiser
"""

import flask
from flask import request, render_template, redirect, url_for
from .Base import BaseHandler


class ExerciseListHandler(BaseHandler):
def __init(self, request: flask.Request):
"""
Constructor of the exerciseListHandler
Will Render the HTML Template for all the exercises.
"""
super().__init__(request)

def get(self):
"""
Renders the template for the exercises site.
@return: The rendered template
@rtype: HTML
"""
exercises = self.api.get("/exercises")
return render_template("exercises.html", **exercises)


class ExerciseHandler(BaseHandler):
"""
Handles the operation on a single exercise
"""

def __init__(self, request: flask.Request):
"""
Constructor of the exercise Handler
@param request: The request from the app route of flask
@type request: flask.Request
"""
super().__init__(request)

def get(self, id_: int):
"""
Get and render the page for a given exercise by its id
@param id_: The id of the exercise
@type id_: int
@return: The rendered page of the exercise
@rtype: HTML
"""
exercise = self.api.get(f"/exercise/{id_}")
return render_template("exercise.html", **exercise)

def post(self, id_: int):
"""
Handler for the update of an exercise
@param id_: The identifier of the exercise
@return:
"""
assert self.request.form is not None
exercise_data = dict()

exercise_data["name"] = self.get_value("name")
exercise_data["tag"] = self.get_value("tag")

# getting the data from the form provided in the request
self.api.put(f"/exercise/{id_}", body=exercise_data)

return redirect(url_for("exercise", id_=id_))
68 changes: 68 additions & 0 deletions codeGrader/frontend/admin/handlers/Subject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Handlers for the rendering of Subjects
@author: mkaiser
"""

import flask
from flask import request, render_template, redirect, url_for
from .Base import BaseHandler


class SubjectListHandler(BaseHandler):
def __init(self, request: flask.Request):
"""
Constructor of the SubjectListHandler
Will Render the HTML Template for all the subjects.
"""
super().__init__(request)

def get(self):
"""
Renders the template for the Subjects site.
@return: The rendered template
@rtype: HTML
"""
subjects = self.api.get("/subjects")
return render_template("subjects.html", **subjects)


class SubjectHandler(BaseHandler):
"""
Handles the operation on a single Subject
"""

def __init__(self, request: flask.Request):
"""
Constructor of the Subject Handler
@param request: The request from the app route of flask
@type request: flask.Request
"""
super().__init__(request)

def get(self, id_: int):
"""
Get and render the page for a given subject by its id
@param id_: The id of the subject
@type id_: int
@return: The rendered page of the subject
@rtype: HTML
"""
subject = self.api.get(f"/subject/{id_}")
return render_template("subject.html", **subject)

def post(self, id_: int):
"""
Handler for the update of a subject
@param id_: The identifier of the subject
@return:
"""
assert self.request.form is not None
subject_data = dict()

subject_data["name"] = self.get_value("name")
subject_data["tag"] = self.get_value("tag")

# getting the data from the form provided in the request
self.api.put(f"/subject/{id_}", body=subject_data)

return redirect(url_for("subject", id_=id_))
68 changes: 68 additions & 0 deletions codeGrader/frontend/admin/handlers/Task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Handlers for the rendering of Task
@author: mkaiser
"""

import flask
from flask import request, render_template, redirect, url_for
from .Base import BaseHandler


class TaskListHandler(BaseHandler):
def __init(self, request: flask.Request):
"""
Constructor of the TaskListHandler
Will Render the HTML Template for all the tasks.
"""
super().__init__(request)

def get(self):
"""
Renders the template for the tasks site.
@return: The rendered template
@rtype: HTML
"""
tasks = self.api.get("/tasks")
return render_template("tasks.html", **tasks)


class TaskHandler(BaseHandler):
"""
Handles the operation on a single task
"""

def __init__(self, request: flask.Request):
"""
Constructor of the task Handler
@param request: The request from the app route of flask
@type request: flask.Request
"""
super().__init__(request)

def get(self, id_: int):
"""
Get and render the page for a given task by its id
@param id_: The id of the task
@type id_: int
@return: The rendered page of the task
@rtype: HTML
"""
task = self.api.get(f"/task/{id_}")
return render_template("task.html", **task)

def post(self, id_: int):
"""
Handler for the update of a task
@param id_: The identifier of the task
@return:
"""
assert self.request.form is not None
task_data = dict()

task_data["name"] = self.get_value("name")
task_data["tag"] = self.get_value("tag")

# getting the data from the form provided in the request
self.api.put(f"/task/{id_}", body=task_data)

return redirect(url_for("task", id_=id_))
7 changes: 6 additions & 1 deletion codeGrader/frontend/admin/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
from .Home import HomeHandler
from .AdminUser import AdminUserListHandler, AdminUserHandler
from .Profile import ProfileHandler, ProfileListHandler
from .Subject import SubjectHandler, SubjectListHandler
from .Task import TaskHandler, TaskListHandler
from .Exercise import ExerciseHandler, ExerciseListHandler

__all__ = ["AdminUserLoginHandler", "AdminUserSessionHandler", "SessionAdminUser", "UserListHandler", "UserHandler",
"HomeHandler", "AdminUserHandler", "AdminUserListHandler", "ProfileListHandler", "ProfileHandler"]
"HomeHandler", "AdminUserHandler", "AdminUserListHandler", "ProfileListHandler", "ProfileHandler",
"SubjectListHandler", "SubjectHandler", "ExerciseListHandler", "ExerciseHandler", "TaskHandler",
"TaskListHandler"]
2 changes: 1 addition & 1 deletion codeGrader/frontend/admin/templates/adminUser.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h1 class="header1 core_content">Admin User {{ username }}</h1>
<p class="core_content">Admin User {{ username }}</p>

<form action="{{url_for('adminUser', id_ = id)}}" method="POST" class="core_content">
<div id="user_data">
<div id="admin_user_data">
<table class="vertical_table">
<tr>
<td class="data">Username</td>
Expand Down
6 changes: 3 additions & 3 deletions codeGrader/frontend/admin/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
<a href="{{ url_for('adminUsers') }}">Admins</a>
<a href="{{ url_for('users') }}">Users</a>
<a href="{{ url_for('profiles') }}">Profiles</a>
<a href="#">Subjects</a>
<a href="#">Exercises</a>
<a href="#">Tasks</a>
<a href="{{ url_for('subjects') }}">Subjects</a>
<a href="{{ url_for('exercises') }}">Exercises</a>
<a href="{{ url_for('tasks') }}">Tasks</a>
<br>
<div>
<a href="{{ url_for('logout') }}" class="btn_logout" >
Expand Down
34 changes: 34 additions & 0 deletions codeGrader/frontend/admin/templates/exercise.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends "base.html" %}

{% block core %}
<!-- Add all page content inside this div if you want the side nav to push page content to the right (not used if you only want the sidenav to sit on top of the page -->
<div id="main" class="main">
<span id="main-menu-button" class="btn-menu" onclick="openNav()">&equiv;</span>
<div>
<h1 class="header1 core_content">Exercise {{ name }}</h1>
</div>
<p class="core_content">Exercise {{ name }}</p>

<form action="{{url_for('exercise', id_ = id)}}" method="POST" class="core_content">
<div id="exercise_data">
<table class="vertical_table">
<tr>
<td class="data">Name</td>
<td class="data">
<input type="text" id="input_name" name="name" value="{{ name }}">
</td>
</tr>
<tr>
<td class="data">Tag</td>
<td class="data">
<input type="text" id="input_tag" name="tag" value="{{ tag }}">
</td>
</tr>
</table>
</div>
<div id="control_buttons">
<button id="btn_submit" class="btn_submit" type="submit">Submit</button>
</div>
</form>
</div>
{% endblock core %}
Loading

0 comments on commit 837890c

Please sign in to comment.