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