Fix datepicker arrows style on hover
[cds-indico.git] / indico / MaKaC / webinterface / pages / errors.py
blob38f0c513627e0b17f60d6efb50c2320f59dd3860
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 """Some pages for dealing with generic application errors
18 """
19 import json
20 import sys
21 import traceback
22 from xml.sax.saxutils import quoteattr
24 from flask import session, request
26 import MaKaC.webinterface.urlHandlers as urlHandlers
27 from MaKaC.webinterface.pages.base import WPDecorated
28 from MaKaC.webinterface.wcomponents import WTemplated
29 from MaKaC.webinterface.pages.main import WPMainBase
30 from MaKaC.i18n import _
31 from indico.core.config import Config
32 from indico.util.i18n import i18nformat
33 from indico.web.util import get_request_info
36 class WGenericError( WTemplated ):
38 def __init__( self, rh, showDetails=False ):
39 self._rh = rh
40 self._showDetails = showDetails
43 def getVars( self ):
44 vars = WTemplated.getVars( self )
45 ex = sys.exc_info()[1]
46 vars["msg"] = self.htmlText( str( ex ) )
47 vars["area"]= ""
48 ty, ex, tb = sys.exc_info()
49 tracebackList = traceback.format_list( traceback.extract_tb( tb ) )
50 rh = self._rh.__class__
51 url = request.url.encode('utf-8')
52 params = []
53 for (k,v) in self._rh.getRequestParams().items():
54 if k.strip() != "password":
55 params.append("""%s = %s""" % (self.htmlText(k), self.htmlText(v)))
56 headers = []
57 for k, v in request.headers.iteritems():
58 headers.append("""%s: %s""" % (self.htmlText(k), self.htmlText(v)))
59 userHTML = """-- none --"""
60 vars["userEmail"] = ""
61 av = self._rh.getAW().getUser()
62 if av:
63 userHTML = self.htmlText( "%s <%s>"%( av.getFullName(), av.getEmail() ) )
64 vars["userEmail"] = quoteattr( av.getEmail() )
65 vars["reportURL"] = quoteattr( str( urlHandlers.UHErrorReporting.getURL() ) )
66 details = ""
67 show_details = Config.getInstance().getDebug()
68 if not show_details:
69 try:
70 show_details = session.user and session.user.is_admin
71 except Exception:
72 # We are handling some error so we cannot know if accessing the session user works
73 # If it fails we simply don't show details...
74 pass
75 if show_details:
76 details = """
77 <table class="errorDetailsBox">
78 <tr>
79 <td>ERROR DETAILS</td>
80 </tr>
81 <tr>
82 <td><br></td>
83 </tr>
84 <tr>
85 <td nowrap align="right"><b>Exception type:</b></td>
86 <td>%s</td>
87 </tr>
88 <tr>
89 <td nowrap align="right" valign="top"><b>Exception message:</b></td>
90 <td>%s</td>
91 </tr>
92 """%( self.htmlText( str(ty) ), self.htmlText( str(ex) ))
94 if hasattr(ex, 'problematic_templates') and hasattr(ex, 'template_tracebacks'):
95 for i in range(len(ex.problematic_templates)):
96 details +="""
97 <tr>
98 <td nowrap align="right" valign="top"><b>Traceback for<br>%s.tpl:</b></td>
99 <td>%s</td>
100 </tr>
101 """%(ex.problematic_templates[i], "<br>".join(ex.template_tracebacks[i]))
103 details +="""
104 <tr>
105 <td valign="top" nowrap align="right"><b>Traceback:</b></td>
106 <td><pre>%s</pre></td>
107 </tr>
108 <tr>
109 <td nowrap align="right"><b>Request handler:</b></td>
110 <td>%s</td>
111 </tr>
112 <tr>
113 <td nowrap align="right"><b>URL:</b></td>
114 <td>%s</td>
115 </tr>
116 <tr>
117 <td nowrap align="right" valign="top"><b>Params:</b></td>
118 <td>%s</td>
119 </tr>
120 <tr>
121 <td valign="top" nowrap align="right"><b>HTTP headers:</b></td>
122 <td><pre>%s</pre></td>
123 </tr>
124 <tr>
125 <td nowrap align="right"><b>Logged user:</b></td>
126 <td>%s</td>
127 </tr>
128 </table>
129 """%("\n".join( tracebackList ), rh.__name__, url, "<br>".join(params), \
130 "\n".join( headers ), userHTML )
131 vars["errorDetails"] = details
132 vars["reportMsg"] = quoteattr(json.dumps({'request_info': get_request_info(),
133 'traceback': traceback.format_exc()}))
134 return vars
136 class WUnexpectedError( WGenericError ):
137 pass
140 class WPGenericError( WPDecorated ):
142 def __init__( self, rh):
143 WPDecorated.__init__( self, rh )
146 def _getBody( self, params ):
147 wc = WGenericError( self._rh, params.get("showDetails", False) )
148 return wc.getHTML()
150 class WPUnexpectedError( WPDecorated ):
152 def __init__( self, rh):
153 WPDecorated. __init__( self, rh )
156 def _getBody( self, params ):
157 wc = WUnexpectedError( self._rh )
158 return wc.getHTML()
160 class WAccessError( WTemplated ):
162 def __init__( self, rh ):
163 self._rh = rh
165 def getVars( self ):
166 vars = WTemplated.getVars( self )
167 vars["area"]= i18nformat(""" _("Authorisation") - """)
168 vars["msg"] = _("The access to this page has been restricted by its owner and you are not authorised to view it")
169 if isinstance(self._rh._target, list):
170 #only objects with Access Controler (e.g. we do not want to check this for RB reservertion target): Conferences, Contribs...
171 contactInfo = [item.getAccessController().getAnyContactInfo() for item in self._rh._target if hasattr(item, 'getAccessController') ]
172 vars["contactInfo"] = ";".join(contactInfo)
173 elif self._rh._target is not None and hasattr(self._rh._target, 'getAccessController'): #only objects with Access Controler (e.g. we do not want to check this for RB reservertion target): Conferences, Contribs...
174 vars["contactInfo"] = self._rh._target.getAccessController().getAnyContactInfo()
175 else:
176 vars["contactInfo"] = ""
177 return vars
179 class WAccessKeyError( WTemplated ):
181 def __init__( self, rh, msg="" ):
182 self._rh = rh
183 self._msg = msg
185 def getVars( self ):
186 from MaKaC.conference import Conference,Material, Resource
187 vars = WTemplated.getVars( self )
188 if isinstance(self._rh._target,Conference):
189 vars["type"] = "event"
190 vars["url"] = quoteattr( str( urlHandlers.UHConfEnterAccessKey.getURL(self._rh._target) ) )
191 else:
192 vars["type"] = "presentation"
193 vars["url"] = quoteattr( str( urlHandlers.UHConfEnterAccessKey.getURL(self._rh._target.getConference()) ) )
194 vars["msg"] = self._msg
195 return vars
198 class WPAccessError( WPDecorated ):
200 def __init__( self, rh ):
201 WPDecorated.__init__( self, rh )
203 def _getBody( self, params ):
204 wc = WAccessError( self._rh )
205 return wc.getHTML()
208 class WPKeyAccessError( WPDecorated ):
210 def __init__( self, rh ):
211 WPDecorated.__init__( self, rh )
213 def _getBody( self, params ):
214 tgt = self._rh._target
215 msg = ""
216 keys = session.get("accessKeys", {})
217 if tgt.getUniqueId() in keys:
218 msg = i18nformat("""<font color=red> _("Bad access key")!</font>""")
219 else:
220 msg = ""
221 wc = WAccessKeyError( self._rh, msg )
222 return wc.getHTML()
225 class WPLaTeXError(WPDecorated):
227 def __init__(self, rh, error):
228 WPDecorated.__init__(self, rh)
229 self._error = error
231 def _getBody( self, params ):
232 wc = WTemplated('LaTeXError')
233 conf = self._error.params['conf']
234 return wc.getHTML({
235 'report_id': self._error.report_id,
236 'is_manager': conf.canModify(self._getAW()),
237 'log': open(self._error.log_file, 'r').read(),
238 'source_code': open(self._error.source_file, 'r').read()
242 class WTimingError( WTemplated ):
244 def __init__( self, rh, msg="" ):
245 self._rh = rh
246 self._msg = msg
248 def getVars( self ):
249 vars = WTemplated.getVars( self )
250 vars["msg"] = self._msg
251 vars["urlbase"] = Config.getInstance().getBaseURL()
252 return vars
254 class WParentTimingError( WTimingError ):
255 pass
257 class WEntryTimingError( WTimingError ):
258 pass
260 class WPTimingError( WPDecorated ):
262 def __init__( self, rh, msg="" ):
263 self._msg = msg
264 WPDecorated. __init__( self, rh)
266 def _getBody( self, params ):
267 wc = WTimingError( self._rh, self._msg )
268 return wc.getHTML()
270 class WPParentTimingError( WPTimingError ):
272 def _getBody( self, params ):
273 wc = WParentTimingError( self._rh, self._msg )
274 return wc.getHTML()
276 class WPEntryTimingError( WPTimingError ):
278 def _getBody( self, params ):
279 wc = WEntryTimingError( self._rh, self._msg )
280 return wc.getHTML()
282 class WModificationError( WTemplated ):
284 def __init__( self, rh ):
285 self._rh = rh
287 def getVars( self ):
288 vars = WTemplated.getVars( self )
289 return vars
292 class WModificationKeyError( WTemplated ):
294 def __init__( self, rh, msg="" ):
295 self._rh = rh
296 self._msg = msg
298 def getVars( self ):
299 vars = WTemplated.getVars( self )
300 vars["msg"] = self._msg
301 redirectURL = ""
302 if hasattr(self._rh, "_redirectURL"):
303 redirectURL = self._rh._redirectURL
304 vars["redirectURL"] = quoteattr(redirectURL)
305 vars["url"] = quoteattr( str( urlHandlers.UHConfEnterModifKey.getURL(self._rh._target) ) )
306 return vars
309 class WPModificationError( WPDecorated ):
311 def __init__( self, rh ):
312 WPDecorated.__init__( self, rh )
314 def _getBody( self, params ):
315 if hasattr(self._rh._target, "getModifKey") and \
316 self._rh._target.getModifKey() != "":
317 keys = session.get("modifKeys", {})
318 if keys.get(self._rh._target.getId()):
319 msg = i18nformat("""<font color=red> _("Wrong modification key!")</font>""")
320 else:
321 msg = ""
322 wc = WModificationKeyError( self._rh, msg )
323 else:
324 wc = WModificationError( self._rh )
325 return wc.getHTML()
328 class WReportError( WTemplated ):
330 def __init__( self, dstMail, msg ):
331 WTemplated.__init__(self)
332 self._dstMail = dstMail
333 self._msg = msg
335 def getVars( self ):
336 vars = WTemplated.getVars( self )
337 vars["postURL"] = quoteattr( str( urlHandlers.UHErrorReporting.getURL() ) )
338 vars["dstEmail"] = quoteattr( self._dstMail )
339 vars["reportMsg"] = quoteattr( self._msg )
340 return vars
343 class WPReportError( WPDecorated ):
345 def __init__( self, rh):
346 WPDecorated.__init__(self, rh)#, True)
348 def _getHTMLHeader(self):
349 return ""
351 def _getHeader(self):
352 return ""
354 def _getBody( self, params ):
355 wc = WReportError( params["userEmail"], params["msg"] )
356 return wc.getHTML( params )
358 def _getFooter( self ):
359 return ""
361 class WNoReportError( WTemplated ):
363 def __init__( self, msg ):
364 self._msg = msg
366 def getVars( self ):
367 vars = WTemplated.getVars( self )
368 vars["msg"] = self._msg
369 return vars
372 class WPNoReportError( WPDecorated ):
374 def __init__( self, rh, msg ):
375 self._msg = msg
376 WPDecorated. __init__( self, rh)
378 def _getHeader(self):
379 return ""
381 def _getBody( self, params ):
382 wc = WNoReportError( self._msg )
383 return wc.getHTML( params )
385 class WReportErrorSummary( WTemplated ):
386 pass
389 class WPReportErrorSummary( WPDecorated ):
391 def __init__( self, rh ):
392 WPDecorated. __init__( self, rh)
394 def _getHTMLHeader( self ):
395 return ""
397 def _getHeader( self ):
398 return ""
400 def _getBody( self, params ):
401 wc = WReportErrorSummary()
402 return wc.getHTML()
404 def _getFooter( self ):
405 return ""
407 class WFormValuesError( WTemplated ):
409 def __init__( self, rh, msg="" ):
410 self._rh = rh
411 self._msg = msg
413 def getVars( self ):
414 vars = WTemplated.getVars( self )
415 vars["msg"] = self._msg
416 return vars
418 class WPFormValuesError( WPDecorated ):
420 def __init__( self, rh, msg="" ):
421 self._msg = msg
422 WPDecorated. __init__( self, rh)
424 def _getBody( self, params ):
425 wc = WFormValuesError( self._rh, self._msg )
426 return wc.getHTML()
429 class WPRestrictedHTML( WPDecorated ):
431 def __init__( self, rh, msg="" ):
432 self._msg = msg
433 WPDecorated. __init__( self, rh)
435 def _getBody( self, params ):
436 wc = WRestrictedHTML( self._rh, self._msg )
437 return wc.getHTML()
439 class WRestrictedHTML( WGenericError ):
441 def __init__( self, rh, msg="" ):
442 self._rh = rh
443 self._msg = msg
445 def getVars( self ):
446 vars = WGenericError.getVars( self )
447 vars["msg"] = self._msg
448 return vars
450 class WPError404( WPMainBase ):
452 def __init__( self, rh, goBack="" ):
453 WPMainBase. __init__( self, rh)
454 self._goBack = goBack
456 def _getBody( self, params ):
457 wc = WError404( self._rh, self._goBack )
458 return wc.getHTML()
460 class WError404( WTemplated ):
462 def __init__( self, rh, goBack="" ):
463 self._rh = rh
464 self._goBack = goBack
466 def getVars( self ):
467 vars = WTemplated.getVars( self )
468 vars["goBack"] = self._goBack
469 return vars