import functools
import logging
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
logger = logging.getLogger(__name__)
[docs]class UnrecognisedFileType(CoveInputDataError):
context = {
'sub_title': _("Sorry we can't process that data"),
'link': 'index',
'link_text': _('Try Again'),
'msg': _('We did not recognise the file type.\n\nWe can only process json, csv and xlsx files.')
}
[docs]def cove_spreadsheet_conversion_error(func):
@functools.wraps(func)
def wrapper(request, *args, **kwargs):
try:
return func(request, *args, **kwargs)
except Exception as err:
logger.exception(err, extra={
'request': request,
})
raise CoveInputDataError({
'sub_title': _("Sorry we can't process that data"),
'link': 'index',
'link_text': _('Try Again'),
'msg': _('We think you tried to supply a spreadsheet, but we failed to convert it to JSON.'
'\n\nError message: {}'.format(repr(err)))
})
return wrapper