diff --git a/docs/panels.rst b/docs/panels.rst index 1c9252d..b97aafe 100644 --- a/docs/panels.rst +++ b/docs/panels.rst @@ -104,3 +104,10 @@ Profiler Reports profiling data for the current request. Due to the performance overhead, profiling is disabled by default. Click the checkmark to toggle profiling on or off. After enabling the profiler, refresh the page to re-run it with profiling. .. image:: _static/screenshot-profiler-panel.png + +Mail +-------- + + flask_debugtoolbar.panels.mail.MailDebugPanel + +Shows mails send with flask_mail. diff --git a/flask_debugtoolbar/__init__.py b/flask_debugtoolbar/__init__.py index 80c896d..de7fd4f 100644 --- a/flask_debugtoolbar/__init__.py +++ b/flask_debugtoolbar/__init__.py @@ -99,6 +99,7 @@ def _default_config(self, app): 'flask_debugtoolbar.panels.logger.LoggingPanel', 'flask_debugtoolbar.panels.route_list.RouteListDebugPanel', 'flask_debugtoolbar.panels.profiler.ProfilerDebugPanel', + 'flask_debugtoolbar.panels.mail.MailDebugPanel', ), } diff --git a/flask_debugtoolbar/panels/mail.py b/flask_debugtoolbar/panels/mail.py new file mode 100644 index 0000000..c6c2960 --- /dev/null +++ b/flask_debugtoolbar/panels/mail.py @@ -0,0 +1,78 @@ +from flask import g +from flask_debugtoolbar.panels import DebugPanel +from flask_debugtoolbar import module +import jinja2 + +mails = {} +last_index = 0 + +def _add_mail(message, app): + global mails, last_index + mails.update({last_index: message}) + last_index += 1 + +try: + import flask_mail + flask_mail.email_dispatched.connect(_add_mail) +except: + pass + +@module.route('/mail/remove/', methods=['GET', 'POST']) +def remove_mail(key=None): + global mails + del mails[key] + return "ok" + +@module.route('/mail/remove/all', methods=['GET', 'POST']) +def remove_all_mails(): + global mails + mails = {} + return "ok" + + +class MailDebugPanel(DebugPanel): + """ + Panel that displays the mails send from flask_mail. + """ + name = 'Mail' + + try: # if resource module not available, don't show content panel + flask_mail + except NameError: + has_content = False + has_resource = False + else: + has_content = True + has_resource = True + + def process_request(self, request): + pass + + def process_response(self, request, response): + pass + + def nav_title(self): + return 'Mails' + + def nav_subtitle(self): + if len(mails) == 1: + return '1 Mail' + else: + return '%d Mails' % (len(mails)) + + def title(self): + return 'Mails' + + def url(self): + return '' + + def content(self): + global mails + context = self.context.copy() + context.update({ + 'mails': mails, + }) + + return self.render('panels/mail.html', context) + + diff --git a/flask_debugtoolbar/templates/panels/mail.html b/flask_debugtoolbar/templates/panels/mail.html new file mode 100644 index 0000000..c68cd82 --- /dev/null +++ b/flask_debugtoolbar/templates/panels/mail.html @@ -0,0 +1,118 @@ +remove all + +{% for key, mail in mails.items() %} +
+ +remove + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
VariableValue
subject{{ mail.subject }}
recipients{{ mail.recipients }}
body{{ mail.body }}
html{{ mail.html | safe }}
sender{{ mail.sender }}
cc{{ mail.cc }}
bcc{{ mail.bcc }}
attachments{{ mail.attachments }}
reply_to{{ mail.reply_to }}
date{{ mail.date }}
charset{{ mail.charset }}
extra_headers{{ mail.extra_headers }}
mail_options{{ mail.mail_options }}
rcpt_options{{ mail.rcpt_options }}
+
+{% endfor %} +