8 |
8 |
9 |
9 |
10 from django.utils.translation import ugettext |
10 from django.utils.translation import ugettext |
11 |
11 |
12 |
12 |
|
13 DEFAULT_ERROR_MESSAGE = ugettext( |
|
14 "There was some error in your request.") |
|
15 |
13 DEFAULT_LOGIN_MESSAGE = ugettext( |
16 DEFAULT_LOGIN_MESSAGE = ugettext( |
14 "You have to login to view this page.") |
17 "You have to login to view this page.") |
15 |
18 |
16 |
19 |
17 class UnauthorizedAccess(Exception): |
20 class PyTaskException(Exception): |
|
21 """Base exception class to be used through out PyTask |
|
22 """ |
|
23 |
|
24 def __init__(self, message=None, **response_args): |
|
25 """Constructor specifying the exception specific attributes. |
|
26 """ |
|
27 |
|
28 if not message: |
|
29 message = DEFAULT_ERROR_MESSAGE |
|
30 |
|
31 self.message = message |
|
32 self.response_args = response_args |
|
33 |
|
34 super(PyTaskException, self).__init__() |
|
35 |
|
36 |
|
37 class UnauthorizedAccess(PyTaskException): |
18 """Exception that is raised when some one tries to access a view |
38 """Exception that is raised when some one tries to access a view |
19 without the right priviliges. |
39 without the right priviliges. |
20 """ |
40 """ |
21 |
41 |
22 def __init__(self, message=None, **response_args): |
42 def __init__(self, message=None, **response_args): |
24 """ |
44 """ |
25 |
45 |
26 if not message: |
46 if not message: |
27 message = DEFAULT_LOGIN_MESSAGE |
47 message = DEFAULT_LOGIN_MESSAGE |
28 |
48 |
29 self.message = message |
49 response_args['status'] = 401 |
30 self.response_args = response_args |
|
31 self.response_args['status'] = 401 |
|
32 |
50 |
33 super(UnauthorizedAccess, self).__init__() |
51 super(UnauthorizedAccess, self).__init__(message, **response_args) |