Skip to content

Commit

Permalink
spiral-project#869 Fix Invitation Mail
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhgad committed Dec 16, 2021
1 parent a0d13e4 commit f678bbf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 21 deletions.
13 changes: 13 additions & 0 deletions ihatemoney/templates/inv.j2
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions ihatemoney/templates/invitation_mail.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{prediction}}
22 changes: 15 additions & 7 deletions ihatemoney/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
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,
Expand Down Expand Up @@ -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
Expand Down
34 changes: 20 additions & 14 deletions ihatemoney/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
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,
Expand All @@ -48,7 +47,6 @@
MemberForm,
PasswordReminder,
ProjectForm,
ProjectFormWithCaptcha,
ResetPasswordForm,
UploadForm,
get_billform_for,
Expand Down Expand Up @@ -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))
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit f678bbf

Please sign in to comment.