Skip to content

Commit

Permalink
simplify form page
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-oleshkevich committed Jan 2, 2024
1 parent 4fb7511 commit d9aed0e
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 31 deletions.
3 changes: 1 addition & 2 deletions issues.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# FEATURES
1. implement relations
2. add display_view: autoview that accepts list[DisplayView] and BuilderView to build custom layouts
* display view can be templates
5. add profile settings (change name, reset password)
6. permissions & access control
7. improve ui
Expand All @@ -16,5 +14,6 @@
16. actions should have static urls - pass route name and path prefix via args
17. add image display and form component
18. simplify datasource -> django-like?
19. implement table component and use in TableView. just like display view

# BUGS
1 change: 0 additions & 1 deletion ohmyadmin/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ class ResourceScreen(Screen):
create_form_actions: typing.Sequence[actions.Action] | None = None

# display page
# display_layout_class: type[ohmyadmin.components.DisplayLayoutBuilder] = ohmyadmin.components.AutoDisplayLayout
display_object_actions: typing.Sequence[actions.Action] = tuple()
display_view: DisplayView | None = None

Expand Down
2 changes: 1 addition & 1 deletion ohmyadmin/screens/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_route(self) -> BaseRoute:
return Mount(
"",
routes=[
Route(path="/", endpoint=self.dispatch, name=self.url_name),
Route(path="/", endpoint=self.dispatch, name=self.url_name, methods=["get", "post"]),
Mount("/actions", routes=self.get_action_routes()),
Mount("/metrics", routes=self.get_metrics_routes()),
],
Expand Down
32 changes: 5 additions & 27 deletions ohmyadmin/screens/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
import typing

import wtforms
from starlette.middleware import Middleware
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import BaseRoute, Mount, Route

from ohmyadmin.actions import actions
from ohmyadmin.components import AutoFormLayout, FormLayoutBuilder
from ohmyadmin.forms.utils import create_form, validate_on_submit
from ohmyadmin.templating import render_to_response
from ohmyadmin.screens.base import ExposeViewMiddleware, Screen
from ohmyadmin.screens.base import Screen


class FormScreen(Screen):
form_class: typing.Type[wtforms.Form] = wtforms.Form
layout_class: typing.Type[FormLayoutBuilder] = AutoFormLayout
form_actions: typing.Sequence[actions.Action] | None = None
form_actions: typing.Sequence[actions.Action] = tuple()
template = "ohmyadmin/screens/form/page.html"

async def init_form(self, request: Request, form: wtforms.Form) -> None:
Expand All @@ -27,7 +25,7 @@ async def get_object(self, request: Request) -> typing.Any:
return None

def get_form_actions(self) -> typing.Sequence[actions.Action]:
return self.form_actions or []
return self.form_actions

@abc.abstractmethod
async def handle(self, request: Request, form: wtforms.Form, instance: typing.Any) -> Response:
Expand All @@ -54,25 +52,5 @@ async def dispatch(self, request: Request) -> Response:
},
)

def get_route(self) -> BaseRoute:
return Mount(
"/",
routes=[
Route("/", self.dispatch, name=self.url_name, methods=["get", "post"]),
Mount(
"/actions",
routes=[
Route(
"/" + action.slug, action, name=self.get_action_route_name(action), methods=["get", "post"]
)
for action in self.get_form_actions()
],
middleware=[
Middleware(ExposeViewMiddleware, screen=self),
],
),
],
)

def get_action_route_name(self, action: actions.Action) -> str:
return f"{self.url_name}.actions.{action.slug}"
def get_action_handlers(self) -> typing.Sequence[actions.Action]:
return [*super().get_action_handlers(), *self.get_form_actions()]

0 comments on commit d9aed0e

Please sign in to comment.