1
0
Fork 0
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:
Jocelyn Delande 2015-08-22 01:19:27 +02:00
parent 64c2cd56df
commit ec8fe2326b
6 changed files with 60 additions and 6 deletions

View file

@ -155,16 +155,18 @@ class MemberForm(Form):
weight = CommaDecimalField(_("Weight"), default=1)
submit = SubmitField(_("Add"))
def __init__(self, project, *args, **kwargs):
def __init__(self, project, edit=False, *args, **kwargs):
super(MemberForm, self).__init__(*args, **kwargs)
self.project = project
self.edit = edit
def validate_name(form, field):
if field.data == form.name.default:
raise ValidationError(_("User name incorrect"))
if Person.query.filter(Person.name == field.data)\
.filter(Person.project == form.project)\
.filter(Person.activated == True).all():
if (not form.edit and Person.query.filter(
Person.name == field.data,
Person.project == form.project,
Person.activated == True).all()):
raise ValidationError(_("This project already have this member"))
def save(self, project, person):
@ -175,6 +177,10 @@ class MemberForm(Form):
return person
def fill(self, member):
self.name.data = member.name
self.weight.data = member.weight
class InviteForm(Form):
emails = TextAreaField(_("People to notify"))

View file

@ -217,4 +217,3 @@ tr.payer_line .balance-name{
.row-fluid > .offset3{margin-left:25.5%;}
.row-fluid > .offset2{margin-left:17%;}
.row-fluid > .offset1{margin-left:8.5%;}

View 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 %}

View file

@ -95,6 +95,20 @@
{{ form.name(placeholder=_("Type user name here")) }}<button class="btn">{{ _("Add") }}</button>
{% 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) %}
{{ form.hidden_tag() }}
{{ input(form.emails) }}

View file

@ -72,7 +72,7 @@
<td>
<form class="action delete" action="{{ url_for(".remove_member", member_id=member.id) }}" method="POST">
<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>
</td>
{% else %}

View file

@ -322,6 +322,24 @@ def remove_member(member_id):
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"])
def add_bill():
form = get_billform_for(g.project)