Skip to content

Commit

Permalink
Merge pull request #56 from LCOGT/fix/target-extra-params
Browse files Browse the repository at this point in the history
Fix target extra params
  • Loading branch information
eheinrich authored Jul 22, 2019
2 parents 2f5965a + f4f3535 commit 94cbc49
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions observation_portal/requestgroups/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,10 @@ def __str__(self):

def as_dict(self):
ret_dict = model_to_dict(self, exclude=self.SERIALIZER_EXCLUDE)
extra_params = ret_dict.get('extra_params', {})
target_helper = TARGET_TYPE_HELPER_MAP[ret_dict['type'].upper()](ret_dict)
ret_dict = {k: ret_dict.get(k) for k in target_helper.fields}
ret_dict['extra_params'] = extra_params
return ret_dict

@property
Expand Down
4 changes: 3 additions & 1 deletion observation_portal/requestgroups/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def to_representation(self, instance):
# Only return data for the specific target type
data = super().to_representation(instance)
target_helper = TARGET_TYPE_HELPER_MAP[data['type']](data)
return {k: data.get(k) for k in target_helper.fields if data.get(k) is not None}
target_dict = {k: data.get(k) for k in target_helper.fields if data.get(k) is not None}
target_dict['extra_params'] = data.get('extra_params', {})
return target_dict

def validate(self, data):
target_helper = TARGET_TYPE_HELPER_MAP[data['type']](data)
Expand Down
8 changes: 8 additions & 0 deletions observation_portal/userrequests/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def convert_userrequest_to_requestgroup(userrequest):
for request in requestgroup['requests']:
target = request['target']
target['type'] = ur_target_type_to_rg(target['type'])

target_extra_params = {}
if 'vmag' in target and target['vmag'] is not None:
target_extra_params['v_magnitude'] = float(target['vmag'])
if 'radvel' in target and target['radvel'] is not None:
target_extra_params['radial_velocity'] = float(target['radvel'])
target['extra_params'] = target_extra_params

constraints = request['constraints']
configurations = []
if 'observatory' in request['location']:
Expand Down
1 change: 1 addition & 0 deletions static/js/request_detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<b-col class="font-weight-bold text-nowrap" v-if="configuration.target[idx]">{{ idx | formatField }}</b-col>
<b-col v-if="x" class="text-right">
<span v-if="idx === 'name'">{{ x }}</span>
<span v-else-if="isObjEmpty(x) && idx==='extra_params'">None</span>
<span v-else>{{ x | formatValue }}</span>
<em v-if="idx === 'ra'" class="text-muted"> ({{ x | raAsSexigesimal }})</em>
<em v-if="idx === 'dec'" class="text-muted"> ({{ x | decAsSexigesimal }})</em>
Expand Down
2 changes: 1 addition & 1 deletion static/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function getFieldDescription(value) {
function formatJson(dict){
let stringVal = '';
for(let key in dict){
if (!_.isEmpty(dict[key])) {
if (!_.isEmpty(dict[key]) || _.isNumber(dict[key])) {
if (!_.isEmpty(stringVal)) {
stringVal += ', ';
}
Expand Down

0 comments on commit 94cbc49

Please sign in to comment.