# 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/utils.py
# def timestamp_to_string(ts):
#     return django_date(
#         datetime.datetime.fromtimestamp(int(ts)),
#         'SHORT_DATETIME_FORMAT')


from django.urls 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
from disaster_recovery.utils import shield
from disaster_recovery.utils import timestamp_to_string
import disaster_recovery.api.api as freezer_api
                '<i class="fa fa-chain-broken fa-fw" title="There are {} '
                'broken links in this backup"></i>'.format(
                    backup.total_broken_links))
    except Exception:
        result.append(placeholder)

    try:
        if backup.excluded_files:
            result.append(
                '<i class="fa fa-minus-square fa-fw" title="{} files have been'
                ' excluded from this backup"></i>'.format(
                    len(backup.excluded_files)))
    except Exception:
        result.append(placeholder)

    return safestring.mark_safe("".join(result))


def backup_detail_view(backup):
    return reverse("horizon:disaster_recovery:backups:detail",
                   kwargs={'backup_id': backup.id})


class BackupsTable(tables.DataTable):
    backup_name = tables.Column('backup_name',
                                verbose_name=_("Backup Name"),
                                link=backup_detail_view)
    hostname = tables.Column('hostname', verbose_name=_("Hostname"))
    created = tables.Column("time_stamp",
                            verbose_name=_("Created At"),

# 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/utils.py
# def timestamp_to_string(ts):
#     return django_date(
#         datetime.datetime.fromtimestamp(int(ts)),
#         'SHORT_DATETIME_FORMAT')


# Path: disaster_recovery/backups/tables.py
from django.urls 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
from disaster_recovery.utils import shield
from disaster_recovery.utils import timestamp_to_string
import disaster_recovery.api.api as freezer_api

                '<i class="fa fa-chain-broken fa-fw" title="There are {} '
                'broken links in this backup"></i>'.format(
                    backup.total_broken_links))
    except Exception:
        result.append(placeholder)

    try:
        if backup.excluded_files:
            result.append(
                '<i class="fa fa-minus-square fa-fw" title="{} files have been'
                ' excluded from this backup"></i>'.format(
                    len(backup.excluded_files)))
    except Exception:
        result.append(placeholder)

    return safestring.mark_safe("".join(result))


def backup_detail_view(backup):
    return reverse("horizon:disaster_recovery:backups:detail",
                   kwargs={'backup_id': backup.id})


class BackupsTable(tables.DataTable):
    backup_name = tables.Column('backup_name',
                                verbose_name=_("Backup Name"),
                                link=backup_detail_view)
    hostname = tables.Column('hostname', verbose_name=_("Hostname"))
    created = tables.Column("time_stamp",
                            verbose_name=_("Created At"),

                            filters=[timestamp_to_string])