mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 12:41: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 flask import current_app, escape, redirect, render_template
|
||||
from flask_babel import get_locale, lazy_gettext as _
|
||||
import googletrans
|
||||
import jinja2
|
||||
from markupsafe import Markup
|
||||
from werkzeug.routing import HTTPException, RoutingException
|
||||
|
||||
from googletrans import Translator
|
||||
|
||||
def slugify(value):
|
||||
"""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 language does not exist.
|
||||
"""
|
||||
translator = Translator()
|
||||
fallback = "en"
|
||||
templates = [
|
||||
f"{template_name_prefix}.{lang}.j2"
|
||||
for lang in (get_locale().language, fallback)
|
||||
]
|
||||
lang=(get_locale().language, fallback)[0]
|
||||
with open("ihatemoney/templates/invitation_mail.en.j2") as f:
|
||||
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
|
||||
return render_template(templates, **context)
|
||||
|
||||
return render_template("ihatemoney/templates/inv.j2", prediction = text)
|
||||
|
||||
def format_form_errors(form, prefix):
|
||||
"""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 ihatemoney.currency_convertor import CurrencyConverter
|
||||
from ihatemoney.emails import send_creation_email
|
||||
from ihatemoney.forms import (
|
||||
AdminAuthenticationForm,
|
||||
AuthenticationForm,
|
||||
|
@ -48,7 +47,6 @@ from ihatemoney.forms import (
|
|||
MemberForm,
|
||||
PasswordReminder,
|
||||
ProjectForm,
|
||||
ProjectFormWithCaptcha,
|
||||
ResetPasswordForm,
|
||||
UploadForm,
|
||||
get_billform_for,
|
||||
|
@ -138,9 +136,8 @@ def pull_project(endpoint, values):
|
|||
return
|
||||
if not values:
|
||||
values = {}
|
||||
entered_project_id = values.pop("project_id", None)
|
||||
if entered_project_id:
|
||||
project_id = entered_project_id.lower()
|
||||
project_id = values.pop("project_id", None)
|
||||
if project_id:
|
||||
project = Project.query.get(project_id)
|
||||
if not project:
|
||||
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))
|
||||
|
||||
|
||||
@main.route("/healthcheck", methods=["GET"])
|
||||
def health():
|
||||
return "OK"
|
||||
|
||||
|
||||
@main.route("/admin", methods=["GET", "POST"])
|
||||
def admin():
|
||||
"""Admin authentication.
|
||||
|
@ -233,7 +225,7 @@ def authenticate(project_id=None):
|
|||
|
||||
if not form.id.data and request.args.get("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
|
||||
if not project:
|
||||
|
@ -271,7 +263,8 @@ def authenticate(project_id=None):
|
|||
|
||||
def get_project_form():
|
||||
if current_app.config.get("ENABLE_CAPTCHA", False):
|
||||
return ProjectFormWithCaptcha()
|
||||
ProjectForm.enable_captcha()
|
||||
|
||||
return ProjectForm()
|
||||
|
||||
|
||||
|
@ -326,7 +319,18 @@ def create_project():
|
|||
|
||||
# send reminder email
|
||||
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:
|
||||
flash(
|
||||
_("A reminder email has just been sent to you"), category="success"
|
||||
|
@ -341,6 +345,8 @@ def create_project():
|
|||
),
|
||||
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 render_template("create_project.html", form=form)
|
||||
|
@ -613,7 +619,7 @@ def demo():
|
|||
@main.route("/<project_id>/invite", methods=["GET", "POST"])
|
||||
def invite():
|
||||
"""Send invitations for this particular project"""
|
||||
|
||||
print("anmutign")
|
||||
form = InviteForm()
|
||||
|
||||
if request.method == "POST":
|
||||
|
|
Loading…
Reference in a new issue