Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / ctx.py @ 9cd9bfe7

History | View | Annotate | Download (2.1 kB)

1 85c46d85 Giorgos Korfiatis
# Copyright 2013 GRNET S.A. All rights reserved.
2 85c46d85 Giorgos Korfiatis
#
3 85c46d85 Giorgos Korfiatis
# Redistribution and use in source and binary forms, with or
4 85c46d85 Giorgos Korfiatis
# without modification, are permitted provided that the following
5 85c46d85 Giorgos Korfiatis
# conditions are met:
6 85c46d85 Giorgos Korfiatis
#
7 85c46d85 Giorgos Korfiatis
#   1. Redistributions of source code must retain the above
8 85c46d85 Giorgos Korfiatis
#      copyright notice, this list of conditions and the following
9 85c46d85 Giorgos Korfiatis
#      disclaimer.
10 85c46d85 Giorgos Korfiatis
#
11 85c46d85 Giorgos Korfiatis
#   2. Redistributions in binary form must reproduce the above
12 85c46d85 Giorgos Korfiatis
#      copyright notice, this list of conditions and the following
13 85c46d85 Giorgos Korfiatis
#      disclaimer in the documentation and/or other materials
14 85c46d85 Giorgos Korfiatis
#      provided with the distribution.
15 85c46d85 Giorgos Korfiatis
#
16 85c46d85 Giorgos Korfiatis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 85c46d85 Giorgos Korfiatis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 85c46d85 Giorgos Korfiatis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 85c46d85 Giorgos Korfiatis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 85c46d85 Giorgos Korfiatis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 85c46d85 Giorgos Korfiatis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 85c46d85 Giorgos Korfiatis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 85c46d85 Giorgos Korfiatis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 85c46d85 Giorgos Korfiatis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 85c46d85 Giorgos Korfiatis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 85c46d85 Giorgos Korfiatis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 85c46d85 Giorgos Korfiatis
# POSSIBILITY OF SUCH DAMAGE.
28 85c46d85 Giorgos Korfiatis
#
29 85c46d85 Giorgos Korfiatis
# The views and conclusions contained in the software and
30 85c46d85 Giorgos Korfiatis
# documentation are those of the authors and should not be
31 85c46d85 Giorgos Korfiatis
# interpreted as representing official policies, either expressed
32 85c46d85 Giorgos Korfiatis
# or implied, of GRNET S.A.
33 85c46d85 Giorgos Korfiatis
34 39b2cb50 Giorgos Korfiatis
from django.contrib import messages
35 39b2cb50 Giorgos Korfiatis
from django.utils.translation import ugettext as _
36 39b2cb50 Giorgos Korfiatis
import astakos.im.messages as astakos_messages
37 3833dc0f Giorgos Korfiatis
import logging
38 39b2cb50 Giorgos Korfiatis
39 3833dc0f Giorgos Korfiatis
logger = logging.getLogger(__name__)
40 3833dc0f Giorgos Korfiatis
41 85c46d85 Giorgos Korfiatis
42 39b2cb50 Giorgos Korfiatis
class ExceptionHandler(object):
43 39b2cb50 Giorgos Korfiatis
    def __init__(self, request):
44 39b2cb50 Giorgos Korfiatis
        self.request = request
45 39b2cb50 Giorgos Korfiatis
46 39b2cb50 Giorgos Korfiatis
    def __enter__(self):
47 39b2cb50 Giorgos Korfiatis
        pass
48 85c46d85 Giorgos Korfiatis
49 39b2cb50 Giorgos Korfiatis
    def __exit__(self, type, value, traceback):
50 39b2cb50 Giorgos Korfiatis
        if value is not None:  # exception
51 39b2cb50 Giorgos Korfiatis
            logger.exception(value)
52 39b2cb50 Giorgos Korfiatis
            m = _(astakos_messages.GENERIC_ERROR)
53 39b2cb50 Giorgos Korfiatis
            messages.error(self.request, m)
54 39b2cb50 Giorgos Korfiatis
            return True  # suppress exception