mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add function to generate "keys" for test results.
- As the keys are to be used for dict-based lookup (in a template) then they cannot contains spaces. - May as well enforce lower-case encoding!
This commit is contained in:
parent
c54cb2b280
commit
17f241774f
@ -19,6 +19,20 @@ from .version import inventreeVersion, inventreeInstanceName
|
||||
from .settings import MEDIA_URL, STATIC_URL
|
||||
|
||||
|
||||
def generateTestKey(test_name):
|
||||
"""
|
||||
Generate a test 'key' for a given test name.
|
||||
This must not have spaces as it will be used for dict lookup in a template.
|
||||
|
||||
Tests must be named such that they will have unique keys.
|
||||
"""
|
||||
|
||||
key = test_name.strip().lower()
|
||||
key = key.replace(" ", "")
|
||||
|
||||
return key
|
||||
|
||||
|
||||
def getMediaUrl(filename):
|
||||
"""
|
||||
Return the qualified access path for the given file,
|
||||
|
@ -962,7 +962,8 @@ class StockItem(MPTTModel):
|
||||
result_map = {}
|
||||
|
||||
for result in results:
|
||||
result_map[result.test] = result
|
||||
key = helpers.generateTestKey(result.test)
|
||||
result_map[key] = result
|
||||
|
||||
return result_map
|
||||
|
||||
|
@ -429,5 +429,6 @@ class TestResultTest(StockTest):
|
||||
|
||||
self.assertEqual(len(result_map), 3)
|
||||
|
||||
for test in ['Firmware Version', 'Settings Checksum', 'Temperature Test']:
|
||||
# Keys are all lower-case and do not contain spaces
|
||||
for test in ['firmwareversion', 'settingschecksum', 'temperaturetest']:
|
||||
self.assertIn(test, result_map.keys())
|
||||
|
Loading…
Reference in New Issue
Block a user