Commit 606cfa68 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

Merge branch '255_fix_max_length_short_description' into 'master'

Add size constraint for description field

Closes #255

See merge request !124
parents e6f43d2e 8d019237
Pipeline #38333 passed with stages
in 7 minutes and 22 seconds
......@@ -98,6 +98,25 @@ class TestMockEditor:
assert widget.dump_json() == json_reference
def test_json_load_and_dump_long_description_field_widget(
self, qtbot, dataformat_model
):
json_reference = {
"field": {"value32": "float32", "value64": "float64"},
"description": "This is a very long description to test if the limitation works properly as expected by the editor or not.",
}
json_expected_output = {
"field": {"value32": "float32", "value64": "float64"},
"description": "This is a very long description to test if the limitation works properly as expected by the editor o",
}
widget = MockAssetEditor()
widget.set_dataformat_model(dataformat_model)
widget.load_json(json_reference)
assert widget.dump_json() == json_expected_output
def test_dataformat_creation_field_widget(self, qtbot, dataformat_model):
widget = MockAssetEditor()
widget.set_dataformat_model(dataformat_model)
......
......@@ -439,6 +439,20 @@ class AssetWidget(QWidget):
self.__update_editors_icon(is_valid)
declaration = asset.declaration
# Check if asset description size is bigger to what is allowed by the current editor
if (
len(declaration.get("description", ""))
> self.current_editor.description_max_length
):
QMessageBox.warning(
self,
self.tr("Description size"),
self.tr(
"The loaded description is too big and will be truncated. Please update your description."
),
)
if asset.type == AssetType.ALGORITHM:
if declaration.get("api_version", 0) < 2:
answer = QMessageBox.question(
......
......@@ -24,6 +24,7 @@
###############################################################################
import simplejson as json
import pkg_resources
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtCore import pyqtSlot
......@@ -67,6 +68,11 @@ class AbstractAssetEditor(QWidget):
self.context = None
self.asset_type = asset_type
self.schema_version = None
common_data = pkg_resources.resource_string("beat.core", "schema/common/1.json")
common_data = json.loads(common_data)
definitions = common_data["definitions"]
description = definitions["description"]
description_max_length = description["maxLength"]
self.clearDirty()
......@@ -74,6 +80,7 @@ class AbstractAssetEditor(QWidget):
self.title_label = QLabel(self.tr("Unknown"))
self.description_lineedit = QLineEdit()
self.description_lineedit.setMaxLength(description_max_length)
self.information_group_box = QGroupBox(self.tr("Information"))
self.information_layout = QFormLayout(self.information_group_box)
......@@ -90,6 +97,10 @@ class AbstractAssetEditor(QWidget):
self.description_lineedit.textChanged.connect(self.dataChanged)
self.dataChanged.connect(self.setDirty)
@property
def description_max_length(self):
return self.description_lineedit.maxLength()
def _add_information_widget(self, label, widget):
"""Add field to information widget
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment