Commit e39312f18880b4e1958c76c51f72c2ac841aae3f

Authored by Jeremy
1 parent 11137fb4
Exists in master and in 1 other branch dev

Fix bug on schedule when the table is empty / added some comms

src/dashboard/views.py
... ... @@ -35,12 +35,12 @@ def devices(request):
35 35 @login_required
36 36 def system(request):
37 37 return render(request, 'dashboard/system.html')
38   -
  38 +
39 39  
40 40 @login_required
41 41 def system_retrieve_logs(request):
42 42 '''
43   - Called by the dashboard system page with ajax request every 1s, to get the logs and print them
  43 + Called by the dashboard system page with ajax request every seconds, to get the logs and print them
44 44 '''
45 45 if request.is_ajax():
46 46 alert_logs = Log.objects.filter(agent='Alert manager')
... ...
src/scheduler/templates/scheduler/current_schedule.html
... ... @@ -25,16 +25,22 @@
25 25  
26 26 <div class="row">
27 27  
28   - <h3>Schedule info</h3>
  28 + <h2>Schedule info</h2>
  29 +
  30 + {% if schedule = None %}
  31 +
  32 + <h3>There is no schedule in the database</h3>
  33 +
  34 + {% else %}
29 35  
30 36 <div class="well">
31 37 Schedule Night Start: {{schedule.plan_night_start|jdtodate}}
32 38 </div>
33   -
  39 +
34 40 <div class="well">
35 41 Schedule Start: {{schedule.plan_start|jdtodate}}
36 42 </div>
37   -
  43 +
38 44 <div class="well">
39 45 Schedule End: {{schedule.plan_end|jdtodate}}
40 46 </div>
... ... @@ -53,10 +59,9 @@
53 59  
54 60 </div>
55 61  
56   -
57 62 <div class="row">
58 63 <h3>List of Sequences - <span class="label label-primary">{{sequences|length}}</span></h3>
59   -
  64 +
60 65 <div class="table-responsive">
61 66 <table
62 67 class="table table-bordered table-hover table-striped tablesorter">
... ... @@ -92,8 +97,8 @@
92 97 </table>
93 98 </div>
94 99 </div>
  100 + {% endif %}
95 101  
96 102 </div><!-- /#page-wrapper -->
97 103  
98 104 {% endblock %}
99   -
100 105 \ No newline at end of file
... ...
src/scheduler/views.py
... ... @@ -8,13 +8,19 @@ SIMULATION_FILE = &#39;file:./scheduler/sequences_cador.html&#39;
8 8  
9 9 @login_required
10 10 def current_schedule(request):
11   - schedule = Schedule.objects.order_by("-created")[0]
12   - shs_list = schedule.shs.all()
13   - sequences = [(shs.sequence, shs) for shs in shs_list]
14   -
15   - nb_scheduled_sequences = len(shs_list)
16   - executed_sequences = len([shs for shs in shs_list if shs.status == Sequence.EXECUTED])
17   -
  11 + if (len(Schedule.objects.all()) > 0): # checking if the schedule is empty
  12 + schedule = Schedule.objects.order_by("-created")[0] # Sorting Schedule
  13 + shs_list = schedule.shs.all() # getting all the schedule has sequences references
  14 + sequences = [(shs.sequence, shs) for shs in shs_list] # getting all sequences
  15 +
  16 + nb_scheduled_sequences = len(shs_list)
  17 + executed_sequences = len([shs for shs in shs_list if shs.status == Sequence.EXECUTED])
  18 + else: # if empty set everything to 0 / None (variables are checked in src/templates/scheduler/current_schedule.html)
  19 + schedule = None
  20 + sequences = None
  21 + shs_list = None
  22 + nb_scheduled_sequences = 0
  23 + executed_sequences = 0
18 24  
19 25 return render(request, 'scheduler/current_schedule.html', {'sequences' : sequences, 'schedule' : schedule, 'nb_scheduled_sequences' : nb_scheduled_sequences, 'executed_sequences' : executed_sequences})
20 26  
... ... @@ -31,4 +37,3 @@ def schedule_simulation(request):
31 37  
32 38 sequences.sort(key=lambda seq: seq[1].tsp)
33 39 return render(request, 'scheduler/current_schedule.html', {'sequences' : sequences, 'schedule' : schedule, 'nb_scheduled_sequences' : nb_scheduled_sequences, 'executed_sequences' : executed_sequences})
34   -
... ...