Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/596.new.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added MJD column next to Timestamp in the Photometry data table.
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{% load bootstrap4 %}
{% load tom_common_extras tom_overrides %}
<form method="POST" action="{% url 'tom_dataproducts:share_all' tg_pk=target.id %}" enctype="multipart/form-data" id="photometry-data-share-form">
{% csrf_token %}
{% for hidden in target_data_share_form.hidden_fields %}
{{ hidden }}
{% endfor %}
<div class="card">
<div class="card-header">
<h5 class="mb-0">Photometry Data</h5>
</div>
<div class="card-body p-0">
<table id="photData" class="table table-striped table-hover table-sm mb-0" cellspacing="0" width="100%">
<thead>
<tr>
<th>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="share-all-phot" onclick="select_all_phot()" value=""/>
<label class="form-check-label" for="share-all-phot">Share</label>
</div>
</th>
<th>Timestamp</th>
<th>MJD</th>
<th>Telescope</th>
<th>Filter</th>
<th>Magnitude</th>
<th>Error</th>
<th>Source</th>
</tr>
</thead>
<tbody>
{% for datum in data %}
<tr>
<td><input type="checkbox" class="phot-row" id="phot-row-{{ datum.id }}" name="share-box" value="{{ datum.id }}" onchange="check_selected_phot()"></td>
<td>{{ datum.timestamp }}</td>
<td>{{ datum.mjd|floatformat:4 }}</td>
<td>{{ datum.telescope }}</td>
<td>{{ datum.filter }}</td>
<td>
{% if datum.limit %}&gt;{% endif %}
{{ datum.magnitude|truncate_value_for_display }}
</td>
{% if datum.error %}
<td>{{ datum.error|truncate_value_for_display:5 }}</td>
{% else %}
<td>{{ datum.magnitude_error|floatformat:4 }}</td>
{% endif %}
<td>{{ datum.source }}</td>
</tr>
{% empty %}
<tr>
<td colspan="8">No Photometry Data.</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% if not target_share %}
<div class="card mt-2">
<div class="card-header">
Share Selected Data
</div>
{% if sharing_destinations %}
<div class="form-row" style="padding-inline:1rem">
<div class="col-sm-12">
{% bootstrap_field target_data_share_form.share_title %}
</div>
</div>
<div class="form-row" style="padding-inline:1rem">
<div class="col-sm-12">
{% bootstrap_field target_data_share_form.share_message %}
</div>
</div>
<div class="form-row" style="padding-inline:1rem">
<div class="col-sm-4">
{% bootstrap_field target_data_share_form.share_destination %}
</div>
<div class="col-sm-2 offset-sm-1">
<input type="submit" class="btn btn-primary" id="submit_selected_phot" value="Submit" name="share_targetdata_form" style="position:absolute; bottom:1rem" disabled onclick="setTargetOnPhotometryForm('')">
</div>
{% if hermes_sharing %}
<div class="col-sm-1">
<b style="position:absolute; bottom:1.2rem">or</b>
</div>
<div class="col-sm-4">
<button class="btn btn-info" type="submit" formaction="{% url 'tom_targets:hermes-preload' pk=target.id %}" onclick="setTargetOnPhotometryForm('_blank')" style="position:absolute; bottom:1rem">Open in Hermes &#x1F5D7;</button>
</div>
{% endif %}
</div>
{% else %}
<em style="padding-inline:1rem">Not Configured. See
<a href="https://tom-toolkit.readthedocs.io/en/stable/managing_data/tom_direct_sharing.html"
target="_blank">Documentation</a>.</em>
{% endif %}
</div>
{% endif %}
</div>
</form>
<script>
const photometryShareForm = document.getElementById('photometry-data-share-form');
function setTargetOnPhotometryForm(val) {
if (val && val != '') {
photometryShareForm.setAttribute('target', val);
} else {
photometryShareForm.removeAttribute('target');
}
return true;
};
function select_all_phot() {
var share_all = document.getElementById("share-all-phot");
if (share_all.checked == true) {
$('input[name=share-box][class=phot-row]').prop('checked', true);
} else {
$('input[name=share-box][class=phot-row]').prop('checked', false);
}
check_selected_phot();
}
function check_selected_phot() {
var share_boxes = document.querySelectorAll("[name='share-box'][class='phot-row']");
var submit_btn = document.getElementById('submit_selected_phot');
for (const box of share_boxes) {
if (box.checked == true) {
submit_btn.disabled = false;
return;
}
}
submit_btn.disabled = true;
}
</script>
61 changes: 60 additions & 1 deletion src/goats_tom/templatetags/tom_overrides.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from datetime import datetime

import plotly.graph_objs as go
from django import template
from django import forms, template
from django.conf import settings
from django.core.paginator import Paginator
from guardian.shortcuts import get_objects_for_user
from plotly import offline
from tom_dataproducts.forms import DataShareForm
from tom_dataproducts.models import ReducedDatum
from tom_dataproducts.processors.data_serializers import SpectrumSerializer

Expand Down Expand Up @@ -126,3 +127,61 @@ def goats_recent_photometry(target, limit=1):
data.append(rd_data)
context = {"target": target, "data": data}
return context


@register.inclusion_tag(
"tom_dataproducts/partials/photometry_datalist_for_target.html",
takes_context=True,
)
def get_photometry_data(context, target, target_share=False):
"""
Displays a table of the all photometric points for a target.
"""
photometry = ReducedDatum.objects.filter(
data_type="photometry", target=target
).order_by("-timestamp")

data = []
for reduced_datum in photometry:
rd_data = {
"id": reduced_datum.pk,
"timestamp": reduced_datum.timestamp,
"source": reduced_datum.source_name,
"filter": reduced_datum.value.get("filter", ""),
"mjd": reduced_datum.value.get("time", ""),
"telescope": reduced_datum.value.get("telescope", ""),
"error": reduced_datum.value.get(
"error", reduced_datum.value.get("magnitude_error", "")
),
}

if "limit" in reduced_datum.value.keys():
rd_data["magnitude"] = reduced_datum.value["limit"]
rd_data["limit"] = True
else:
rd_data["magnitude"] = reduced_datum.value["magnitude"]
rd_data["limit"] = False
data.append(rd_data)

initial = {
"submitter": context["request"].user,
"target": target,
"data_type": "photometry",
"share_title": f"Updated data for {target.name} from"
"{getattr(settings, 'TOM_NAME', 'TOM Toolkit')}.",
}
form = DataShareForm(initial=initial)
form.fields["data_type"].widget = forms.HiddenInput()

sharing = getattr(settings, "DATA_SHARING", None)
hermes_sharing = sharing and sharing.get("hermes", {}).get("HERMES_API_KEY")

context = {
"data": data,
"target": target,
"target_data_share_form": form,
"sharing_destinations": form.fields["share_destination"].choices,
"hermes_sharing": hermes_sharing,
"target_share": target_share,
}
return context
Loading
Loading