Commit 31eb7bc15675f46a203d0e5390dad9c81c61755c
1 parent
83b4b4b2
Exists in
dev
Adding src/core/pyros_django/sequences_pickle to gitignore
Showing
2 changed files
with
21 additions
and
1 deletions
Show diff stats
.gitignore
... | ... | @@ -65,7 +65,7 @@ privatedev/config/*/history/ |
65 | 65 | privatedev/config/*/obsconfig.p |
66 | 66 | src/core/pyros_django/obsconfig/fixtures/obsconfig.p |
67 | 67 | src/core/pyros_django/obsconfig/fixtures/history/* |
68 | - | |
68 | +src/core/pyros_django/sequences_pickle/ | |
69 | 69 | src/core/guitastro |
70 | 70 | |
71 | 71 | # Token file created by pyros_api.py | ... | ... |
src/core/pyros_django/routine_manager/views.py
1 | 1 | from django.core.paginator import Paginator |
2 | +import pickle | |
2 | 3 | from src.pyros_logger import log |
3 | 4 | from pprint import pprint |
4 | 5 | import mimetypes |
... | ... | @@ -17,6 +18,7 @@ import ast |
17 | 18 | import os |
18 | 19 | import datetime |
19 | 20 | |
21 | +from django.forms.models import model_to_dict | |
20 | 22 | from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig |
21 | 23 | from .forms import RequestForm, SequenceForm, AlbumForm, PlanForm, uneditablePlanForm |
22 | 24 | from .validators import check_plan_validity, check_album_validity, check_sequence_validity, check_request_validity |
... | ... | @@ -250,6 +252,23 @@ def unsubmit_sequence(request, seq_id): |
250 | 252 | messages.add_message(request,messages.INFO,message) |
251 | 253 | return redirect(action_sequence, seq_id, "view") |
252 | 254 | |
255 | +def create_sequence_pickle(sequence): | |
256 | + seq_dict = model_to_dict(sequence) | |
257 | + fullseq_dict = { | |
258 | + "sequence":seq_dict, | |
259 | + "albums": {} | |
260 | + } | |
261 | + for album in sequence.albums.all(): | |
262 | + fullseq_dict["albums"][album.name] = {"plans" : []} | |
263 | + for plan in album.plans.all(): | |
264 | + fullseq_dict["albums"][f"{album.name}"]["plans"].append(model_to_dict(instance=plan)) | |
265 | + period = sequence.period | |
266 | + if not os.path.exists("sequences_pickle"): | |
267 | + os.mkdir("./sequences_pickle") | |
268 | + if not os.path.exists(f"sequences_pickle/P{period.id}"): | |
269 | + os.mkdir(f"sequences_pickle/P{period.id}") | |
270 | + seq_pickle_file_name = f"./sequences_pickle/P{period.id}/{sequence.name}.p" | |
271 | + pickle.dump(fullseq_dict,open(seq_pickle_file_name,"wb")) | |
253 | 272 | |
254 | 273 | @login_required |
255 | 274 | @level_required("Admin", "Unit-PI", "Observer") |
... | ... | @@ -316,6 +335,7 @@ def sequence_validate(request, seq_id): |
316 | 335 | seq.status = Sequence.TOBEPLANNED |
317 | 336 | seq.save() |
318 | 337 | message = "Sequence submitted" |
338 | + create_sequence_pickle(seq) | |
319 | 339 | messages.add_message(request, messages.INFO, message) |
320 | 340 | log.info( |
321 | 341 | f"User {request.user} did action submit sequence {seq} for period {seq.period} ") | ... | ... |
-
mentioned in commit 61306fc751a3543f3c7fbbf106d09513a2bc9def