mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 12:41:49 +02:00
Add functionality to new project creation
We did this to provide a more intuitive and customizable project creation experience
This commit is contained in:
parent
a0d13e4081
commit
68fad54bc0
2 changed files with 23 additions and 5 deletions
|
@ -23,7 +23,7 @@ from wtforms.validators import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from ihatemoney.currency_convertor import CurrencyConverter
|
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 (
|
from ihatemoney.utils import (
|
||||||
eval_arithmetic_expression,
|
eval_arithmetic_expression,
|
||||||
render_localized_currency,
|
render_localized_currency,
|
||||||
|
@ -196,6 +196,8 @@ class ProjectForm(EditProjectForm):
|
||||||
# This field overrides the one from EditProjectForm
|
# This field overrides the one from EditProjectForm
|
||||||
password = PasswordField(_("Private code"), validators=[DataRequired()])
|
password = PasswordField(_("Private code"), validators=[DataRequired()])
|
||||||
submit = SubmitField(_("Create the project"))
|
submit = SubmitField(_("Create the project"))
|
||||||
|
# Field to create a member for the project
|
||||||
|
member_name = StringField(_("Your name"), filters=[strip_filter])
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Create a new project with the information given by this form.
|
"""Create a new project with the information given by this form.
|
||||||
|
@ -216,6 +218,15 @@ class ProjectForm(EditProjectForm):
|
||||||
logging_preference=self.logging_preference,
|
logging_preference=self.logging_preference,
|
||||||
default_currency=self.default_currency.data,
|
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
|
return project
|
||||||
|
|
||||||
def validate_id(form, field):
|
def validate_id(form, field):
|
||||||
|
|
|
@ -69,12 +69,19 @@
|
||||||
|
|
||||||
{% include "display_errors.html" %}
|
{% include "display_errors.html" %}
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
|
<!-- Only display private code if not home page -->
|
||||||
{% if not home %}
|
{% if not home %}
|
||||||
{{ input(form.id) }}
|
{{ input(form.id, placeholder="Unique ID used to login") }}
|
||||||
|
{% endif %}
|
||||||
|
<!-- Fields that are always shown -->
|
||||||
|
{{ input(form.name, placeholder="Example: Trip to Paris") }}
|
||||||
|
{{ input(form.password, placeholder="Password to access project") }}
|
||||||
|
{{ input(form.contact_email, placeholder="Your email") }}
|
||||||
|
<!-- Only display member name and default currency if not home page -->
|
||||||
|
{% if not home %}
|
||||||
|
{{ input(form.member_name, placeholder="(optional) Add your first project member!") }}
|
||||||
|
{{ input(form.default_currency) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ input(form.name) }}
|
|
||||||
{{ input(form.password) }}
|
|
||||||
{{ input(form.contact_email) }}
|
|
||||||
{% if config['ENABLE_CAPTCHA'] %}
|
{% if config['ENABLE_CAPTCHA'] %}
|
||||||
{{ input(form.captcha) }}
|
{{ input(form.captcha) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue