endpoints
This commit is contained in:
parent
07a04af473
commit
255a364c34
@ -7,6 +7,7 @@ from SprintLib.utils import delete_file, write_bytes
|
||||
class AccountView(BaseView):
|
||||
view_file = "account.html"
|
||||
required_login = True
|
||||
endpoint = "account"
|
||||
|
||||
def get(self):
|
||||
if "username" in self.request.GET.keys():
|
||||
|
@ -4,3 +4,4 @@ from SprintLib.BaseView import BaseView
|
||||
class EnterView(BaseView):
|
||||
view_file = "enter.html"
|
||||
required_login = False
|
||||
endpoint = "enter"
|
||||
|
@ -5,6 +5,7 @@ from SprintLib.BaseView import BaseView
|
||||
|
||||
class ExitView(BaseView):
|
||||
required_login = True
|
||||
endpoint = "exit"
|
||||
|
||||
def get(self):
|
||||
logout(self.request)
|
||||
|
@ -5,5 +5,6 @@ from SprintLib.utils import get_bytes
|
||||
|
||||
|
||||
class ImageView(BaseView):
|
||||
endpoint = "image"
|
||||
def get(self):
|
||||
return HttpResponse(get_bytes(int(self.request.GET['id'])), content_type="image/jpg")
|
||||
|
@ -4,3 +4,4 @@ from SprintLib.BaseView import BaseView
|
||||
class MainView(BaseView):
|
||||
view_file = "main.html"
|
||||
required_login = True
|
||||
endpoint = ""
|
||||
|
@ -6,6 +6,7 @@ from SprintLib.BaseView import BaseView
|
||||
class RatingView(BaseView):
|
||||
view_file = "rating.html"
|
||||
required_login = True
|
||||
endpoint = "rating"
|
||||
|
||||
def get(self):
|
||||
self.context["users"] = User.objects.filter(userinfo__verified=True).order_by(
|
||||
|
@ -7,6 +7,7 @@ from random import randrange
|
||||
|
||||
|
||||
class SendCodeView(BaseView):
|
||||
endpoint = "send_code"
|
||||
def post_create(self):
|
||||
username = self.request.POST["username"]
|
||||
user = User.objects.filter(username=username).first()
|
||||
|
@ -4,3 +4,4 @@ from SprintLib.BaseView import BaseView
|
||||
class SetSettingsView(BaseView):
|
||||
required_login = True
|
||||
view_file = 'set_settings.html'
|
||||
endpoint = "admin/set"
|
@ -5,6 +5,7 @@ from SprintLib.BaseView import BaseView
|
||||
class SetsView(BaseView):
|
||||
view_file = "sets.html"
|
||||
required_login = True
|
||||
endpoint = "sets"
|
||||
|
||||
def post(self):
|
||||
set_name = self.request.POST["name"]
|
||||
|
@ -4,6 +4,7 @@ from SprintLib.BaseView import BaseView, AccessError
|
||||
class SolutionView(BaseView):
|
||||
view_file = 'solution.html'
|
||||
required_login = True
|
||||
endpoint = "solution"
|
||||
|
||||
def pre_handle(self):
|
||||
if self.request.user.is_superuser:
|
||||
|
@ -8,6 +8,7 @@ from SprintLib.BaseView import BaseView
|
||||
class SolutionsTableView(BaseView):
|
||||
view_file = 'solutions_table.html'
|
||||
required_login = True
|
||||
endpoint = "solutions_table"
|
||||
|
||||
def get(self):
|
||||
self.context['solutions'] = Solution.objects.filter(
|
||||
|
@ -7,6 +7,7 @@ from SprintLib.BaseView import BaseView
|
||||
class TaskRuntimeView(BaseView):
|
||||
view_file = 'task_runtime.html'
|
||||
required_login = True
|
||||
endpoint = "task_runtime"
|
||||
|
||||
def get(self):
|
||||
progress = Progress.objects.get(task=self.entities.task, user=self.request.user)
|
||||
|
@ -8,6 +8,7 @@ from SprintLib.BaseView import BaseView, AccessError
|
||||
class TaskSettingsView(BaseView):
|
||||
view_file = "task_settings.html"
|
||||
required_login = True
|
||||
endpoint = "admin/task"
|
||||
|
||||
def pre_handle(self):
|
||||
if self.entities.task not in self.request.user.userinfo.available_tasks:
|
||||
|
@ -10,6 +10,7 @@ from SprintLib.utils import write_bytes
|
||||
class TaskView(BaseView):
|
||||
required_login = True
|
||||
view_file = "task.html"
|
||||
endpoint = "task"
|
||||
|
||||
def get(self):
|
||||
progress, _ = Progress.objects.get_or_create(
|
||||
|
@ -5,6 +5,7 @@ from SprintLib.BaseView import BaseView
|
||||
class TasksView(BaseView):
|
||||
view_file = "tasks.html"
|
||||
required_login = True
|
||||
endpoint = "tasks"
|
||||
|
||||
def post(self):
|
||||
task_name = self.request.POST["name"]
|
||||
|
@ -1,23 +1,15 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
|
||||
import Main.views
|
||||
from Main.views import *
|
||||
|
||||
urlpatterns = [
|
||||
path("enter", EnterView.as_view()),
|
||||
path("rating", RatingView.as_view()),
|
||||
path("tasks", TasksView.as_view()),
|
||||
path("account", AccountView.as_view()),
|
||||
path("exit", ExitView.as_view()),
|
||||
path("admin/task", TaskSettingsView.as_view()),
|
||||
path("admin/set", SetSettingsView.as_view()),
|
||||
path("sets", SetsView.as_view()),
|
||||
path("task", TaskView.as_view()),
|
||||
path("solution", SolutionView.as_view()),
|
||||
path("solutions_table", SolutionsTableView.as_view()),
|
||||
path("task_runtime", TaskRuntimeView.as_view()),
|
||||
path("image", ImageView.as_view()),
|
||||
path("send_code", SendCodeView.as_view()),
|
||||
path("", MainView.as_view()),
|
||||
path("admin/", admin.site.urls),
|
||||
]
|
||||
urlpatterns = [path("admin/", admin.site.urls)]
|
||||
|
||||
for v in dir(Main.views):
|
||||
try:
|
||||
view = eval(v)
|
||||
except NameError:
|
||||
continue
|
||||
if hasattr(view, 'endpoint') and view.endpoint is not None:
|
||||
urlpatterns.append(path(view.endpoint, view.as_view()))
|
||||
|
@ -19,6 +19,7 @@ class BaseView:
|
||||
entities = EntityStorage()
|
||||
required_login: Optional[bool] = None
|
||||
view_file: Optional[str] = None
|
||||
endpoint: Optional[str] = None
|
||||
|
||||
@classmethod
|
||||
def as_view(cls):
|
||||
|
Loading…
Reference in New Issue
Block a user