Skip to content

Commit

Permalink
Mail changes (#15)
Browse files Browse the repository at this point in the history
* fix bcc/cc mail function, receive exactly one mail

* add Richt Text Editor to mail_body field on notification.html

* remove log entries for testing
  • Loading branch information
urvdp authored Oct 11, 2023
1 parent 1e7223d commit 34f8e45
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Flask==1.1.2
Flask-Assets==2.0
Flask-Babel==2.0.0
Flask-Caching==1.9.0
Flask-ckeditor==0.4.6
Flask-Login==0.5.0
Flask-Mail==0.9.1
Flask-SQLAlchemy==2.4.4
Expand Down
5 changes: 5 additions & 0 deletions src/spz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from flask_caching import Cache
from flask_wtf import CSRFProtect
from flask_babel import Babel
from flask_ckeditor import CKEditor

from jinja2 import Markup

Expand Down Expand Up @@ -125,6 +126,10 @@ def rlrc_comment():
# I18n setup
babel = Babel(app)

# Rich Text Editor setup
ckeditor = CKEditor(app)


# Register all views here
from spz import views, errorhandlers, pdf # NOQA

Expand Down
3 changes: 2 additions & 1 deletion src/spz/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from markupsafe import Markup
from wtforms import widgets, StringField, SelectField, SelectMultipleField, IntegerField, Label
from wtforms import TextAreaField, BooleanField, DecimalField, MultipleFileField
from flask_ckeditor import CKEditorField

from spz import app, models, token

Expand Down Expand Up @@ -472,7 +473,7 @@ class NotificationForm(FlaskForm):
'Betreff',
[validators.Length(1, 200, 'Betreff muss zwischen 1 und 200 Zeichen enthalten')]
)
mail_body = TextAreaField(
mail_body = CKEditorField(
'Nachricht',
[validators.Length(1, 2000, 'Nachricht muss zwischen 1 und 2000 Zeichen enthalten')]
)
Expand Down
4 changes: 4 additions & 0 deletions src/spz/templates/internal/notifications.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


{% block internal_body %}

<div class="row">
<form class="ui form" method="post" id="confirm" enctype="multipart/form-data">
{{ csrf_field() }}
Expand All @@ -33,5 +34,8 @@ <h3 class="ui dividing header"></h3>
</div>
{{ render_submit(submit='Abschicken')}}
</form>
{{ ckeditor.load(pkg_type="standard") }}
{{ ckeditor.config(name='mail_body') }}
</div>

{% endblock internal_body %}
14 changes: 7 additions & 7 deletions src/spz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,22 +702,22 @@ def notifications():
at_name.append(att.filename)

try:
has_sent_cc = False
recipients = form.get_recipients()
for recipient in recipients:
# TODO: fix following code to send email to cc and bcc recipients only once
'''if recipient.index == 0:
cc_cached = None
bcc_cached = None
if not has_sent_cc:
cc_cached = form.get_cc()
bcc_cached = form.get_bcc()
else:
cc_cached = None
bcc_cached = None'''
has_sent_cc = True
msg = Message(
sender=form.get_sender(),
recipients=[recipient],
subject=form.get_subject(),
body=form.get_body(),
cc=form.get_cc(),
bcc=form.get_bcc(),
cc=cc_cached,
bcc=bcc_cached,
charset='utf-8'
)
if form.get_attachments():
Expand Down

0 comments on commit 34f8e45

Please sign in to comment.