Commit 71a426c1 authored by Janez K's avatar Janez K

reset widget dela tko k more

parent 0aaf1463
......@@ -565,6 +565,26 @@ class Widget(models.Model):
self.running = False
self.save()
def reset_descendants(self):
#find all descendants and reset them as well
widgets = self.workflow.widgets.prefetch_related('inputs','outputs','inputs__connections','outputs__connections','outputs__connections__input','inputs__connections__output')
widgets_dict = {}
widgets_that_need_reset = set([self.pk,])
current_widgets_that_need_reset = set([self.pk,])
for w in widgets:
widgets_dict[w.pk]=w
while len(current_widgets_that_need_reset)>0:
new_widgets_that_need_reset = set()
for w_id in current_widgets_that_need_reset:
for o in widgets_dict[w_id].outputs.all():
for c in o.connections.all():
new_widgets_that_need_reset.add(c.input.widget_id)
widgets_that_need_reset.add(c.input.widget_id)
current_widgets_that_need_reset = new_widgets_that_need_reset
for w in widgets_that_need_reset:
widgets_dict[w].reset(False)
return widgets_that_need_reset
def run_post(self,request):
if not self.ready_to_run():
raise WidgetException("The prerequisites for running this widget have not been met.")
......
......@@ -460,12 +460,7 @@ function runTree(widgetId) {
if(executed[widgetId])
//first reset widget and then run tree
$.post(url['reset-widget'], { 'widget_id':widgetId }, function(data) {
unfinishOne(widgetId)
for (c in connections) {
if (connections[c].outputWidget==widgetId) {
resetWidget(connections[c].inputWidget);
}
}
unfinish(widgetId)
runTreeRec(widgetId);
},'json');
else
......@@ -487,12 +482,12 @@ function runTreeRec(widgetId) {
function resetWidget(widgetId) {
$.post(url['reset-widget'], { 'widget_id':widgetId }, function(data) {
unfinishOne(widgetId)
for (c in connections) {
unfinish(widgetId)
/*for (c in connections) {
if (connections[c].outputWidget==widgetId) {
resetWidget(connections[c].inputWidget);
}
}
}*/
},'json');
}
......
......@@ -914,7 +914,7 @@ def reset_widget(request):
w = get_object_or_404(Widget, pk=request.POST['widget_id'])
if (w.workflow.user==request.user):
try:
w.reset(False)
w.reset_descendants()
data = simplejson.dumps({'status':'ok','message':'Widget '+w.name+' reset successfully.'})
mimetype = 'application/javascript'
except Exception, e:
......
Markdown is supported
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