Commit e5189e4f00484ef46c83c36aa1ec7f62757f43d9

Authored by haribo
1 parent 3dbda6a0
Exists in master and in 1 other branch dev

Date: 20/06/2016

By: Paul Carensac
Version: 0.7.5
Durations are now printed in seconds, and saved in JD
Issues (closed): https://projects.irap.omp.eu/issues/3835
Major current version (0.7): https://projects.irap.omp.eu/versions/117
@@ -60,12 +60,11 @@ PROJECT STRUCTURE: @@ -60,12 +60,11 @@ PROJECT STRUCTURE:
60 -------------------------------------------------------------------------------------------- 60 --------------------------------------------------------------------------------------------
61 CURRENT VERSION 61 CURRENT VERSION
62 62
63 -Date: 17/06/2016 63 +Date: 20/06/2016
64 By: Paul Carensac 64 By: Paul Carensac
65 -Version: 0.7.4  
66 -Import XML + Changed deprecated reverse by dotting path in templates (links)  
67 -Warning : DB updated  
68 -Issues (closed): https://projects.irap.omp.eu/issues/3811 65 +Version: 0.7.5
  66 +Durations are now printed in seconds, and saved in JD
  67 +Issues (closed): https://projects.irap.omp.eu/issues/3835
69 Major current version (0.7): https://projects.irap.omp.eu/versions/117 68 Major current version (0.7): https://projects.irap.omp.eu/versions/117
70 69
71 ROADMAP: https://projects.irap.omp.eu/projects/pyros/roadmap 70 ROADMAP: https://projects.irap.omp.eu/projects/pyros/roadmap
src/routine_manager/RequestSerializer.py
@@ -33,11 +33,13 @@ class RequestSerializer(): @@ -33,11 +33,13 @@ class RequestSerializer():
33 target_type=req.target_type) 33 target_type=req.target_type)
34 for seq in req.sequences.all(): 34 for seq in req.sequences.all():
35 sequence = ET.SubElement(request, "sequence", name=seq.name, target_coords=seq.target_coords, 35 sequence = ET.SubElement(request, "sequence", name=seq.name, target_coords=seq.target_coords,
36 - jd1=str(seq.jd1), jd2=str(seq.jd2), duration=str(seq.duration)) 36 + jd1=str(seq.jd1), jd2=str(seq.jd2))
  37 + sequence.set("duration", str(seq.duration * 86400))
37 for alb in seq.albums.all(): 38 for alb in seq.albums.all():
38 album = ET.SubElement(sequence, "album", name=alb.name, detector=alb.detector.device.name) 39 album = ET.SubElement(sequence, "album", name=alb.name, detector=alb.detector.device.name)
39 for plan in alb.plans.all(): 40 for plan in alb.plans.all():
40 - ET.SubElement(album, "plan", name=plan.name, filter=plan.filter.device.name, duration=str(plan.duration), nb_images=str(plan.nb_images)) 41 + pl = ET.SubElement(album, "plan", name=plan.name, filter=plan.filter.device.name, nb_images=str(plan.nb_images))
  42 + pl.set("duration", str(plan.duration * 86400))
41 43
42 with open(file_name, "w") as file: 44 with open(file_name, "w") as file:
43 file.write(prettify(request)) 45 file.write(prettify(request))
@@ -126,7 +128,7 @@ class RequestSerializer(): @@ -126,7 +128,7 @@ class RequestSerializer():
126 elif name == "jd2": 128 elif name == "jd2":
127 seq.jd2 = Decimal(value) 129 seq.jd2 = Decimal(value)
128 elif name == "duration": 130 elif name == "duration":
129 - seq.duration = Decimal(value) 131 + seq.duration = Decimal(value) / 86400
130 132
131 # faire des checks ?? j'imagine 133 # faire des checks ?? j'imagine
132 album_list = [] 134 album_list = []
@@ -186,7 +188,7 @@ class RequestSerializer(): @@ -186,7 +188,7 @@ class RequestSerializer():
186 elif name == "name": 188 elif name == "name":
187 pl.name = value 189 pl.name = value
188 elif name == "duration": 190 elif name == "duration":
189 - pl.duration = Decimal(value) 191 + pl.duration = Decimal(value) / 86400
190 elif name == "nb_images": 192 elif name == "nb_images":
191 pl.nb_images = int(value) 193 pl.nb_images = int(value)
192 194
src/routine_manager/forms.py
@@ -7,8 +7,6 @@ class RequestForm(forms.ModelForm): @@ -7,8 +7,6 @@ class RequestForm(forms.ModelForm):
7 Form for Request edition 7 Form for Request edition
8 """ 8 """
9 9
10 - time_start = forms.CharField(label="Time start", widget=forms.TextInput)  
11 -  
12 class Meta: 10 class Meta:
13 model = Request 11 model = Request
14 fields = ("name", "scientific_program", "target_type") 12 fields = ("name", "scientific_program", "target_type")
@@ -20,10 +18,6 @@ class RequestForm(forms.ModelForm): @@ -20,10 +18,6 @@ class RequestForm(forms.ModelForm):
20 field.widget.attrs['readonly'] = True 18 field.widget.attrs['readonly'] = True
21 field.widget.attrs['class'] = 'form-control' 19 field.widget.attrs['class'] = 'form-control'
22 field.required = True 20 field.required = True
23 - self.fields['time_start'].widget.attrs['readonly'] = True  
24 - self.fields['time_start'].required = False  
25 -  
26 -  
27 21
28 22
29 class SequenceForm(forms.ModelForm): 23 class SequenceForm(forms.ModelForm):
@@ -38,10 +32,11 @@ class SequenceForm(forms.ModelForm): @@ -38,10 +32,11 @@ class SequenceForm(forms.ModelForm):
38 ) 32 )
39 33
40 start_expo_pref = forms.ChoiceField(label="Start exposure prefered time", choices=START_EXPO_PREF) 34 start_expo_pref = forms.ChoiceField(label="Start exposure prefered time", choices=START_EXPO_PREF)
  35 + duration = forms.IntegerField(label="duration")
