Add ability to delete a Ground Station
parent
3569047599
commit
3719805cde
|
@ -21,6 +21,7 @@ urlpatterns = patterns(
|
|||
# Stations
|
||||
url(r'^stations/$', 'stations_list', name='stations_list'),
|
||||
url(r'^stations/(?P<id>[0-9]+)/$', 'station_view', name='station_view'),
|
||||
url(r'^stations/(?P<id>[0-9]+)/delete/$', 'station_delete', name='station_delete'),
|
||||
url(r'^stations/edit/$', 'station_edit', name='station_edit'),
|
||||
url(r'^stations_all/$', StationAllView.as_view({'get': 'list'}), name='stations_all'),
|
||||
|
||||
|
|
|
@ -273,3 +273,13 @@ def station_edit(request):
|
|||
else:
|
||||
messages.error(request, 'Some fields missing on the form')
|
||||
return redirect(reverse('users:view_user', kwargs={'username': request.user.username}))
|
||||
|
||||
|
||||
@login_required
|
||||
def station_delete(request, id):
|
||||
"""View for deleting a station."""
|
||||
me = request.user
|
||||
station = get_object_or_404(Station, id=id, owner=request.user)
|
||||
station.delete()
|
||||
messages.success(request, 'Ground Station deleted successfully.')
|
||||
return redirect(reverse('users:view_user', kwargs={'username': me}))
|
||||
|
|
|
@ -128,7 +128,7 @@
|
|||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var message = "Do you really want to delete this observation?";
|
||||
var message = "Do you really want to delete this Observation?";
|
||||
var actions = $('#obs-delete');
|
||||
if (actions.length) {
|
||||
actions[0].addEventListener("click", function(e) {
|
||||
|
|
|
@ -23,7 +23,14 @@
|
|||
<div class="col-md-6 text-right">
|
||||
<h2>
|
||||
{% if request.user == station.owner %}
|
||||
<button class="btn btn-primary" data-toggle="modal" data-target="#StationModal">Edit Ground Station</button>
|
||||
<button class="btn btn-primary" data-toggle="modal" data-target="#StationModal">
|
||||
<span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>
|
||||
Edit
|
||||
</button>
|
||||
<a class="btn btn-danger" id="station-delete" href="{% url 'base:station_delete' id=station.id %}">
|
||||
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
|
||||
Delete
|
||||
</a>
|
||||
{% endif %}
|
||||
</h2>
|
||||
</div>
|
||||
|
@ -144,4 +151,18 @@
|
|||
<script src="{% static 'js/lib/mapbox.js' %}"></script>
|
||||
<script src="{% static 'js/station_view.js' %}"></script>
|
||||
<script src="{% static 'js/gridsquare.js' %}"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
(function() {
|
||||
var message = "Do you really want to delete this Ground Station?";
|
||||
var actions = $('#station-delete');
|
||||
if (actions.length) {
|
||||
actions[0].addEventListener("click", function(e) {
|
||||
if (! confirm(message)) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{% endblock javascript %}
|
||||
|
|
Loading…
Reference in New Issue