VC: Fix error on clone page for legacy-ID events
[cds-indico.git] / indico / MaKaC / errors.py
blob917c54233c8a5c518b656a8d84ba75ae81c72f4b
1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 """
18 Module containing the MaKaC exception class hierarchy
19 """
21 from MaKaC.common.fossilize import fossilizes, Fossilizable
22 from indico.core.fossils.errors import IErrorReportFossil, IErrorNoReportFossil
23 from indico.util.translations import ensure_str
26 class MaKaCError(Exception, Fossilizable):
28 fossilizes(IErrorReportFossil)
30 def __init__(self, msg="", area="", explanation=None):
31 self._msg = msg
32 self._area = area
33 self._explanation = explanation
35 def getMessage(self):
36 return self._msg
38 @ensure_str
39 def __str__(self):
40 if self._area != "":
41 return "%s - %s" % (self._area, self._msg)
42 else:
43 return self._msg
45 def getArea(self):
46 return self._area
48 def getExplanation(self):
49 """
50 Some extra information, like actions that can be taken
51 """
53 return self._explanation
56 class AccessControlError(MaKaCError):
57 """
58 """
60 fossilizes(IErrorNoReportFossil)
62 def __init__(self, objectType="object"):
63 MaKaCError.__init__(self)
64 self.objType = objectType
66 @ensure_str
67 def __str__(self):
68 return _("you are not authorised to access this %s") % self.objType
70 def getMessage(self):
71 return str(self)
74 class ConferenceClosedError(MaKaCError):
75 """
76 """
77 fossilizes(IErrorNoReportFossil)
79 def __init__(self, conf):
80 MaKaCError.__init__(self)
81 self._conf = conf
83 @ensure_str
84 def __str__(self):
85 return _("the event has been closed")
88 class AccessError(AccessControlError):
89 """
90 """
91 pass
94 class KeyAccessError(AccessControlError):
95 """
96 """
97 pass
100 class ModificationError(AccessControlError):
104 @ensure_str
105 def __str__(self):
106 return _("you are not authorised to modify this %s") % self.objType
109 class AdminError(AccessControlError):
113 @ensure_str
114 def __str__(self):
115 return _("only administrators can access this %s") % self.objType
118 class TimingError(MaKaCError):
120 Timetable problems
123 fossilizes(IErrorNoReportFossil)
126 class ParentTimingError(TimingError):
129 pass
132 class EntryTimingError(TimingError):
135 pass
138 class UserError(MaKaCError):
142 @ensure_str
143 def __str__(self):
144 if self._msg:
145 return self._msg
146 else:
147 return _("Error creating user")
150 class NotLoggedError(MaKaCError):
153 fossilizes(IErrorNoReportFossil)
156 class FormValuesError(MaKaCError):
159 fossilizes(IErrorNoReportFossil)
162 class NoReportError(MaKaCError):
165 fossilizes(IErrorNoReportFossil)
168 class NotFoundError(MaKaCError):
170 MaKaC's own NotFound version (just for legacy support)
172 fossilizes(IErrorNoReportFossil)
174 def __init__(self, message, title=""):
175 if not title:
176 title = message
177 message = ''
178 super(NotFoundError, self).__init__(title, explanation=message)
181 class HtmlForbiddenTag(MaKaCError):
184 pass
187 class BadRefererError(MaKaCError):
188 pass