|
1 | 1 | # Standard Python libraries. |
2 | 2 | import datetime |
| 3 | +import os |
3 | 4 | import pytz |
4 | 5 |
|
5 | 6 | # Third party Python libraries. |
@@ -163,8 +164,33 @@ def partial_update(self, request, pk=None, **kwargs): |
163 | 164 |
|
164 | 165 | return JsonResponse(response_dict) |
165 | 166 |
|
166 | | - # Update the scheduled_scan_dict with the most recent scan_status state from the PUT request. When |
167 | | - # originally querying above, the old state is passed to utility.py unless it is updated. |
| 167 | + # Setup folder directories. |
| 168 | + scan_results_dir = "/home/scantron/console/scan_results" |
| 169 | + pending_files_dir = os.path.join(scan_results_dir, "pending") |
| 170 | + completed_files_dir = os.path.join(scan_results_dir, "complete") |
| 171 | + cancelled_files_dir = os.path.join(scan_results_dir, "cancelled") |
| 172 | + |
| 173 | + if new_scan_status == "cancelled": |
| 174 | + # Move scan files to the "cancelled" directory for historical purposes. |
| 175 | + utility.move_wildcard_files( |
| 176 | + f"{scheduled_scan_dict['result_file_base_name']}*", pending_files_dir, cancelled_files_dir |
| 177 | + ) |
| 178 | + |
| 179 | + if new_scan_status == "completed": |
| 180 | + # Move files from "pending" directory to "complete" directory. |
| 181 | + utility.move_wildcard_files( |
| 182 | + f"{scheduled_scan_dict['result_file_base_name']}*", pending_files_dir, completed_files_dir |
| 183 | + ) |
| 184 | + |
| 185 | + # Django compliant pre-formated datetimestamp. |
| 186 | + now_datetime = get_current_time() |
| 187 | + ScheduledScan.objects.filter(scan_engine=request.user).filter(pk=pk).update( |
| 188 | + completed_time=now_datetime |
| 189 | + ) |
| 190 | + |
| 191 | + # Update the scheduled_scan_dict with the most recent scan_status state from the PATCH request. When |
| 192 | + # originally querying above, the old state would passed to utility.py since it hasn't officially been |
| 193 | + # updated by Django's .update() yet. |
168 | 194 | scheduled_scan_dict["scan_status"] = new_scan_status |
169 | 195 |
|
170 | 196 | # Create a redis connection object. |
|
0 commit comments