Commit b7a1601b authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

astakos: Move ExceptionHandler in views.util

It is view-specific and did not deserve a separate file.
parent 7e778bf4
# Copyright 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from django.contrib import messages
from django.utils.translation import ugettext as _
import astakos.im.messages as astakos_messages
import logging
logger = logging.getLogger(__name__)
class ExceptionHandler(object):
def __init__(self, request):
self.request = request
def __enter__(self):
pass
def __exit__(self, type, value, traceback):
if value is not None: # exception
logger.exception(value)
m = _(astakos_messages.GENERIC_ERROR)
messages.error(self.request, m)
return True # suppress exception
# Copyright 2011-2012 GRNET S.A. All rights reserved.
# Copyright 2011, 2012, 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -66,9 +66,8 @@ from astakos.im.functions import check_pending_app_quota, accept_membership, \
get_related_project_id, get_by_chain_or_404, approve_application, \
deny_application, cancel_application, dismiss_application
from astakos.im import settings
from astakos.im.ctx import ExceptionHandler
from astakos.im.views.util import render_response, _create_object, \
_update_object, _resources_catalog
_update_object, _resources_catalog, ExceptionHandler
from astakos.im.views.decorators import cookie_fix, signed_terms_required,\
valid_astakos_user_required
......
# Copyright 2011-2012 GRNET S.A. All rights reserved.
# Copyright 2011, 2012, 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -49,6 +49,26 @@ from snf_django.lib.db.transaction import commit_on_success_strict
from astakos.im import presentation
from astakos.im.util import model_to_dict
from astakos.im.models import Resource
import astakos.im.messages as astakos_messages
import logging
logger = logging.getLogger(__name__)
class ExceptionHandler(object):
def __init__(self, request):
self.request = request
def __enter__(self):
pass
def __exit__(self, exc_type, value, traceback):
if value is not None: # exception
logger.exception(value)
m = _(astakos_messages.GENERIC_ERROR)
messages.error(self.request, m)
return True # suppress exception
def render_response(template, tab=None, status=200, context_instance=None, **kwargs):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment