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: add utils for creating files #487

Merged
merged 6 commits into from
Mar 15, 2024
Merged

feat: add utils for creating files #487

merged 6 commits into from
Mar 15, 2024

Conversation

Yelinz
Copy link
Member

@Yelinz Yelinz commented Mar 13, 2024

avoids forgetting to set encryption_status

@Yelinz Yelinz requested review from winged and anehx March 13, 2024 09:12
avoids forgetting to set encryption_status
Copy link
Contributor

@winged winged left a comment

Choose a reason for hiding this comment

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

Code LGTM, but a few things to note:

  • Rename the utils.py to api.py (similar to Caluma, where the public python API is also in an api module)
  • Add some docstrings to explain what the functions do
  • Add some documentation (README.md or create a new file PYTHON_API.md or similar)

Copy link
Contributor

@winged winged left a comment

Choose a reason for hiding this comment

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

Thought about the whole thing some more, and I think for a "public" API, we need to refine it a bit more. Good work so far though!

from alexandria.core import models


def create_document_file(user, group, document_attributes, file_attributes):
Copy link
Contributor

Choose a reason for hiding this comment

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

Since there are some required arguments, it may make sense to have them listed directly in the arguments. That way, it's clear without even needing to document them.

The file arguments could be renamed, so as to show which ones are required as well. Maybe something like this:

Suggested change
def create_document_file(user, group, document_attributes, file_attributes):
def create_document_file(
user,
group,
category,
title,
file_name,
file_content,
mime_type,
file_size,
additional_attributes=None,
additional_file_attributes=None
):
additional_attributes = additional_attributes or {}
additional_file_attributes = additional_file_attributes or {}

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest renaming the **attributes / **file_attributes to **additional_attributes, to further show that they're additional to the regular ones.

Otherwise, the PR looks good now, and ready to merge

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@winged
Copy link
Contributor

winged commented Mar 13, 2024

Thought about the whole thing some more, and I think for a "public" API, we need to refine it a bit more. Good work so far though!

Yet another thought: some of the functionality could probably be put into django signal handlers instead (before_save for determining a file's size, post_save for creating the thumbnail).

@Yelinz
Copy link
Member Author

Yelinz commented Mar 13, 2024

Thought about the whole thing some more, and I think for a "public" API, we need to refine it a bit more. Good work so far though!

Yet another thought: some of the functionality could probably be put into django signal handlers instead (before_save for determining a file's size, post_save for creating the thumbnail).

Could be considered for a seperate PR, as that would introduce some more code overhaul. We can open an issue for this.
Changed the api to be more explicit, previously I kept it with dicts, to be more flexible(category or category_id).

@winged
Copy link
Contributor

winged commented Mar 14, 2024

Nice work! Please squash before merge though, we don't need all intra-PR fixes in the history

@Yelinz Yelinz merged commit a26f058 into main Mar 15, 2024
3 checks passed
Yelinz added a commit that referenced this pull request Mar 15, 2024
Feature
* Add python api for creating files ([#487](#487)) ([`a26f058`](a26f058))
Yelinz added a commit that referenced this pull request Mar 15, 2024
Feature
* Add python api for creating files ([#487](#487)) ([`a26f058`](a26f058))
@anehx anehx deleted the add-utils branch March 15, 2024 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants