diff --git a/disaster_recovery/api/api.py b/disaster_recovery/api/api.py index 0aa1805..86a7c2b 100644 --- a/disaster_recovery/api/api.py +++ b/disaster_recovery/api/api.py @@ -571,3 +571,6 @@ class Backup(object): } job_id = self.client.jobs.create(job) return Job(self.request).start(job_id) + + def delete(self, backup_id): + return self.client.backups.delete(backup_id) diff --git a/disaster_recovery/backups/tables.py b/disaster_recovery/backups/tables.py index c087b8b..7d702c5 100644 --- a/disaster_recovery/backups/tables.py +++ b/disaster_recovery/backups/tables.py @@ -14,11 +14,14 @@ from django.core.urlresolvers import reverse from django.utils import safestring +from django.utils.translation import ungettext_lazy from django.utils.translation import ugettext_lazy as _ from horizon import tables from horizon.utils import functions as utils +import disaster_recovery.api.api as freezer_api +from disaster_recovery.utils import shield from disaster_recovery.utils import timestamp_to_string @@ -33,6 +36,37 @@ class Restore(tables.LinkAction): kwargs={'backup_id': datum.id}) +class DeleteBackup(tables.DeleteAction): + name = "delete" + classes = ("btn-danger",) + icon = "remove" + help_text = _("Delete backups is not recoverable.") + + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Backup", + u"Delete Backups", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Deleted Backup", + u"Deleted Backups", + count + ) + + @shield("Unable to delete backup", redirect="backups:index") + def delete(self, request, backup_id): + return freezer_api.Backup(request).delete(backup_id) + + +class DeleteMultipleBackups(DeleteBackup): + name = "delete_multiple_backups" + + class Filter(tables.FilterAction): filter_type = "server" filter_choices = (("exact", "Exact text", True),) @@ -100,9 +134,12 @@ class BackupsTable(tables.DataTable): page_size = utils.get_page_size(self.request) return "=".join(['offset', str(self.offset + page_size)]) + def get_object_display_key(self, datum): + return 'backup_name' + class Meta: name = "backups" verbose_name = _("Backup History") - row_actions = (Restore,) - table_actions = (Filter,) - multi_select = False + row_actions = (Restore, DeleteBackup,) + table_actions = (Filter, DeleteMultipleBackups,) + multi_select = True