diff --git a/circle/dashboard/templates/dashboard/confirm/ajax-delete.html b/circle/dashboard/templates/dashboard/confirm/ajax-delete.html index 3446cbc..a00945b 100644 --- a/circle/dashboard/templates/dashboard/confirm/ajax-delete.html +++ b/circle/dashboard/templates/dashboard/confirm/ajax-delete.html @@ -13,7 +13,9 @@ <br /> <div class="pull-right" style="margin-top: 15px;"> <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Cancel" %}</button> - <button id="confirmation-modal-button" type="button" class="btn btn-danger">{% trans "Delete" %}</button> + <button disabled id="confirmation-modal-button" type="button" class="btn btn-danger" + {% if disable_submit %}disabled{% endif %} + >{% trans "Delete" %}</button> </div> <div class="clearfix"></div> </div> diff --git a/circle/dashboard/templates/dashboard/confirm/base-delete.html b/circle/dashboard/templates/dashboard/confirm/base-delete.html index 40c1b38..5f1557c 100644 --- a/circle/dashboard/templates/dashboard/confirm/base-delete.html +++ b/circle/dashboard/templates/dashboard/confirm/base-delete.html @@ -26,7 +26,9 @@ {% csrf_token %} <a class="btn btn-default">{% trans "Cancel" %}</a> <input type="hidden" name="next" value="{{ request.GET.next }}"/> - <button class="btn btn-danger">{% trans "Yes" %}</button> + <button class="btn btn-danger" + {% if disable_submit %}disabled{% endif %} + >{% trans "Yes" %}</button> </form> </div> </div> diff --git a/circle/dashboard/views.py b/circle/dashboard/views.py index e00e238..041d4bb 100644 --- a/circle/dashboard/views.py +++ b/circle/dashboard/views.py @@ -1761,9 +1761,26 @@ class LeaseDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView): else: return ['dashboard/confirm/base-delete.html'] + def get_context_data(self, *args, **kwargs): + c = super(LeaseDelete, self).get_context_data(*args, **kwargs) + lease = self.get_object() + templates = lease.instancetemplate_set + if templates.count() > 0: + text = _("You can't delete this lease because some templates " + "are still using it, modify these to proceed: ") + + c['text'] = text + ", ".join("<strong>%s (#%d)</strong>" + "" % (o.name, o.pk) + for o in templates.all()) + c['disable_submit'] = True + return c + def delete(self, request, *args, **kwargs): object = self.get_object() + if (object.instancetemplate_set.count() > 0): + raise SuspiciousOperation() + object.delete() success_url = self.get_success_url() success_message = _("Lease successfully deleted!")