Commit 31eb7bc15675f46a203d0e5390dad9c81c61755c

Authored by Alexis Koralewski
1 parent 83b4b4b2
Exists in dev

Adding src/core/pyros_django/sequences_pickle to gitignore

@@ -65,7 +65,7 @@ privatedev/config/*/history/ @@ -65,7 +65,7 @@ privatedev/config/*/history/
65 privatedev/config/*/obsconfig.p 65 privatedev/config/*/obsconfig.p
66 src/core/pyros_django/obsconfig/fixtures/obsconfig.p 66 src/core/pyros_django/obsconfig/fixtures/obsconfig.p
67 src/core/pyros_django/obsconfig/fixtures/history/* 67 src/core/pyros_django/obsconfig/fixtures/history/*
68 - 68 +src/core/pyros_django/sequences_pickle/
69 src/core/guitastro 69 src/core/guitastro
70 70
71 # Token file created by pyros_api.py 71 # Token file created by pyros_api.py
src/core/pyros_django/routine_manager/views.py
1 from django.core.paginator import Paginator 1 from django.core.paginator import Paginator
  2 +import pickle
2 from src.pyros_logger import log 3 from src.pyros_logger import log
3 from pprint import pprint 4 from pprint import pprint
4 import mimetypes 5 import mimetypes
@@ -17,6 +18,7 @@ import ast @@ -17,6 +18,7 @@ import ast
17 import os 18 import os
18 import datetime 19 import datetime
19 20
  21 +from django.forms.models import model_to_dict
20 from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig 22 from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig
21 from .forms import RequestForm, SequenceForm, AlbumForm, PlanForm, uneditablePlanForm 23 from .forms import RequestForm, SequenceForm, AlbumForm, PlanForm, uneditablePlanForm
22 from .validators import check_plan_validity, check_album_validity, check_sequence_validity, check_request_validity 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,6 +252,23 @@ def unsubmit_sequence(request, seq_id):
250 messages.add_message(request,messages.INFO,message) 252 messages.add_message(request,messages.INFO,message)
251 return redirect(action_sequence, seq_id, "view") 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 @login_required 273 @login_required
255 @level_required("Admin", "Unit-PI", "Observer") 274 @level_required("Admin", "Unit-PI", "Observer")
@@ -316,6 +335,7 @@ def sequence_validate(request, seq_id): @@ -316,6 +335,7 @@ def sequence_validate(request, seq_id):
316 seq.status = Sequence.TOBEPLANNED 335 seq.status = Sequence.TOBEPLANNED
317 seq.save() 336 seq.save()
318 message = "Sequence submitted" 337 message = "Sequence submitted"
  338 + create_sequence_pickle(seq)
319 messages.add_message(request, messages.INFO, message) 339 messages.add_message(request, messages.INFO, message)
320 log.info( 340 log.info(
321 f"User {request.user} did action submit sequence {seq} for period {seq.period} ") 341 f"User {request.user} did action submit sequence {seq} for period {seq.period} ")