Last active
November 12, 2020 10:33
-
-
Save GuillaumeDerval/b31c8ed2ef84c3ba6a27626c9360197f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from typing import List | |
import abc | |
from inginious.frontend.plugin_manager import PluginManager | |
class SubmissionReader: | |
class __Button: | |
def __init__(self, submission_reader: "SubmissionReader", name: str, prio: int): | |
""" | |
:param submission_reader: | |
:param name: a unique (inside this SubmissionReader) id (that should remain the same over restarts) to this button. Must only contain alphanumerical characters [a-z0-9A-Z_\-]. | |
:param prio: priority. lower is displayed first. | |
""" | |
assert re.match('^[a-z0-9A-Z_\-]+$', name) | |
self._submission_reader = submission_reader | |
self._name = name | |
self._prio = prio | |
@property | |
def prio(self): | |
return self._prio | |
class TopButton(__Button, abc.ABC): | |
def __init__(self, submission_reader: "SubmissionReader", name: str, prio: int): | |
super(SubmissionReader.TopButton, self).__init__(submission_reader, name, prio) | |
@abc.abstractmethod | |
def render(self, name) -> str: | |
""" | |
Renders the button and returns its HTML content | |
:param name: the name (the html property) the button should have for the form to work. | |
:return: the html for the button. | |
""" | |
pass | |
@abc.abstractmethod | |
def process(self, submissions: List[dict]) -> str: | |
""" | |
Process the submission list and return a web page. | |
:param submissions: list of submissions to process | |
:return: the message to be displayed in the submission search form as a result. You can also raise a | |
web.Redirect exception to redirect the user somewhere else. | |
""" | |
pass | |
class SubmissionButton(__Button, abc.ABC): | |
def __init__(self, submission_reader: "SubmissionReader", name: str, prio: int): | |
super(SubmissionReader.SubmissionButton, self).__init__(submission_reader, name, prio) | |
@abc.abstractmethod | |
def render(self, link) -> str: | |
""" | |
Renders the button and returns its HTML content | |
:param name: the link the button should point to. | |
:return: the html for the button. | |
""" | |
pass | |
@abc.abstractmethod | |
def process(self, submissions: dict) -> str: | |
""" | |
Process the submission and return a web page. | |
:param submission: the submission to process | |
:return: the message to be displayed in the submission search form as a result. You can also raise a | |
web.Redirect exception to redirect the user somewhere else. | |
""" | |
pass | |
def __init__(self, name: str, plugin_manager: PluginManager): | |
""" | |
Create a SubmissionReader | |
:param name: a unique id (that should remain the same over restarts) to this SubmissionReader. Must only contain alphanumerical characters [a-z0-9A-Z_\-]. | |
:param plugin_manager: | |
""" | |
assert re.match('^[a-z0-9A-Z_\-]+$', name) | |
self._name = name | |
plugin_manager.add_hook("submission_readers", lambda l: l.append(self)) | |
@property | |
def top_buttons(self) -> List[TopButton]: | |
""" | |
Returns a list of SubmissionReader.TopButton. These buttons will be shown above the submission list, | |
and should point to actions that affect the whole selection of submissions. | |
""" | |
return [] | |
@property | |
def submission_buttons(self) -> List[SubmissionButton]: | |
""" | |
Returns a list of SubmissionReader.SubmissionButton. | |
These buttons will be shown at the right part of each submission | |
and should point to actions that affect the whole selection of submissions. | |
""" | |
return [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment