Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor 0.3.0 #18

Merged
merged 19 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2xauthoring/app/handlers/apihandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from nbgrader.server_extensions.formgrader.base import check_xsrf
from tornado import web

from ...git import get_author, set_author
from ...managers import (
AssignmentManager,
PresetManager,
Expand All @@ -14,7 +15,6 @@
TemplateManager,
WorksheetManager,
)
from ...utils.gitutils import get_author, set_author
from .base import ApiManageHandler


Expand Down
10 changes: 5 additions & 5 deletions e2xauthoring/app/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from nbgrader.server_extensions.formgrader.base import check_xsrf
from tornado import web

from e2xauthoring.managers.dataclasses import ErrorMessage, SuccessMessage
from ...dataclasses import ErrorMessage, SuccessMessage


def status_msg(method):
Expand Down Expand Up @@ -103,22 +103,22 @@ async def handle_request(self, request_type: str):
@check_xsrf
async def get(self):
result = await self.handle_request("get")
self.finish(result.json())
self.finish(result.to_json())

@web.authenticated
@check_xsrf
async def delete(self):
result = await self.handle_request("delete")
self.finish(result.json())
self.finish(result.to_json())

@web.authenticated
@check_xsrf
async def put(self):
result = await self.handle_request("put")
self.finish(result.json())
self.finish(result.to_json())

@web.authenticated
@check_xsrf
async def post(self):
result = await self.handle_request("post")
self.finish(result.json())
self.finish(result.to_json())
18 changes: 18 additions & 0 deletions e2xauthoring/dataclasses/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from .gitstatus import GitStatus
from .jsondataclass import JSONDataClass
from .messages import ErrorMessage, SuccessMessage
from .pool import PoolCollectionRecord, PoolRecord
from .task import TaskRecord
from .template import TemplateCollectionRecord, TemplateRecord

__all__ = [
"ErrorMessage",
"GitStatus",
"JSONDataClass",
"TaskRecord",
"PoolRecord",
"PoolCollectionRecord",
"SuccessMessage",
"TemplateRecord",
"TemplateCollectionRecord",
]
12 changes: 12 additions & 0 deletions e2xauthoring/dataclasses/gitstatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dataclasses import dataclass, field
from typing import List, Optional

from .jsondataclass import JSONDataClass


@dataclass
class GitStatus(JSONDataClass):
untracked: Optional[List[str]] = field(default_factory=list)
unstaged: Optional[List[str]] = field(default_factory=list)
staged: Optional[List[str]] = field(default_factory=list)
status: Optional[str] = None
7 changes: 7 additions & 0 deletions e2xauthoring/dataclasses/jsondataclass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from dataclasses import asdict, dataclass


@dataclass
class JSONDataClass:
def to_json(self):
return asdict(self)
17 changes: 17 additions & 0 deletions e2xauthoring/dataclasses/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from dataclasses import dataclass
from typing import Any

from .jsondataclass import JSONDataClass


@dataclass
class SuccessMessage(JSONDataClass):
success: bool = True
message: str = ""
data: Any = None


@dataclass
class ErrorMessage(JSONDataClass):
success: bool = False
error: str = ""
19 changes: 19 additions & 0 deletions e2xauthoring/dataclasses/pool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from dataclasses import dataclass, field
from typing import List

from .jsondataclass import JSONDataClass
from .task import TaskRecord


@dataclass
class PoolRecord(JSONDataClass):
name: str
base_path: str
n_tasks: int = 0
tasks: List[TaskRecord] = field(default_factory=list)
is_repo: bool = False


@dataclass
class PoolCollectionRecord(JSONDataClass):
pools: List[PoolRecord] = field(default_factory=list)
13 changes: 13 additions & 0 deletions e2xauthoring/dataclasses/task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from dataclasses import dataclass

from .gitstatus import GitStatus
from .jsondataclass import JSONDataClass


@dataclass
class TaskRecord(JSONDataClass):
name: str
pool: str
points: int
n_questions: int
git_status: GitStatus
15 changes: 15 additions & 0 deletions e2xauthoring/dataclasses/template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from dataclasses import dataclass, field
from typing import List

from .jsondataclass import JSONDataClass


@dataclass
class TemplateRecord(JSONDataClass):
name: str
variables: List[str]


@dataclass
class TemplateCollectionRecord(JSONDataClass):
templates: List[TemplateRecord] = field(default_factory=list)
6 changes: 6 additions & 0 deletions e2xauthoring/git/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .base import BaseRepo
from .factory import GitRepoFactory
from .gitrepo import GitRepo
from .utils import get_author, set_author

__all__ = ["BaseRepo", "GitRepo", "GitRepoFactory", "get_author", "set_author"]
Loading
Loading