Skip to content

Commit 2ebd2bb

Browse files
committed
Added object to always duplicate on import
1 parent 087e47c commit 2ebd2bb

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

web/conductEditor.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def conductImportData(conductID):
235235
return { }, 404
236236
access, accessIDs, adminBypass = db.ACLAccess(api.g.sessionData,conductObj.acl,"write")
237237
if access:
238-
data = json.loads(api.request.data)
238+
data = json.loads(api.request.data)
239239
importData = helpers.typeCast(data["importData"])
240240
conductObj.flow = importData["flow"]
241241
for flow in importData["flow"]:
@@ -252,7 +252,9 @@ def conductImportData(conductID):
252252
classObj = _class = model._model().getAsClass(api.g.sessionData,query={ "name" : importData["trigger"][flow["triggerID"]]["className"] })
253253
if len(classObj) > 0:
254254
classObj = classObj[0]
255-
existingTrigger = trigger._trigger().getAsClass(api.g.sessionData,query={ "name" : importData["trigger"][flow["triggerID"]]["name"], "classID" : classObj._id })
255+
existingTrigger = []
256+
if data["duplicateObjects"] == False:
257+
existingTrigger = trigger._trigger().getAsClass(api.g.sessionData,query={ "name" : importData["trigger"][flow["triggerID"]]["name"], "classID" : classObj._id })
256258
if len(existingTrigger) > 0:
257259
existingTrigger = existingTrigger[0]
258260
else:
@@ -267,15 +269,20 @@ def conductImportData(conductID):
267269
for member in members:
268270
if member in importData["trigger"][flow["triggerID"]]:
269271
if member not in blacklist:
270-
setattr(existingTrigger,member,importData["trigger"][flow["triggerID"]][member])
272+
if data["duplicateObjects"] and member == "name":
273+
setattr(existingTrigger,member,"{0}-{1}".format(importData["trigger"][flow["triggerID"]][member],existingTrigger._id))
274+
else:
275+
setattr(existingTrigger,member,importData["trigger"][flow["triggerID"]][member])
271276
updateList.append(member)
272277
existingTrigger.update(updateList,sessionData=api.g.sessionData)
273278
flow["triggerID"] = existingTrigger._id
274279
elif flow["type"] == "action":
275280
classObj = _class = model._model().getAsClass(api.g.sessionData,query={ "name" : importData["action"][flow["actionID"]]["className"] })
276281
if len(classObj) > 0:
277282
classObj = classObj[0]
278-
existingAction = action._action().getAsClass(api.g.sessionData,query={ "name" : importData["action"][flow["actionID"]]["name"], "classID" : classObj._id })
283+
existingAction = []
284+
if data["duplicateObjects"] == False:
285+
existingAction = action._action().getAsClass(api.g.sessionData,query={ "name" : importData["action"][flow["actionID"]]["name"], "classID" : classObj._id })
279286
if len(existingAction) > 0:
280287
existingAction = existingAction[0]
281288
else:
@@ -290,7 +297,10 @@ def conductImportData(conductID):
290297
for member in members:
291298
if member in importData["action"][flow["actionID"]]:
292299
if member not in blacklist:
293-
setattr(existingAction,member,importData["action"][flow["actionID"]][member])
300+
if data["duplicateObjects"] and member == "name":
301+
setattr(existingAction,member,"{0}-{1}".format(importData["action"][flow["actionID"]][member],existingAction._id))
302+
else:
303+
setattr(existingAction,member,importData["action"][flow["actionID"]][member])
294304
updateList.append(member)
295305
existingAction.update(updateList,sessionData=api.g.sessionData)
296306
flow["actionID"] = existingAction._id

web/templates/import.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
<body class="theme-panelContainer">
3030
<div class="container-fluid theme-panelContainer">
3131
Import Data:<br>
32-
<textarea id="importData" class="inputFullWidth theme-panelTextArea" style="height: 150px;"></textarea></br>
32+
<textarea id="importData" class="inputFullWidth theme-panelTextArea" style="height: 150px;"></textarea></br>
33+
<input class="theme-panelCheckbox" type="checkbox" id="duplicateObjects"> Duplicate all objects</input></br>
3334
<button id="import" class="btn btn-primary theme-panelButton">Import</button></br>
3435
</div>
3536
</body>
@@ -41,7 +42,7 @@
4142

4243
<script>
4344
$("#import").click(function () {
44-
$.ajax({type:"POST", data:JSON.stringify({ importData: $('#importData').val(), CSRF: CSRF }), contentType:"application/json", success: function(result) {
45+
$.ajax({type:"POST", data:JSON.stringify({ importData: $('#importData').val(), duplicateObjects: $("#duplicateObjects").is(":checked"), CSRF: CSRF }), contentType:"application/json", success: function(result) {
4546
alert("Imported!");
4647
}
4748
});

0 commit comments

Comments
 (0)