41 36
42 class Meta: 37 class Meta:
43 model = Sequence 38 model = Sequence
44 - fields = ("name", "target_coords", "jd1", "jd2", "duration") 39 + fields = ("name", "target_coords", "jd1", "jd2")
45 40
46 def __init__(self, *args, readonly=False, **kwargs): 41 def __init__(self, *args, readonly=False, **kwargs):
47 super(SequenceForm, self).__init__(*args, **kwargs) 42 super(SequenceForm, self).__init__(*args, **kwargs)
@@ -54,6 +49,10 @@ class SequenceForm(forms.ModelForm): @@ -54,6 +49,10 @@ class SequenceForm(forms.ModelForm):
54 self.fields['duration'].widget.attrs['readonly'] = True 49 self.fields['duration'].widget.attrs['readonly'] = True
55 self.fields['duration'].required = False 50 self.fields['duration'].required = False
56 51
  52 + seq = kwargs["instance"]
  53 + if seq.duration:
  54 + self.fields["duration"].initial = seq.duration * 86400
  55 +
57 def save(self): 56 def save(self):
58 seq = super(SequenceForm, self).save() 57 seq = super(SequenceForm, self).save()
59 if self.cleaned_data["start_expo_pref"] == "IM": 58 if self.cleaned_data["start_expo_pref"] == "IM":
@@ -62,6 +61,7 @@ class SequenceForm(forms.ModelForm): @@ -62,6 +61,7 @@ class SequenceForm(forms.ModelForm):
62 seq.t_prefered = -1; #  TODO : calculer avec le programme de simulation ? 61 seq.t_prefered = -1; #  TODO : calculer avec le programme de simulation ?
63 elif self.cleaned_data["start_expo_pref"] == "MD": 62 elif self.cleaned_data["start_expo_pref"] == "MD":
64 seq.t_prefered = (seq.jd1 + seq .jd2) / 2; 63 seq.t_prefered = (seq.jd1 + seq .jd2) / 2;
  64 + seq.duration = self.cleaned_data["duration"] / 86400
65 seq.save() 65 seq.save()
66 return seq 66 return seq
67 67
@@ -89,9 +89,11 @@ class PlanForm(forms.ModelForm): @@ -89,9 +89,11 @@ class PlanForm(forms.ModelForm):
89 Form for Plan edition 89 Form for Plan edition
90 """ 90 """
91 91
  92 + duration = forms.IntegerField(label="duration")
  93 +
92 class Meta: 94 class Meta:
93 model = Plan 95 model = Plan
94 - fields = ("name", "filter", "duration", "nb_images") 96 + fields = ("name", "filter", "nb_images")
95 97
96 def __init__(self, *args, readonly=False, **kwargs): 98 def __init__(self, *args, readonly=False, **kwargs):
97 super(PlanForm, self).__init__(*args, **kwargs) 99 super(PlanForm, self).__init__(*args, **kwargs)
@@ -101,6 +103,10 @@ class PlanForm(forms.ModelForm): @@ -101,6 +103,10 @@ class PlanForm(forms.ModelForm):
101 field.widget.attrs['class'] = 'form-control' 103 field.widget.attrs['class'] = 'form-control'
102 field.required = True 104 field.required = True
103 105
  106 + plan = kwargs["instance"]
  107 + if plan.duration:
  108 + self.fields["duration"].initial = plan.duration * 86400
  109 +
104 def clean_duration(self): 110 def clean_duration(self):
105 ''' 111 '''
106 Checks if duration is at least of 1s 112 Checks if duration is at least of 1s
@@ -124,6 +130,7 @@ class PlanForm(forms.ModelForm): @@ -124,6 +130,7 @@ class PlanForm(forms.ModelForm):
124 def save(self): 130 def save(self):
125 plan = super(PlanForm, self).save() 131 plan = super(PlanForm, self).save()
126 plan.complete = True 132 plan.complete = True
  133 + plan.duration = self.cleaned_data["duration"] / 86400
127 plan.save() 134 plan.save()
128 check_album_validity(plan.album) 135 check_album_validity(plan.album)
129 return plan 136 return plan