IEEE.org     |     IEEE Xplore Digital Library     |     IEEE Standards     |     IEEE Spectrum     |     More Sites

Verified Commit 44453071 authored by Emi Simpson's avatar Emi Simpson
Browse files

[new arch] Doc outcomes

parent 390c19ef
......@@ -6,28 +6,43 @@ from typing import Any, Collection, Mapping, NamedTuple, NewType, Tuple, TypeAli
@unique
class SignupFieldKind(Enum):
"""
Designates a field kind used in the signup form
"""
Username = "username"
Password = "password"
Name = "name"
Email = "email"
class SignupField(NamedTuple):
"""
Designates a specific field in the signup form
"""
field: SignupFieldKind
def __str__(self):
return f"signup-{self.field.value}"
@unique
class LoginFieldKind(Enum):
"""
Designates a field kind used in the login form
"""
Username = "username"
Password = "password"
class LoginField(NamedTuple):
"""
Designates a specific field in the login form
"""
field: LoginFieldKind
def __str__(self):
return f"login-{self.field.value}"
@unique
class ProjectFieldKind(Enum):
"""
Designates a field kind used in the project form
"""
AddSource = "add_source"
AddOwner = "add_owner"
ProjectName = "project-name"
......@@ -36,37 +51,77 @@ class ProjectFieldKind(Enum):
Generic = "generic"
class ProjectField(NamedTuple):
"""
Designates a specific field a the project form
"""
pid: UncheckedPID
field: ProjectFieldKind
def __str__(self):
return f"{compute_alphaid(self.pid)}-{self.field.value}"
class GenericAlert(NamedTuple):
"""
Used to indicate that an alert is generic, and does not apply to a specific form
"""
pass
Field: TypeAlias = Union[GenericAlert, ProjectField, LoginField, SignupField]
"""
A generalization over the types of fields
"""
Backend = NewType('Backend', str)
"""
A `str`-like field exclusively for backends
"""
Url = NewType('Url', str)
"""
A `str`-like field exclusively for URLs
"""
class ForceLogin:
"""
An outcome that designates that the user should be redirected to the login page
"""
pass
class Logout:
"""
An outcome that designates that the user should be logged out
"""
pass
class RebuildProjectsJson:
"""
Designates that projects.json should be overwritten with data from the database
"""
pass
class Error(NamedTuple):
"""
Designates that an error should be shown, related to this specific field
"""
component: Field
message: str
def to_tuple(self) -> Tuple[str, str]:
"""
The "category" to set the error to in flask
This is later parsed to determine where the error should be shown
"""
return (self.message, f"error-{self.component}")
class AmendSession(NamedTuple):
new_values: Mapping[str, Any]
"""
Designates that the provided key-value mappings should be applied ontop the session
"""
new_values: Mapping[str, Any]
class SubmitCoordinatorJob(NamedTuple):
tags: Collection[str]
desc: str
priority: int
backends: Mapping[Backend, Collection[Url]]
"""
Indicates that the described job should be sent to the coordinator
See also: :meth:`mystic.coordinator.CoordinatorConnection.post_job()`
"""
tags: Collection[str]
desc: str
priority: int
backends: Mapping[Backend, Collection[Url]]
Outcome: TypeAlias \
= ForceLogin \
......@@ -75,5 +130,11 @@ Outcome: TypeAlias \
| SubmitCoordinatorJob \
| AmendSession \
| Error
"""
A type for all possible outcomes
"""
Outcomes: TypeAlias = Collection[Outcome]
"""
One or more :class:`Outcome`s
"""
......@@ -9,6 +9,11 @@ from pymysql.cursors import Cursor
from werkzeug.wrappers.response import Response
def run_outcomes(outcomes: Outcomes, cursor: Cursor) -> Optional[Response]:
"""
Take action based on a series of outcomes
The return value is an optional response override used for things like redirects
"""
default_response: Optional[Response] = None
for outcome in outcomes:
if isinstance(outcome, Error):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment