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

feat: extend File.write() to accept a rootnode and foldername #1308

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

bb-mausbrand
Copy link
Contributor

feat: extend the write()-method of File to accept a rootnode and foldername

@phorward phorward changed the title feat: extend the write()-method of File to accept a rootnode and foldername feat: extend File.write() to accept a rootnode and foldername Oct 30, 2024
src/viur/core/modules/file.py Outdated Show resolved Hide resolved
src/viur/core/modules/file.py Show resolved Hide resolved
@sveneberth sveneberth added feature New feature or request Priority: Medium This issue may be useful, and needs some attention. labels Oct 30, 2024
Copy link
Member

@phorward phorward left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good already, mostly some cosmetics.

rootnode = self.ensureOwnModuleRootNode()
elif not foldername:
# if rootnode is set and foldername is not, save the file in the root of the rootnode
foldername = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like tuples ;)

Suggested change
foldername = []
foldername = ()

if foldername is not None:
foldernames = foldername
if isinstance(foldername, str):
foldernames = foldernames.replace('\\', '/')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should handle this case. What do the others think? @sveneberth?

foldernames = foldername
if isinstance(foldername, str):
foldernames = foldernames.replace('\\', '/')
foldernames = (i for i in foldernames.split('/'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
foldernames = (i for i in foldernames.split('/'))
foldernames = foldernames.split("/")

if isinstance(foldername, str):
foldernames = foldernames.replace('\\', '/')
foldernames = (i for i in foldernames.split('/'))
foldernames = (i for i in foldernames if i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
foldernames = (i for i in foldernames if i)
foldernames = tuple(foldernames) # ensure tuple, run any iterators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request Priority: Medium This issue may be useful, and needs some attention.
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

Extend File.write() to optionally write files to specific folders
4 participants