-
Notifications
You must be signed in to change notification settings - Fork 10
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
[14.0][IMP] cetmix_tower_server: Implemented binary files processing #64
Conversation
dmitriypaulov
commented
Jun 5, 2024
- 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
- Added 2 fields:
- File Template:
- Added 1 field:
- Binary (boolean) - is used to prefill same field in files created from this template.
- Added 1 field:
ba333c5
to
a04aaf4
Compare
There was a problem hiding this 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": |
There was a problem hiding this comment.
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?
6e92683
to
ca72d40
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this file
50092a8
to
392f6de
Compare
/ocabot rebase |
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"): |
There was a problem hiding this comment.
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")], |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR has the |
There was a problem hiding this 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
66b688f
to
722218a
Compare
[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
722218a
to
2a3fccd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/ocabot merge nobump
Hey, thanks for contributing! Proceeding to merge this for you. |
Congratulations, your PR was merged at 49603af. Thanks a lot for contributing to cetmix. ❤️ |