# Path: disaster_recovery/utils.py
# def shield(message, redirect=''):
#     """decorator to reduce boilerplate try except blocks for horizon functions
#     :param message: a str error message
#     :param redirect: a str with the redirect namespace without including
#                      horizon:disaster_recovery:
#                      eg. @shield('error', redirect='jobs:index')
#     """
#     def wrap(function):
# 
#         @wraps(function)
#         def wrapped_function(view, *args, **kwargs):
# 
#             try:
#                 return function(view, *args, **kwargs)
#             except Exception as error:
#                 LOG.error(error.message)
#                 namespace = "horizon:disaster_recovery:"
#                 r = reverse("{0}{1}".format(namespace, redirect))
# 
#                 if view.request.path == r:
#                     # To avoid an endless loop, we must not redirect to the
#                     # same page on which the error happened
#                     user_home = get_user_home(view.request.user)
#                     exceptions.handle(view.request, _(error.message),
#                                       redirect=user_home)
#                 else:
#                     exceptions.handle(view.request, _(error.message),
#                                       redirect=r)
# 
#         return wrapped_function
#     return wrap


from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import tables
from django.urls import reverse
from disaster_recovery.utils import shield
import disaster_recovery.api.api as freezer_api
#  under the License.





class Filter(tables.FilterAction):
    filter_type = "server"
    filter_choices = (("exact", "Exact text", True),)


class DeleteClient(tables.DeleteAction):
    help_text = _("Delete Clients is not recoverable.")

    @staticmethod
    def action_present(count):
        return ungettext_lazy(
            u"Delete Client",
            u"Delete Clients",
            count
        )

    @staticmethod
    def action_past(count):
        return ungettext_lazy(
            u"Deleted Client",
            u"Deleted Clients",
            count
        )


# Path: disaster_recovery/utils.py
# def shield(message, redirect=''):
#     """decorator to reduce boilerplate try except blocks for horizon functions
#     :param message: a str error message
#     :param redirect: a str with the redirect namespace without including
#                      horizon:disaster_recovery:
#                      eg. @shield('error', redirect='jobs:index')
#     """
#     def wrap(function):
# 
#         @wraps(function)
#         def wrapped_function(view, *args, **kwargs):
# 
#             try:
#                 return function(view, *args, **kwargs)
#             except Exception as error:
#                 LOG.error(error.message)
#                 namespace = "horizon:disaster_recovery:"
#                 r = reverse("{0}{1}".format(namespace, redirect))
# 
#                 if view.request.path == r:
#                     # To avoid an endless loop, we must not redirect to the
#                     # same page on which the error happened
#                     user_home = get_user_home(view.request.user)
#                     exceptions.handle(view.request, _(error.message),
#                                       redirect=user_home)
#                 else:
#                     exceptions.handle(view.request, _(error.message),
#                                       redirect=r)
# 
#         return wrapped_function
#     return wrap


# Path: disaster_recovery/clients/tables.py
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ungettext_lazy
from horizon import tables
from django.urls import reverse
from disaster_recovery.utils import shield
import disaster_recovery.api.api as freezer_api

#  under the License.





class Filter(tables.FilterAction):
    filter_type = "server"
    filter_choices = (("exact", "Exact text", True),)


class DeleteClient(tables.DeleteAction):
    help_text = _("Delete Clients is not recoverable.")

    @staticmethod
    def action_present(count):
        return ungettext_lazy(
            u"Delete Client",
            u"Delete Clients",
            count
        )

    @staticmethod
    def action_past(count):
        return ungettext_lazy(
            u"Deleted Client",
            u"Deleted Clients",
            count
        )


    @shield("Unable to delete client", redirect="clients:index")