mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
converting to using rendered templates
This commit is contained in:
parent
f4dfe0a9b2
commit
f4cbac34ba
3 changed files with 40 additions and 8 deletions
15
app/templates/email/suggested_topic.html
Normal file
15
app/templates/email/suggested_topic.html
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<p style="margin-bottom: 0;"><a href="https://{{ domain }}/"><img src="https://{{ domain }}/static/images/logo2.png" style="max-width: 100%;" width="50" height="50"></a></p>
|
||||||
|
<p>Hi {{ site_name }} Admin,</p>
|
||||||
|
<p>The user {{ current_user_name }} has suggested the following new Topic:</p>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>Topic Name: </td>
|
||||||
|
<td>{{ topic_name }}</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Communities: </td>
|
||||||
|
<td>{{ communities_for_topic }}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>Thank you for your time and attention.</p>
|
8
app/templates/email/suggested_topic.txt
Normal file
8
app/templates/email/suggested_topic.txt
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Hi {{ site_name }} Admin!
|
||||||
|
|
||||||
|
The user {{ current_user_name }} has suggested the following new Topic:
|
||||||
|
|
||||||
|
Topic Name: {{ topic_name }}
|
||||||
|
Communities: {{ communities_for_topic }}
|
||||||
|
|
||||||
|
Thank you for your time and attention.
|
|
@ -4,6 +4,7 @@ from random import randint
|
||||||
|
|
||||||
from feedgen.feed import FeedGenerator
|
from feedgen.feed import FeedGenerator
|
||||||
from flask import request, flash, json, url_for, current_app, redirect, abort, make_response, g
|
from flask import request, flash, json, url_for, current_app, redirect, abort, make_response, g
|
||||||
|
from flask import render_template as flask_render_template
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from flask_babel import _
|
from flask_babel import _
|
||||||
from sqlalchemy import text, desc, or_
|
from sqlalchemy import text, desc, or_
|
||||||
|
@ -244,14 +245,22 @@ def suggest_topics():
|
||||||
if current_user.created_recently() or current_user.reputation <= -10 or current_user.banned or not current_user.verified:
|
if current_user.created_recently() or current_user.reputation <= -10 or current_user.banned or not current_user.verified:
|
||||||
return redirect(url_for('topic.suggestion_denied'))
|
return redirect(url_for('topic.suggestion_denied'))
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
sub = f'New Topic Suggestion from {g.site.name}'
|
subject = f'New Topic Suggestion from {g.site.name}'
|
||||||
send = f'{g.site.name} <{current_app.config["MAIL_FROM"]}>'
|
sender = f'{g.site.name} <{current_app.config["MAIL_FROM"]}>'
|
||||||
recip = g.site.contact_email
|
recipients = g.site.contact_email
|
||||||
tn = form.topic_name.data
|
topic_name = form.topic_name.data
|
||||||
cft = form.communities_for_topic.data
|
communities_for_topic = form.communities_for_topic.data
|
||||||
text_body = f'{current_user.user_name} suggested the new Topic "{tn}", containing the communities: {cft}'
|
send_email(subject,
|
||||||
html_body = f'<p>{current_user.user_name} suggested the new Topic "{tn}", containing the communities: {cft}</p>'
|
sender,
|
||||||
send_email(sub, send, recip, text_body=text_body, html_body=html_body)
|
recipients,
|
||||||
|
text_body=flask_render_template('email/suggested_topic.txt', site_name=g.site.name,
|
||||||
|
current_user_name=current_user.user_name, topic_name=topic_name,
|
||||||
|
communities_for_topic=communities_for_topic),
|
||||||
|
html_body=flask_render_template('email/suggested_topic.html', site_name=g.site.name,
|
||||||
|
current_user_name=current_user.user_name, topic_name=topic_name,
|
||||||
|
communities_for_topic=communities_for_topic,
|
||||||
|
domain=current_app.config['SERVER_NAME'])
|
||||||
|
)
|
||||||
flash(_(f'Thank you for the Topic Suggestion! Your suggestion has been sent to the site administrator(s)'))
|
flash(_(f'Thank you for the Topic Suggestion! Your suggestion has been sent to the site administrator(s)'))
|
||||||
return redirect(url_for('main.list_topics'))
|
return redirect(url_for('main.list_topics'))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue