@@ -229,6 +229,14 @@ def process_arrays(params):
229229 return params
230230
231231
232+ add_data_field_examples = (
233+ 'sample() or '
234+ 'random(<min_int>, <max_int>) or '
235+ 'choices(["<value1>", "<value2>", ...], [<weight1>, <weight2>, ...]) or '
236+ 'replace("old-string", "new-string")'
237+ )
238+
239+
232240def add_expression (queryset , size , value , value_name ):
233241 # simple parsing
234242 command , args = value .split ('(' )
@@ -262,12 +270,16 @@ def add_expression(queryset, size, value, value_name):
262270 for i , v in enumerate (values ):
263271 tasks [i ].data [value_name ] = v
264272
273+ # replaceg
274+ elif command == 'replace' :
275+ old_value , new_value = json .loads (args [0 ]), json .loads (args [1 ])
276+ for task in tasks :
277+ if value_name in task .data :
278+ task .data [value_name ] = task .data [value_name ].replace (old_value , new_value )
279+
265280 else :
266281 raise Exception (
267- 'Undefined expression, you can use: '
268- 'sample() or'
269- 'random(<min_int>, <max_int>) or '
270- 'choices([<value1>, <value2>, ...], [<weight1>, <weight2>, ...])'
282+ 'Undefined expression, you can use: ' + add_data_field_examples
271283 )
272284
273285 Task .objects .bulk_update (tasks , fields = ['data' ], batch_size = 1000 )
@@ -301,13 +313,13 @@ def add_data_field_form(user, project):
301313 {
302314 'entry_point' : add_data_field ,
303315 'permission' : all_permissions .tasks_change ,
304- 'title' : 'Add Data Field' ,
316+ 'title' : 'Add Or Modify Data Field' ,
305317 'order' : 1 ,
306318 'experimental' : True ,
307319 'dialog' : {
308320 'text' : 'Confirm that you want to add a new field in tasks. '
309321 'After this operation you must refresh the Data Manager page fully to see the new column! '
310- 'You can use the following expressions: sample(), random(<min_int>, <max_int>)' ,
322+ 'You can use the following expressions: ' + add_data_field_examples ,
311323 'type' : 'confirm' ,
312324 'form' : add_data_field_form ,
313325 }
0 commit comments