1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

Users are deleted when no bill is assigned to them. Fixes #5

This commit is contained in:
Frédéric Sureau 2011-08-09 19:34:46 +02:00
parent cb05727ec3
commit 0e5bab13af
2 changed files with 16 additions and 3 deletions

View file

@ -48,6 +48,14 @@ class Person(db.Model):
name = db.Column(db.UnicodeText)
activated = db.Column(db.Boolean, default=True)
def is_used(self):
bills_as_ower_number = db.session.query(Bill).join(billowers, Person)\
.filter("Bill.id == billowers.bill_id")\
.filter("Person.id == billowers.person_id")\
.filter(Person.id == self.id)\
.count()
return bills_as_ower_number != 0 or len(self.bills) != 0
def __str__(self):
return self.name

View file

@ -134,9 +134,14 @@ def add_member(project):
def remove_member(project, member_id):
person = Person.query.get_or_404(member_id)
if person.project == project:
person.activated = False
db.session.commit()
flash("%s has been removed" % person.name)
if not person.is_used():
db.session.delete(person)
db.session.commit()
flash("User '%s' has been removed" % person.name)
else:
person.activated = False
db.session.commit()
flash("User '%s' has been desactivated" % person.name)
return redirect(url_for("list_bills", project_id=project.id))
@app.route("/<string:project_id>/add", methods=["GET", "POST"])