Skip to content

Commit

Permalink
#220 simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
rodja committed Jan 6, 2023
1 parent 3725591 commit c8ed67f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 54 deletions.
18 changes: 6 additions & 12 deletions nicegui/elements/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,30 @@

from fastapi import Request, Response

from ..dependencies import register_component
from ..element import Element
from ..events import UploadEventArguments, handle_event
from ..nicegui import app

register_component('upload', __file__, 'upload.vue')


class Upload(Element):

def __init__(self, *,
multiple: bool = False,
on_upload: Optional[Callable] = None,
file_picker_label: str = '',
label: str = '',
auto_upload: bool = False,
upload_button_icon: str = 'file_upload') -> None:
) -> None:
"""File Upload
:param multiple: allow uploading multiple files at once (default: `False`)
:param on_upload: callback to execute when for each file which is uploaded (type: nicegui.events.UploadEventArguments)
:param file_picker_label: label for the file picker element (default: `''`)
:param label: label for the file picker element (default: `''`)
:param auto_upload: automatically upload files when they are selected (default: `False`)
:param upload_button_icon: icon for the upload button
"""
super().__init__('upload')
self.classes('row items-center gap-2')
super().__init__('q-uploader')
self._props['multiple'] = multiple
self._props['file_picker_label'] = file_picker_label
self._props['auto_upload'] = auto_upload
self._props['upload_button_icon'] = upload_button_icon
self._props['label'] = label
self._props['auto-upload'] = auto_upload
self._props['url'] = f'/_nicegui/client/{self.client.id}/upload/{self.id}'

@app.post(f'/_nicegui/client/{self.client.id}/upload/{self.id}')
Expand Down
39 changes: 0 additions & 39 deletions nicegui/elements/upload.vue

This file was deleted.

6 changes: 3 additions & 3 deletions tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def handle_upload(event: events.UploadEventArguments):
nonlocal result
result = event

ui.upload(on_upload=handle_upload, file_picker_label='Test Title')
ui.upload(on_upload=handle_upload, label='Test Title')

screen.open('/')
screen.should_contain('Test Title')
Expand All @@ -41,8 +41,8 @@ def handle_upload2(event: events.UploadEventArguments):
nonlocal result2
result2 = event

ui.upload(on_upload=handle_upload1, auto_upload=True, file_picker_label='Test Title 1')
ui.upload(on_upload=handle_upload2, auto_upload=True, file_picker_label='Test Title 2')
ui.upload(on_upload=handle_upload1, auto_upload=True, label='Test Title 1')
ui.upload(on_upload=handle_upload2, auto_upload=True, label='Test Title 2')

screen.open('/')
screen.should_contain('Test Title 1')
Expand Down

0 comments on commit c8ed67f

Please sign in to comment.