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

[14.0][IMP] cetmix_tower_server: Implemented binary files processing #64

Merged

Conversation

dmitriypaulov
Copy link
Contributor

  • File:
    • Added 2 fields:
      • Binary (boolean) - if true, binary file field will be used in upload method as data source instead of code. Will be prefilled from related template
      • File - binary content of the file
    • When binary switch is on - all code related fields become hidden and will not be rendered
  • File Template:
    • Added 1 field:
      • Binary (boolean) - is used to prefill same field in files created from this template.

@dmitriypaulov dmitriypaulov force-pushed the 14.0-t3553-cetmix_tower_server-binary_files_mngmt branch 2 times, most recently from ba333c5 to a04aaf4 Compare June 5, 2024 09:54
Copy link
Contributor

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

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

You are adding new features. They must be covered by tests.

@@ -139,6 +152,15 @@ def _compute_render(self):
var_vals = file.server_id.get_variable_values(variables).get(
file.server_id.id
)

rendered_code = ""
if not file.binary and file.source == "server":
Copy link
Contributor

Choose a reason for hiding this comment

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

What if file is not binary and file source is tower? How will this file be rendered?

@dmitriypaulov dmitriypaulov force-pushed the 14.0-t3553-cetmix_tower_server-binary_files_mngmt branch 2 times, most recently from 6e92683 to ca72d40 Compare June 18, 2024 09:38
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this file

@dmitriypaulov dmitriypaulov force-pushed the 14.0-t3553-cetmix_tower_server-binary_files_mngmt branch 4 times, most recently from 50092a8 to 392f6de Compare June 19, 2024 14:26
@ivs-cetmix
Copy link
Contributor

/ocabot rebase

@CetmixGitDrone
Copy link

Congratulations, PR rebased to 14.0-dev.

@@ -139,6 +150,15 @@ def _compute_render(self):
var_vals = file.server_id.get_variable_values(variables).get(
file.server_id.id
)

rendered_code = ""
if not (file.file_type == "binary" and file.source == "server"):
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to use positive check. Eg

if file.file_type == "text" and file.source == "tower":

@@ -111,6 +114,14 @@ class CxTowerFile(models.Model):
keep_when_deleted = fields.Boolean(
help="File will be kept on server when deleted in Tower",
)
file_type = fields.Selection(
selection=[("text", "Text"), ("binary", "Binary")],
Copy link
Contributor

Choose a reason for hiding this comment

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

Opt for using functions to define both selection and default value. This simplifies the inheritance process.
Example

@@ -37,11 +37,30 @@ def _compute_file_count(self):
help="File will be kept on server when deleted in Tower",
)
file_type = fields.Selection(
selection=[("text", "Text"), ("binary", "Binary")],
default="text",
selection=lambda self: self._selection_file_type(),
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use already existing methods from the cx.tower.file model.
Otherwise you would need to keep both functions updated which is error prone.

Copy link
Contributor

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

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

Code review LGTM

Copy link
Contributor

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

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

@CetmixGitDrone
Copy link

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

Copy link
Contributor

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

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

Code is fine. However this should be covered by tests to ensure it works as expected

@dmitriypaulov dmitriypaulov force-pushed the 14.0-t3553-cetmix_tower_server-binary_files_mngmt branch 3 times, most recently from 66b688f to 722218a Compare June 28, 2024 22:14
[FIX] cetmix_tower_server: code field is not longer rendered if file source is tower, file field becomes readonly when record has been already created

[IMP] cetmix_tower_server

cx.tower.file: Decode file content from base64 before processing upload.
cx.tower.server: Workaround for handling different types of file content (bytes or string).
test_file: check rendered code on template update.

[FIX] cetmix_tower_server: fixed code rendering, replaced binary widget

[ADD] cetmix_tower_server: added functionality of downloading binary files from server

[UPD] cetmix_tower_server: replaced binary boolean with a selection, added search filters

[FIX] cetmix_tower_server: better condition of rendering code, optimized approach of setting selection options and default value for both of file_type fields

[FIX] cetmix_tower_server: using already existing methods for retrieving selection options and default value for file_type field of cx.tower.file.template

[ADD] cetmix_tower_server: exception handling for case when user tries to download binary file as text

[FIX] cetmix_tower_server: fixed popup notification, add tests

[FIX] cetmix_tower_server: complete docstring, fixed tests
@dmitriypaulov dmitriypaulov force-pushed the 14.0-t3553-cetmix_tower_server-binary_files_mngmt branch from 722218a to 2a3fccd Compare July 2, 2024 15:05
Copy link
Contributor

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

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

/ocabot merge nobump

@CetmixGitDrone
Copy link

Hey, thanks for contributing! Proceeding to merge this for you.
Prepared branch 14.0-dev-ocabot-merge-pr-64-by-ivs-cetmix-bump-nobump, awaiting test results.

@CetmixGitDrone CetmixGitDrone merged commit 478c07b into 14.0-dev Jul 2, 2024
5 checks passed
@CetmixGitDrone
Copy link

Congratulations, your PR was merged at 49603af. Thanks a lot for contributing to cetmix. ❤️

@CetmixGitDrone CetmixGitDrone deleted the 14.0-t3553-cetmix_tower_server-binary_files_mngmt branch July 2, 2024 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants