[Fixes #99] Allow user to delete Scheduled Observations
parent
3ec1c90e61
commit
c6ab485753
|
@ -152,6 +152,11 @@ class Observation(models.Model):
|
|||
def is_future(self):
|
||||
return self.end > now()
|
||||
|
||||
@property
|
||||
def is_deletable(self):
|
||||
deletion = self.start - timedelta(minutes=int(settings.OBSERVATION_MAX_DELETION_RANGE))
|
||||
return deletion > now()
|
||||
|
||||
@property
|
||||
def has_data(self):
|
||||
return self.data_set.exclude(payload='').count()
|
||||
|
|
|
@ -13,6 +13,7 @@ urlpatterns = patterns(
|
|||
# Observations
|
||||
url(r'^observations/$', 'observations_list', name='observations_list'),
|
||||
url(r'^observations/(?P<id>[0-9]+)/$', 'observation_view', name='observation_view'),
|
||||
url(r'^observations/(?P<id>[0-9]+)/delete/$', 'observation_delete', name='observation_delete'),
|
||||
url(r'^observations/new/$', 'observation_new', name='observation_new'),
|
||||
url(r'^prediction_windows/(?P<sat_id>[\w.@+-]+)/(?P<start_date>.+)/(?P<end_date>.+)/$',
|
||||
'prediction_windows', name='prediction_windows'),
|
||||
|
|
|
@ -214,6 +214,19 @@ def observation_view(request, id):
|
|||
{'observation': observation, 'data': data})
|
||||
|
||||
|
||||
@login_required
|
||||
def observation_delete(request, id):
|
||||
"""View for deleting observation."""
|
||||
me = request.user
|
||||
observation = get_object_or_404(Observation, id=id)
|
||||
if observation.author == me and observation.is_deletable:
|
||||
observation.delete()
|
||||
messages.success(request, 'Observation deleted successfully.')
|
||||
else:
|
||||
messages.error(request, 'Permission denied.')
|
||||
return redirect(reverse('base:observations_list'))
|
||||
|
||||
|
||||
def stations_list(request):
|
||||
"""View to render Stations page."""
|
||||
stations = Station.objects.all()
|
||||
|
|
|
@ -204,6 +204,7 @@ DATE_MAX_RANGE = '480'
|
|||
|
||||
# Station heartbeat in minutes
|
||||
STATION_HEARTBEAT_TIME = getenv('STATION_HEARTBEAT_TIME', 60)
|
||||
OBSERVATION_MAX_DELETION_RANGE = getenv('OBSERVATION_MAX_DELETION_RANGE', 15)
|
||||
|
||||
# DB API
|
||||
DB_API_ENDPOINT = getenv('DB_API_ENDPOINT', 'https://db.satnogs.org/api/')
|
||||
|
|
|
@ -6,11 +6,22 @@
|
|||
{% block title %} - Observation {{ observation.id }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2 id="observation-info"
|
||||
data-start="{{ observation.start|date:"U"}}"
|
||||
data-end="{{ observation.end|date:"U"}}">
|
||||
Observation #{{ observation.id }}
|
||||
</h2>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h2 id="observation-info"
|
||||
data-start="{{ observation.start|date:"U"}}"
|
||||
data-end="{{ observation.end|date:"U"}}">
|
||||
Observation #{{ observation.id }}
|
||||
</h2>
|
||||
</div>
|
||||
<div class="col-md-6 text-right">
|
||||
<h2>
|
||||
{% if observation.author == request.user and observation.is_deletable %}
|
||||
<a href="{% url 'base:observation_delete' id=observation.id %}" id="obs-delete" class="btn btn-danger">Delete Observation</a>
|
||||
{% endif %}
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
@ -114,4 +125,18 @@
|
|||
<script src="{% static 'js/lib/d3-timeline.js' %}"></script>
|
||||
<script src="{% static 'js/lib/wavesurfer.min.js' %}"></script>
|
||||
<script src="{% static 'js/observation_view.js' %}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var message = "Do you really want to delete this observation?";
|
||||
var actions = $('#obs-delete');
|
||||
if (actions.length) {
|
||||
actions[0].addEventListener("click", function(e) {
|
||||
if (! confirm(message)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{% endblock javascript %}
|
||||
|
|
Loading…
Reference in New Issue