Fix datepicker arrows style on hover
[cds-indico.git] / indico / MaKaC / webinterface / rh / errors.py
blobaacdfedaab91d23446c6b89a2ed4fe0e9e1f859f
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 import json
18 import os
19 from pprint import pformat
22 from flask import request, send_from_directory
23 from werkzeug.urls import url_parse
24 from werkzeug.utils import secure_filename
26 from indico.web.flask.templating import get_template_module
27 from indico.core.notifications import make_email, send_email
28 from MaKaC.webinterface.pages import errors
29 from MaKaC.webinterface.rh.base import RH
31 from indico.core.config import Config
34 class RHErrorReporting(RH):
35 """
36 Handles the reporting of errors to the Indico support.
38 This handler is quite special as it has to handle the reporting of
39 generic errors to the support of the application; any error can happen
40 which means that even the DB could not be avilable so it has to use
41 the minimal system resources possible in order to always be able to
42 report errors.
43 """
45 def _checkParams(self, params):
46 self._sendIt = "confirm" in params
47 self._comments = ""
48 if self._sendIt:
49 self._comments = params.get("comments", "").strip()
50 self._userMail = params.get("userEmail", "")
51 self._msg = params.get("reportMsg", "{}")
53 def _sendReport(self):
54 cfg = Config.getInstance()
55 data = json.loads(self._msg)
56 template = get_template_module('emails/error_report.txt', comment=self._comments, traceback=data['traceback'],
57 request_info=pformat(data['request_info']),
58 server_name=url_parse(cfg.getBaseURL()).netloc)
59 send_email(make_email(cfg.getSupportEmail(), reply_address=self._userMail, template=template), skip_queue=True)
61 def process(self, params):
62 self._checkParams(params)
63 if self._sendIt:
64 self._sendReport()
65 p = errors.WPReportErrorSummary(self)
66 return p.display()
67 else:
68 p = errors.WPReportError(self)
69 return p.display(userEmail=self._userMail, msg=self._msg)
72 class RHDownloadErrorReport(RH):
73 """
74 Allows error reports to be downloaded
75 """
77 def process(self, params):
78 config = Config.getInstance()
80 target_dir = os.path.join(
81 config.getSharedTempDir(), 'reports',
82 secure_filename(request.view_args['report_id']))
84 return send_from_directory(
85 target_dir, request.view_args['filename'],
86 mimetype='text/plain', as_attachment=True)