diff --git a/.gitignore b/.gitignore index 63cd83d..1833f77 100644 --- a/.gitignore +++ b/.gitignore @@ -65,7 +65,7 @@ privatedev/config/*/history/ privatedev/config/*/obsconfig.p src/core/pyros_django/obsconfig/fixtures/obsconfig.p src/core/pyros_django/obsconfig/fixtures/history/* - +src/core/pyros_django/sequences_pickle/ src/core/guitastro # Token file created by pyros_api.py diff --git a/src/core/pyros_django/routine_manager/views.py b/src/core/pyros_django/routine_manager/views.py index 4cb051f..e32c530 100644 --- a/src/core/pyros_django/routine_manager/views.py +++ b/src/core/pyros_django/routine_manager/views.py @@ -1,4 +1,5 @@ from django.core.paginator import Paginator +import pickle from src.pyros_logger import log from pprint import pprint import mimetypes @@ -17,6 +18,7 @@ import ast import os import datetime +from django.forms.models import model_to_dict from src.core.pyros_django.obsconfig.obsconfig_class import OBSConfig from .forms import RequestForm, SequenceForm, AlbumForm, PlanForm, uneditablePlanForm 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): messages.add_message(request,messages.INFO,message) return redirect(action_sequence, seq_id, "view") +def create_sequence_pickle(sequence): + seq_dict = model_to_dict(sequence) + fullseq_dict = { + "sequence":seq_dict, + "albums": {} + } + for album in sequence.albums.all(): + fullseq_dict["albums"][album.name] = {"plans" : []} + for plan in album.plans.all(): + fullseq_dict["albums"][f"{album.name}"]["plans"].append(model_to_dict(instance=plan)) + period = sequence.period + if not os.path.exists("sequences_pickle"): + os.mkdir("./sequences_pickle") + if not os.path.exists(f"sequences_pickle/P{period.id}"): + os.mkdir(f"sequences_pickle/P{period.id}") + seq_pickle_file_name = f"./sequences_pickle/P{period.id}/{sequence.name}.p" + pickle.dump(fullseq_dict,open(seq_pickle_file_name,"wb")) @login_required @level_required("Admin", "Unit-PI", "Observer") @@ -316,6 +335,7 @@ def sequence_validate(request, seq_id): seq.status = Sequence.TOBEPLANNED seq.save() message = "Sequence submitted" + create_sequence_pickle(seq) messages.add_message(request, messages.INFO, message) log.info( f"User {request.user} did action submit sequence {seq} for period {seq.period} ") -- libgit2 0.21.2