mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
Added member edit form
This commit is contained in:
parent
64c2cd56df
commit
ec8fe2326b
6 changed files with 60 additions and 6 deletions
|
@ -155,16 +155,18 @@ class MemberForm(Form):
|
||||||
weight = CommaDecimalField(_("Weight"), default=1)
|
weight = CommaDecimalField(_("Weight"), default=1)
|
||||||
submit = SubmitField(_("Add"))
|
submit = SubmitField(_("Add"))
|
||||||
|
|
||||||
def __init__(self, project, *args, **kwargs):
|
def __init__(self, project, edit=False, *args, **kwargs):
|
||||||
super(MemberForm, self).__init__(*args, **kwargs)
|
super(MemberForm, self).__init__(*args, **kwargs)
|
||||||
self.project = project
|
self.project = project
|
||||||
|
self.edit = edit
|
||||||
|
|
||||||
def validate_name(form, field):
|
def validate_name(form, field):
|
||||||
if field.data == form.name.default:
|
if field.data == form.name.default:
|
||||||
raise ValidationError(_("User name incorrect"))
|
raise ValidationError(_("User name incorrect"))
|
||||||
if Person.query.filter(Person.name == field.data)\
|
if (not form.edit and Person.query.filter(
|
||||||
.filter(Person.project == form.project)\
|
Person.name == field.data,
|
||||||
.filter(Person.activated == True).all():
|
Person.project == form.project,
|
||||||
|
Person.activated == True).all()):
|
||||||
raise ValidationError(_("This project already have this member"))
|
raise ValidationError(_("This project already have this member"))
|
||||||
|
|
||||||
def save(self, project, person):
|
def save(self, project, person):
|
||||||
|
@ -175,6 +177,10 @@ class MemberForm(Form):
|
||||||
|
|
||||||
return person
|
return person
|
||||||
|
|
||||||
|
def fill(self, member):
|
||||||
|
self.name.data = member.name
|
||||||
|
self.weight.data = member.weight
|
||||||
|
|
||||||
|
|
||||||
class InviteForm(Form):
|
class InviteForm(Form):
|
||||||
emails = TextAreaField(_("People to notify"))
|
emails = TextAreaField(_("People to notify"))
|
||||||
|
|
|
@ -217,4 +217,3 @@ tr.payer_line .balance-name{
|
||||||
.row-fluid > .offset3{margin-left:25.5%;}
|
.row-fluid > .offset3{margin-left:25.5%;}
|
||||||
.row-fluid > .offset2{margin-left:17%;}
|
.row-fluid > .offset2{margin-left:17%;}
|
||||||
.row-fluid > .offset1{margin-left:8.5%;}
|
.row-fluid > .offset1{margin-left:8.5%;}
|
||||||
|
|
||||||
|
|
17
budget/templates/edit_member.html
Normal file
17
budget/templates/edit_member.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
{% extends "layout.html" %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
$('#cancel-form').click(function(){location.href={{ url_for(".list_bills") }};});
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block top_menu %}
|
||||||
|
<a href="{{ url_for(".list_bills") }}">{{ _("Back to the list") }}</a>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<form class="form-horizontal" method="post">
|
||||||
|
{{ forms.edit_member(form, edit) }}
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -95,6 +95,20 @@
|
||||||
{{ form.name(placeholder=_("Type user name here")) }}<button class="btn">{{ _("Add") }}</button>
|
{{ form.name(placeholder=_("Type user name here")) }}<button class="btn">{{ _("Add") }}</button>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro edit_member(form, title=True) %}
|
||||||
|
<fieldset>
|
||||||
|
{% if title %}<legend>{{ _("Edit this member") }}</legend>{% endif %}
|
||||||
|
{% include "display_errors.html" %}
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{{ input(form.name) }}
|
||||||
|
{{ input(form.weight) }}
|
||||||
|
</fieldset>
|
||||||
|
<div class="actions">
|
||||||
|
{{ form.submit(class="btn btn-primary") }}
|
||||||
|
</div>
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
{% macro invites(form) %}
|
{% macro invites(form) %}
|
||||||
{{ form.hidden_tag() }}
|
{{ form.hidden_tag() }}
|
||||||
{{ input(form.emails) }}
|
{{ input(form.emails) }}
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
<td>
|
<td>
|
||||||
<form class="action delete" action="{{ url_for(".remove_member", member_id=member.id) }}" method="POST">
|
<form class="action delete" action="{{ url_for(".remove_member", member_id=member.id) }}" method="POST">
|
||||||
<button type="submit">{{ _("delete") }}</button></form>
|
<button type="submit">{{ _("delete") }}</button></form>
|
||||||
<form class="action edit" action="{{ url_for(".edit_member", member_id=member.id) }}" method="POST">
|
<form class="action edit" action="{{ url_for(".edit_member", member_id=member.id) }}" method="GET">
|
||||||
<button type="submit">{{ _("edit") }}</button></form>
|
<button type="submit">{{ _("edit") }}</button></form>
|
||||||
</td>
|
</td>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -322,6 +322,24 @@ def remove_member(member_id):
|
||||||
return redirect(url_for(".list_bills"))
|
return redirect(url_for(".list_bills"))
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/<project_id>/members/<member_id>/edit",
|
||||||
|
methods=["POST", "GET"])
|
||||||
|
def edit_member(member_id):
|
||||||
|
member = Person.query.get(member_id, g.project)
|
||||||
|
if not member:
|
||||||
|
raise werkzeug.exceptions.NotFound()
|
||||||
|
form = MemberForm(g.project, edit=True)
|
||||||
|
|
||||||
|
if request.method == 'POST' and form.validate():
|
||||||
|
form.save(g.project, member)
|
||||||
|
db.session.commit()
|
||||||
|
flash(_("User '%(name)s' has been edited", name=member.name))
|
||||||
|
return redirect(url_for(".list_bills"))
|
||||||
|
|
||||||
|
form.fill(member)
|
||||||
|
return render_template("edit_member.html", form=form, edit=True)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/<project_id>/add", methods=["GET", "POST"])
|
@main.route("/<project_id>/add", methods=["GET", "POST"])
|
||||||
def add_bill():
|
def add_bill():
|
||||||
form = get_billform_for(g.project)
|
form = get_billform_for(g.project)
|
||||||
|
|
Loading…
Reference in a new issue