Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
11 changes: 2 additions & 9 deletions bmds_ui/desktop/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,10 @@ def setup_django_environment(db: Database):
django.setup()


def _create_django_db(db):
"""Create a django database and sync persistent state with application."""
def create_django_db(db: Database):
log.info(f"Creating {db}")
setup_django_environment(db)
sync_persistent_data()


def create_django_db(config: DesktopConfig, db: Database):
log.info(f"Creating {db}")
thread = Thread(target=_create_django_db, args=(db,), daemon=True)
thread.start()
thread.join()
log.info(f"Creation successful {db}")


Expand Down
17 changes: 14 additions & 3 deletions bmds_ui/desktop/components/database_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any

from django.utils.text import slugify
from textual import on
from textual import on, work
from textual.app import ComposeResult
from textual.containers import Grid, Horizontal
from textual.reactive import reactive
Expand Down Expand Up @@ -138,6 +138,7 @@ def compose(self) -> ComposeResult:
Button("Cancel", variant="default", id="db-edit-cancel"),
delete_btn,
classes="btn-holder span4",
id="actions-row",
),
id="grid-db-form",
)
Expand All @@ -154,10 +155,17 @@ async def on_db_create(self) -> None:
db_path = (Path(path).expanduser().resolve() / db).absolute()
config = Config.get()
db = Database(name=name, description=description, path=db_path)
self._create_django_db(config, db)

@work(exclusive=True, thread=True)
def _create_django_db(self, config, db):
# sleeps are required for loading indicator to show/hide properly
self.app.call_from_thread(self.set_loading, True)
config.add_db(db)
Config.sync()
create_django_db(config, db)
self.dismiss(True)
create_django_db(db)
self.app.call_from_thread(self.set_loading, False)
self.app.call_from_thread(self.dismiss, True)

@on(Button.Pressed, "#db-update")
async def on_db_update(self) -> None:
Expand Down Expand Up @@ -193,3 +201,6 @@ async def on_db_delete(self) -> None:
@on(Button.Pressed, "#db-edit-cancel")
def on_db_create_cancel(self) -> None:
self.dismiss(False)

def set_loading(self, status: bool):
self.get_widget_by_id("actions-row").loading = status
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [

# desktop
"packaging~=24.0",
"textual~=0.62.0",
"textual~=0.72.0",
"whitenoise~=6.6.0",
]

Expand Down
8 changes: 7 additions & 1 deletion tests/desktop/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ async def test_db_form(self, rollback_get_app):
# create a new db
app.query_one("#path").value = resolved_temp_dir
await pilot.click("#db-create")
await pilot.pause()
# wait for db creation to finish or max of 60 seconds
max = 1
while max < 60 and isinstance(
app.screen, components.database_form.DatabaseFormModel
):
await pilot.pause(delay=1)
max += 1
assert app.screen.name == "main"

# make sure a new one appears on the list page
Expand Down