Skip to content

Commit

Permalink
Limits dataset descripiton to 4000 characters
Browse files Browse the repository at this point in the history
+ Updates UI to warn user about limit in tooltips
+ Adds api test for character limit.

Closes #386
  • Loading branch information
vchendrix committed Apr 11, 2023
1 parent 23183bd commit 58246ab
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion archive_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def data_set_id(self):
return "NGT{:04}".format(self.ngt_id)

ngt_id = models.IntegerField()
description = models.TextField(blank=True, null=True)
description = models.TextField(blank=True, null=True, max_length=4000)
version = models.CharField(max_length=15, default="0.0")

status = models.IntegerField(choices=STATUS_CHOICES,
Expand Down
8 changes: 6 additions & 2 deletions archive_api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,11 @@ def test_client_put(self):
value = json.loads(response.content.decode('utf-8'))
self.assertEqual(value['description'], "A FooBarBaz DataSet")

def test_client_put_reference_error(self):
def test_client_put_field_character_limits(self):
"""Test field character limit errors"""
self.login_user("auser")
reference = 'a'*2256
description = 'a'*4001
response = self.client.put('/api/v1/datasets/1/', data='{"data_set_id":"FooBarBaz","description":"A FooBarBaz DataSet",'
'"name": "Data Set 1", '
'"status_comment": "",'
Expand All @@ -276,6 +278,7 @@ def test_client_put_reference_error(self):
'"doe_funding_contract_numbers": "",'
'"acknowledgement": "",'
'"reference": "'+reference+'",'
'"description": "'+description+'",'
'"additional_reference_information": "",'
'"additional_access_information": "",'
'"submission_date": "2016-10-28T19:12:35Z",'
Expand All @@ -289,7 +292,8 @@ def test_client_put_reference_error(self):
print(response.content)
self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code)
value = json.loads(response.content.decode('utf-8'))
self.assertEqual(value, {"reference": ["Ensure this field has no more than 2255 characters."]})
self.assertEqual(value, {'description': ['Ensure this field has no more than 4000 characters.'],
'reference': ['Ensure this field has no more than 2255 characters.']})

def test_user_workflow(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion ui/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ $(document).ready(function () {
}
});

$.getJSON("static/js/metadata/dataset.json?v=20220901", function (data) {
$.getJSON("static/js/metadata/dataset.json?v=20230411", function (data) {
templates.datasets = data;
createEditForm('datasets');
});
Expand Down
2 changes: 1 addition & 1 deletion ui/static/js/metadata/dataset.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"label": "Dataset Description",
"sequence": 4,
"multiple": false,
"description": "<p>Dataset description and overview. This should read as an abstract for the dataset, and provide users with adequate information about what the dataset contains, and how to use it. Include details on what data what, when and where data was collected, and if any data processing was done.</p> <p><i>E.g.: Raw output from the data logger connected to 9 sapflow and 5 soil moisture sensors are provided in xxx.dat. The metadata file (BR-Ma2 E-field log_20160501.xls) has information on locations where the sensors were installed, and other installation/maintenance details. No data processing or QA/QC was done on the raw datasets. Processed datasets will be uploaded separately. Contact [email protected] if you need to use this dataset for additional information.</i></p>"
"description": "<p>Dataset description and overview. This should read as an abstract for the dataset, and provide users with adequate information about what the dataset contains, and how to use it. Include details on what data what, when and where data was collected, and if any data processing was done.</p> <p><i>E.g.: Raw output from the data logger connected to 9 sapflow and 5 soil moisture sensors are provided in xxx.dat. The metadata file (BR-Ma2 E-field log_20160501.xls) has information on locations where the sensors were installed, and other installation/maintenance details. No data processing or QA/QC was done on the raw datasets. Processed datasets will be uploaded separately. Contact [email protected] if you need to use this dataset for additional information.</i> <b>This field has a limit of 4,000 characters.</b></p>"
},
"sites": {
"type": "reference_list",
Expand Down

0 comments on commit 58246ab

Please sign in to comment.