Skip to content

Commit

Permalink
[UPD] cetmix_tower_server: replaced binary boolean with a selection, …
Browse files Browse the repository at this point in the history
…added search filters
  • Loading branch information
Dmytro committed Jun 19, 2024
1 parent 5d73403 commit 50092a8
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM my-odoo:14.0

USER root
# Install project related modules
# Install project related modules as root gi
RUN python3.10 -m pip install paramiko
USER odoo
12 changes: 10 additions & 2 deletions cetmix_tower_server/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,11 @@ and put values in the fields:
- **Name**: Filesystem filename
- **Source**: File source. Available options are ``Server`` and
``Tower``. Check above for more details.
- **Binary**: Enable to upload/download binary file.
- **File type**: Type of file contents. Possible options:

- **Text**: Regular text. Eg configuration file or log
- **Binary**: Binary file. Eg file archive or pdf document

- **File**: Is used to store binary file data.
- **Template**: File template used to render this file. If selected
file will be automatically updated every time template is modified.
Expand Down Expand Up @@ -301,7 +305,11 @@ click ``Create`` and put values in the fields:
- **Directory on server**: Directory on remote server where this file
will be stored. This field supports
`Variables <#configure-variables>`__.
- **Binary**: Indicates a binary file.
- **File type**: Type of file contents. Possible options:

- **Text**: Regular text. Eg configuration file or log
- **Binary**: Binary file. Eg file archive or pdf document

- **Tags**: Make usage as search more convenient
- **Note**: Comments or user notes
- **Code**: Raw file content. This field supports
Expand Down
17 changes: 8 additions & 9 deletions cetmix_tower_server/models/cx_tower_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# mapping of field names from template and field names from file
TEMPLATE_FILE_FIELD_MAPPING = {
"code": "code",
"binary": "binary",
"file_name": "name",
"file_type": "file_type",
"server_dir": "server_dir",
"keep_when_deleted": "keep_when_deleted",
}
Expand Down Expand Up @@ -114,11 +114,10 @@ class CxTowerFile(models.Model):
keep_when_deleted = fields.Boolean(
help="File will be kept on server when deleted in Tower",
)
binary = fields.Boolean(
help=(
"If checked, file will be treated as binary "
"and its code will not be editable."
),
file_type = fields.Selection(
selection=[("text", "Text"), ("binary", "Binary")],
default="text",
required=True,
)
file = fields.Binary(
attachment=True,
Expand Down Expand Up @@ -153,7 +152,7 @@ def _compute_render(self):
)

rendered_code = ""
if not (file.binary and file.source == "server"):
if not (file.file_type == "binary" and file.source == "server"):
rendered_code = (
var_vals
and file.code
Expand Down Expand Up @@ -514,12 +513,12 @@ def _process(self, action, raise_error=False):
# In case server version of a 'tower' file is requested
if is_server_code_version_process:
return code
if file.binary:
if file.file_type == "binary":
file.file = b64encode(code)
else:
file.code = code
elif action == "upload":
if file.binary:
if file.file_type == "binary":
file_content = b64decode(file.file)
else:
file_content = tower_key_obj.parse_code(file.rendered_code)
Expand Down
9 changes: 4 additions & 5 deletions cetmix_tower_server/models/cx_tower_file_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ def _compute_file_count(self):
keep_when_deleted = fields.Boolean(
help="File will be kept on server when deleted in Tower",
)
binary = fields.Boolean(
help=(
"If checked, file will be treated as binary "
"and its code will not be editable."
),
file_type = fields.Selection(
selection=[("text", "Text"), ("binary", "Binary")],
default="text",
required=True,
)

def write(self, vals):
Expand Down
8 changes: 6 additions & 2 deletions cetmix_tower_server/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ To create a new file go to `Cetmix Tower/Files/Files` click `Create` and put val

- **Name**: Filesystem filename
- **Source**: File source. Available options are `Server` and `Tower`. Check above for more details.
- **Binary**: Enable to upload/download binary file.
- **File type**: Type of file contents. Possible options:
- **Text**: Regular text. Eg configuration file or log
- **Binary**: Binary file. Eg file archive or pdf document
- **File**: Is used to store binary file data.
- **Template**: File template used to render this file. If selected file will be automatically updated every time template is modified. Used only with `Tower` source.
- **Server**: Server where this file is located
Expand All @@ -141,7 +143,9 @@ To create a new file template go to `Cetmix Tower/Files/Templates` click `Create
- **Name**: Template name
- **File Name**: Filesystem name of the file(s) created from this template. This field supports [Variables](#configure-variables).
- **Directory on server**: Directory on remote server where this file will be stored. This field supports [Variables](#configure-variables).
- **Binary**: Indicates a binary file.
- **File type**: Type of file contents. Possible options:
- **Text**: Regular text. Eg configuration file or log
- **Binary**: Binary file. Eg file archive or pdf document
- **Tags**: Make usage as search more convenient
- **Note**: Comments or user notes
- **Code**: Raw file content. This field supports [Variables](#configure-variables).
Expand Down
12 changes: 10 additions & 2 deletions cetmix_tower_server/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,11 @@ <h2><a class="toc-backref" href="#toc-entry-12">Configure a File</a></h2>
<li><strong>Name</strong>: Filesystem filename</li>
<li><strong>Source</strong>: File source. Available options are <tt class="docutils literal">Server</tt> and
<tt class="docutils literal">Tower</tt>. Check above for more details.</li>
<li><strong>Binary</strong>: Enable to upload/download binary file.</li>
<li><strong>File type</strong>: Type of file contents. Possible options:<ul>
<li><strong>Text</strong>: Regular text. Eg configuration file or log</li>
<li><strong>Binary</strong>: Binary file. Eg file archive or pdf document</li>
</ul>
</li>
<li><strong>File</strong>: Is used to store binary file data.</li>
<li><strong>Template</strong>: File template used to render this file. If selected
file will be automatically updated every time template is modified.
Expand Down Expand Up @@ -670,7 +674,11 @@ <h3><a class="toc-backref" href="#toc-entry-13">File Templates</a></h3>
<li><strong>Directory on server</strong>: Directory on remote server where this file
will be stored. This field supports
<a class="reference external" href="#configure-variables">Variables</a>.</li>
<li><strong>Binary</strong>: Indicates a binary file.</li>
<li><strong>File type</strong>: Type of file contents. Possible options:<ul>
<li><strong>Text</strong>: Regular text. Eg configuration file or log</li>
<li><strong>Binary</strong>: Binary file. Eg file archive or pdf document</li>
</ul>
</li>
<li><strong>Tags</strong>: Make usage as search more convenient</li>
<li><strong>Note</strong>: Comments or user notes</li>
<li><strong>Code</strong>: Raw file content. This field supports
Expand Down
22 changes: 20 additions & 2 deletions cetmix_tower_server/views/cx_tower_file_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
options="{'color_field': 'color'}"
/>
<field name="keep_when_deleted" />
<field name="binary" />
<field name="file_type" />
<field name="note" />
</group>
</group>
<notebook>
<page
name="code"
string="Code"
attrs="{'invisible': [('binary', '=', True)]}"
attrs="{'invisible': [('file_type', '=', 'binary')]}"
>
<field name="code" nolabel="1" />
</page>
Expand All @@ -61,6 +61,7 @@
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="file_type" optional="show" />
<field name="file_name" optional="show" />
<field name="server_dir" optional="show" />
<field
Expand All @@ -81,6 +82,23 @@
<field name="name" />
<field name="server_dir" />
<field name="tag_ids" />
<filter
name="filter_binary"
string="Binary"
domain="[('file_type', '=', 'binary')]"
/>
<filter
name="filter_text"
string="Text"
domain="[('file_type', '=', 'text')]"
/>
<group expand="0" string="Group By">
<filter
name="group_by_file_type"
string="File Type"
context="{'group_by': 'file_type'}"
/>
</group>
</search>
</field>
</record>
Expand Down
52 changes: 36 additions & 16 deletions cetmix_tower_server/views/cx_tower_file_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@
<group>
<group>
<field name="source" required="1" />
<field name="file_type" />
<field name="id" invisible="1" />
<field
name="file"
filename="name"
attrs="{
'invisible': [('file_type', '!=', 'binary')],
'required': [('file_type', '=', 'binary'), ('source', '!=', 'server')],
'readonly': ['|', ('id', '!=', False), ('source', '=', 'server')]
}"
/>
<field
name="template_id"
attrs="{'invisible': [('source', '!=', 'tower')]}"
Expand All @@ -54,17 +65,6 @@
<field
name="keep_when_deleted"
attrs="{'invisible': [('source', '!=', 'tower')]}"
/>
<field name="binary" />
<field name="id" invisible="1" />
<field
name="file"
filename="name"
attrs="{
'invisible': [('binary', '=', False)],
'required': [('binary', '=', True), ('source', '!=', 'server')],
'readonly': ['|', ('id', '!=', False), ('source', '=', 'server')]
}"
/>
</group>
<group>
Expand All @@ -84,7 +84,7 @@
<page
name="code"
string="Code"
attrs="{'invisible': [('binary', '=', True)]}"
attrs="{'invisible': [('file_type', '=', 'binary')]}"
>
<button
string="Modify Code"
Expand All @@ -104,7 +104,7 @@
<page
name="rendered_code"
string="Preview"
attrs="{'invisible': ['|', ('source', '!=', 'tower'), ('binary', '=', True)]}"
attrs="{'invisible': ['|', ('source', '!=', 'tower'), ('file_type', '=', 'binary')]}"
>
<field
name="rendered_code"
Expand All @@ -115,7 +115,7 @@
<page
name="code_on_server"
string="Server Version"
attrs="{'invisible': ['|', ('source', '!=', 'tower'), ('binary', '=', True)]}"
attrs="{'invisible': ['|', ('source', '!=', 'tower'), ('file_type', '=', 'binary')]}"
>
<group>
<button
Expand Down Expand Up @@ -149,6 +149,9 @@
<tree>
<field name="rendered_name" />
<field name="source" />
<field name="file_type" optional="show" />
<field name="file" widget="binary" optional="show" filename="name" />
<field name="name" invisible="1" />
<field name="server_id" />
<field name="full_server_path" optional="hide" />
<field name="sync_date_last" />
Expand Down Expand Up @@ -201,13 +204,30 @@
name="filter_is_error_synced"
domain="[('server_response', 'not in', ['ok', False])]"
/>
<separator />
<filter
string="Text"
name="filter_text"
domain="[('file_type', '=', 'text')]"
/>
<filter
string="Binary"
name="filter_binary"
domain="[('file_type', '=', 'binary')]"
/>
<group expand="0" string="Group By">
<filter
string="Type"
name="group_by_type"
string="Source"
name="group_by_source"
domain="[]"
context="{'group_by': 'source'}"
/>
<filter
string="File Type"
name="group_by_file_type"
domain="[]"
context="{'group_by': 'file_type'}"
/>
<filter
string="Server"
name="group_by_server"
Expand Down

0 comments on commit 50092a8

Please sign in to comment.