mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 20:51:49 +02:00
#869 Fix Invitation Mail
This commit is contained in:
parent
a0d13e4081
commit
f678bbf582
4 changed files with 49 additions and 21 deletions
13
ihatemoney/templates/inv.j2
Normal file
13
ihatemoney/templates/inv.j2
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
Salut,
|
||||||
|
|
||||||
|
Quelqu'un à l'aide de l'adresse e-mail {{g.project.contact_email}} vous a invité à partager vos dépenses pour "{{g.project.name}}".
|
||||||
|
|
||||||
|
C'est aussi simple que de dire ce que vous avez payé, pour qui et combien cela vous a-t-il coûté, nous nous soucions du reste.
|
||||||
|
|
||||||
|
Vous pouvez vous connecter à l'aide de ce lien: {{url_for (". Join_project", _external = true, project_id = g.project.id, jeton = g.project.generate_Token ())}}.
|
||||||
|
|
||||||
|
Une fois connecté, vous pouvez utiliser le lien suivant qui est plus facile à retenir: {{url_for (". List_bills", _external = true)}}
|
||||||
|
Si votre cookie est supprimé ou si vous vous déconnectez, vous devrez vous reconnecter à l'aide du premier lien.
|
||||||
|
|
||||||
|
Prendre plaisir,
|
||||||
|
À bientôt :-)
|
1
ihatemoney/templates/invitation_mail.j2
Normal file
1
ihatemoney/templates/invitation_mail.j2
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{prediction}}
|
|
@ -14,10 +14,11 @@ from babel import Locale
|
||||||
from babel.numbers import get_currency_name, get_currency_symbol
|
from babel.numbers import get_currency_name, get_currency_symbol
|
||||||
from flask import current_app, escape, redirect, render_template
|
from flask import current_app, escape, redirect, render_template
|
||||||
from flask_babel import get_locale, lazy_gettext as _
|
from flask_babel import get_locale, lazy_gettext as _
|
||||||
|
import googletrans
|
||||||
import jinja2
|
import jinja2
|
||||||
from markupsafe import Markup
|
from markupsafe import Markup
|
||||||
from werkzeug.routing import HTTPException, RoutingException
|
from werkzeug.routing import HTTPException, RoutingException
|
||||||
|
from googletrans import Translator
|
||||||
|
|
||||||
def slugify(value):
|
def slugify(value):
|
||||||
"""Normalizes string, converts to lowercase, removes non-alpha characters,
|
"""Normalizes string, converts to lowercase, removes non-alpha characters,
|
||||||
|
@ -389,14 +390,21 @@ def render_localized_template(template_name_prefix, **context):
|
||||||
current user language. Fallback to English if a template for the
|
current user language. Fallback to English if a template for the
|
||||||
current language does not exist.
|
current language does not exist.
|
||||||
"""
|
"""
|
||||||
|
translator = Translator()
|
||||||
fallback = "en"
|
fallback = "en"
|
||||||
templates = [
|
lang=(get_locale().language, fallback)[0]
|
||||||
f"{template_name_prefix}.{lang}.j2"
|
with open("ihatemoney/templates/invitation_mail.en.j2") as f:
|
||||||
for lang in (get_locale().language, fallback)
|
contents = ""
|
||||||
]
|
for line in f.readlines():
|
||||||
|
contents += line
|
||||||
|
text_to_translate = translator.translate(text=contents, src=fallback, dest = lang)
|
||||||
|
text = text_to_translate.text
|
||||||
|
with open("ihatemoney/templates/inv.j2", "r+") as f:
|
||||||
|
f.seek(0)
|
||||||
|
f.write(text)
|
||||||
|
f.truncate()
|
||||||
# render_template() supports a list of templates to try in order
|
# render_template() supports a list of templates to try in order
|
||||||
return render_template(templates, **context)
|
return render_template("ihatemoney/templates/inv.j2", prediction = text)
|
||||||
|
|
||||||
|
|
||||||
def format_form_errors(form, prefix):
|
def format_form_errors(form, prefix):
|
||||||
"""Format all form errors into a single string, with a string prefix in
|
"""Format all form errors into a single string, with a string prefix in
|
||||||
|
|
|
@ -37,7 +37,6 @@ from werkzeug.exceptions import NotFound
|
||||||
from werkzeug.security import check_password_hash, generate_password_hash
|
from werkzeug.security import check_password_hash, generate_password_hash
|
||||||
|
|
||||||
from ihatemoney.currency_convertor import CurrencyConverter
|
from ihatemoney.currency_convertor import CurrencyConverter
|
||||||
from ihatemoney.emails import send_creation_email
|
|
||||||
from ihatemoney.forms import (
|
from ihatemoney.forms import (
|
||||||
AdminAuthenticationForm,
|
AdminAuthenticationForm,
|
||||||
AuthenticationForm,
|
AuthenticationForm,
|
||||||
|
@ -48,7 +47,6 @@ from ihatemoney.forms import (
|
||||||
MemberForm,
|
MemberForm,
|
||||||
PasswordReminder,
|
PasswordReminder,
|
||||||
ProjectForm,
|
ProjectForm,
|
||||||
ProjectFormWithCaptcha,
|
|
||||||
ResetPasswordForm,
|
ResetPasswordForm,
|
||||||
UploadForm,
|
UploadForm,
|
||||||
get_billform_for,
|
get_billform_for,
|
||||||
|
@ -138,9 +136,8 @@ def pull_project(endpoint, values):
|
||||||
return
|
return
|
||||||
if not values:
|
if not values:
|
||||||
values = {}
|
values = {}
|
||||||
entered_project_id = values.pop("project_id", None)
|
project_id = values.pop("project_id", None)
|
||||||
if entered_project_id:
|
if project_id:
|
||||||
project_id = entered_project_id.lower()
|
|
||||||
project = Project.query.get(project_id)
|
project = Project.query.get(project_id)
|
||||||
if not project:
|
if not project:
|
||||||
raise Redirect303(url_for(".create_project", project_id=project_id))
|
raise Redirect303(url_for(".create_project", project_id=project_id))
|
||||||
|
@ -155,11 +152,6 @@ def pull_project(endpoint, values):
|
||||||
raise Redirect303(url_for(".authenticate", project_id=project_id))
|
raise Redirect303(url_for(".authenticate", project_id=project_id))
|
||||||
|
|
||||||
|
|
||||||
@main.route("/healthcheck", methods=["GET"])
|
|
||||||
def health():
|
|
||||||
return "OK"
|
|
||||||
|
|
||||||
|
|
||||||
@main.route("/admin", methods=["GET", "POST"])
|
@main.route("/admin", methods=["GET", "POST"])
|
||||||
def admin():
|
def admin():
|
||||||
"""Admin authentication.
|
"""Admin authentication.
|
||||||
|
@ -233,7 +225,7 @@ def authenticate(project_id=None):
|
||||||
|
|
||||||
if not form.id.data and request.args.get("project_id"):
|
if not form.id.data and request.args.get("project_id"):
|
||||||
form.id.data = request.args["project_id"]
|
form.id.data = request.args["project_id"]
|
||||||
project_id = form.id.data.lower() if form.id.data else None
|
project_id = form.id.data
|
||||||
|
|
||||||
project = Project.query.get(project_id) if project_id is not None else None
|
project = Project.query.get(project_id) if project_id is not None else None
|
||||||
if not project:
|
if not project:
|
||||||
|
@ -271,7 +263,8 @@ def authenticate(project_id=None):
|
||||||
|
|
||||||
def get_project_form():
|
def get_project_form():
|
||||||
if current_app.config.get("ENABLE_CAPTCHA", False):
|
if current_app.config.get("ENABLE_CAPTCHA", False):
|
||||||
return ProjectFormWithCaptcha()
|
ProjectForm.enable_captcha()
|
||||||
|
|
||||||
return ProjectForm()
|
return ProjectForm()
|
||||||
|
|
||||||
|
|
||||||
|
@ -326,7 +319,18 @@ def create_project():
|
||||||
|
|
||||||
# send reminder email
|
# send reminder email
|
||||||
g.project = project
|
g.project = project
|
||||||
success = send_creation_email(project)
|
|
||||||
|
message_title = _(
|
||||||
|
"You have just created '%(project)s' " "to share your expenses",
|
||||||
|
project=g.project.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
message_body = render_localized_template("reminder_mail")
|
||||||
|
|
||||||
|
msg = Message(
|
||||||
|
message_title, body=message_body, recipients=[project.contact_email]
|
||||||
|
)
|
||||||
|
success = send_email(msg)
|
||||||
if success:
|
if success:
|
||||||
flash(
|
flash(
|
||||||
_("A reminder email has just been sent to you"), category="success"
|
_("A reminder email has just been sent to you"), category="success"
|
||||||
|
@ -341,6 +345,8 @@ def create_project():
|
||||||
),
|
),
|
||||||
category="info",
|
category="info",
|
||||||
)
|
)
|
||||||
|
# redirect the user to the next step (invite)
|
||||||
|
flash(_("The project identifier is %(project)s", project=project.id))
|
||||||
return redirect(url_for(".list_bills", project_id=project.id))
|
return redirect(url_for(".list_bills", project_id=project.id))
|
||||||
|
|
||||||
return render_template("create_project.html", form=form)
|
return render_template("create_project.html", form=form)
|
||||||
|
@ -613,7 +619,7 @@ def demo():
|
||||||
@main.route("/<project_id>/invite", methods=["GET", "POST"])
|
@main.route("/<project_id>/invite", methods=["GET", "POST"])
|
||||||
def invite():
|
def invite():
|
||||||
"""Send invitations for this particular project"""
|
"""Send invitations for this particular project"""
|
||||||
|
print("anmutign")
|
||||||
form = InviteForm()
|
form = InviteForm()
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
|
Loading…
Reference in a new issue