From 68fad54bc0f73f394ed8cbb125f8294bcf4780a9 Mon Sep 17 00:00:00 2001 From: seanlu99 Date: Thu, 16 Dec 2021 04:55:58 -0500 Subject: [PATCH] Add functionality to new project creation We did this to provide a more intuitive and customizable project creation experience --- ihatemoney/forms.py | 13 ++++++++++++- ihatemoney/templates/forms.html | 15 +++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 4e241c86..8e2e4abf 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -23,7 +23,7 @@ from wtforms.validators import ( ) from ihatemoney.currency_convertor import CurrencyConverter -from ihatemoney.models import LoggingMode, Person, Project +from ihatemoney.models import LoggingMode, Person, Project, db from ihatemoney.utils import ( eval_arithmetic_expression, render_localized_currency, @@ -196,6 +196,8 @@ class ProjectForm(EditProjectForm): # This field overrides the one from EditProjectForm password = PasswordField(_("Private code"), validators=[DataRequired()]) submit = SubmitField(_("Create the project")) + # Field to create a member for the project + member_name = StringField(_("Your name"), filters=[strip_filter]) def save(self): """Create a new project with the information given by this form. @@ -216,6 +218,15 @@ class ProjectForm(EditProjectForm): logging_preference=self.logging_preference, default_currency=self.default_currency.data, ) + # Check that the member name is not empty so you don't insert an empty + # Person object if no member name is given + if self.member_name.data != "": + # Create a person object and link it to this project + member = Person(project_id=self.id.data, name=self.member_name.data) + # Add the new Person object to the database + db.session.add(member) + # Commit the database changes + db.session.commit() return project def validate_id(form, field): diff --git a/ihatemoney/templates/forms.html b/ihatemoney/templates/forms.html index e6662b76..9c04a154 100644 --- a/ihatemoney/templates/forms.html +++ b/ihatemoney/templates/forms.html @@ -69,12 +69,19 @@ {% include "display_errors.html" %} {{ form.hidden_tag() }} + {% if not home %} - {{ input(form.id) }} + {{ input(form.id, placeholder="Unique ID used to login") }} + {% endif %} + + {{ input(form.name, placeholder="Example: Trip to Paris") }} + {{ input(form.password, placeholder="Password to access project") }} + {{ input(form.contact_email, placeholder="Your email") }} + + {% if not home %} + {{ input(form.member_name, placeholder="(optional) Add your first project member!") }} + {{ input(form.default_currency) }} {% endif %} - {{ input(form.name) }} - {{ input(form.password) }} - {{ input(form.contact_email) }} {% if config['ENABLE_CAPTCHA'] %} {{ input(form.captcha) }} {% endif %}