autorefresh index and details (login user)
authorCezary Czaplewski <czarek@chem.univ.gda.pl>
Mon, 8 Jan 2018 19:35:32 +0000 (20:35 +0100)
committerCezary Czaplewski <czarek@chem.univ.gda.pl>
Mon, 8 Jan 2018 19:35:32 +0000 (20:35 +0100)
django_simple/todo/templates/details.html
django_simple/todo/templates/index.html
django_simple/todo/views.py

index f8439bd..4cb9bd7 100644 (file)
@@ -633,6 +633,29 @@ function showDivs(n) {
   x[slideIndex-1].style.display = "block";
 }
 </script>
+
+{% if not task.done %}
+<script>
+function worker() {
+  $.ajax({
+    data:{csrfmiddlewaretoken: '{{ csrf_token }}'},
+    url: "/refresh_done/", 
+    type:"post",
+    success: function(data) {
+      document.location.reload();
+    },
+    complete: function() {
+      // Schedule the next request when the current one's complete
+      setTimeout(worker, 30000);
+    }
+  });
+};
+$(document).ready(function() {
+  // run the first time; all subsequent calls will take care of themselves
+  setTimeout(worker, 30000);
+});
+</script>
+{% endif %} 
        
        
 {% endblock %}
index 1aa90da..33bbd55 100644 (file)
                {% endfor %}            
        </ul>
 
+{% if not alldone %}
+<script src="/static/jquery.min.js"></script>
 
-{% endblock %}
\ No newline at end of file
+<script>
+function worker() {
+  $.ajax({
+    data:{csrfmiddlewaretoken: '{{ csrf_token }}'},
+    url: "/refresh_done/", 
+    type:"post",
+    success: function(data) {
+      window.location.href = "/refresh_done/";
+    },
+    complete: function() {
+      // Schedule the next request when the current one's complete
+      setTimeout(worker, 30000);
+    }
+  });
+};
+$(document).ready(function() {
+  // run the first time; all subsequent calls will take care of themselves
+  setTimeout(worker, 30000);
+});
+</script>
+{% endif %} 
+
+{% endblock %}
index 1c7434c..a29ae69 100644 (file)
@@ -110,7 +110,7 @@ def index(request):
     tasks = Task.objects.filter(owner=user).order_by('-created_date')
     variable = ''
     return render(request, "index.html", {
-            'tasks': tasks
+            'tasks': tasks, 'alldone': 0
         })
 
 @login_required
@@ -608,8 +608,11 @@ def refresh_done1(request, task_id):
 def refresh_done(request):
     user = request.user
     tasks = Task.objects.filter(owner=user).order_by('-created_date')
+    alldone = 1
     for task in tasks:
       refresh_done0(task)
+      if not task.done:
+         alldone=0
 
     proc = subprocess.Popen('/opt/torque/bin/qstat', stdout=subprocess.PIPE)
     njob=0
@@ -627,7 +630,8 @@ def refresh_done(request):
     else:
      return render(request, "index.html", {
                 'tasks': tasks ,
-                'variable' : variable
+                'variable' : variable,
+                'alldone': alldone
                         })