diff options
| author | Daniel Atwood <59884378+indatwood@users.noreply.github.com> | 2020-05-24 11:45:34 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-24 11:45:34 +0200 |
| commit | 0fd2958865319983b0c7efed66f702aefdd6184b (patch) | |
| tree | 9d9d9dac99dfd4a7c2cd3624d98f9acb9082d676 /ihatemoney/models.py | |
| parent | 82393a110aa1d240ea8137a96efb66bad65581ac (diff) | |
| download | ihatemoney-mirror-0fd2958865319983b0c7efed66f702aefdd6184b.zip ihatemoney-mirror-0fd2958865319983b0c7efed66f702aefdd6184b.tar.gz ihatemoney-mirror-0fd2958865319983b0c7efed66f702aefdd6184b.tar.bz2 | |
Populate the demo project with defaults. (#616)
Diffstat (limited to 'ihatemoney/models.py')
| -rw-r--r-- | ihatemoney/models.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 9e474c6..fe7b519 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -15,6 +15,7 @@ from sqlalchemy import orm from sqlalchemy.sql import func from sqlalchemy_continuum import make_versioned, version_class from sqlalchemy_continuum.plugins import FlaskPlugin +from werkzeug.security import generate_password_hash from ihatemoney.patch_sqlalchemy_continuum import PatchedBuilder from ihatemoney.versioning import ( @@ -330,6 +331,49 @@ class Project(db.Model): def __repr__(self): return f"<Project {self.name}>" + @staticmethod + def create_demo_project(): + project = Project( + id="demo", + name="demonstration", + password=generate_password_hash("demo"), + contact_email="demo@notmyidea.org", + default_currency="EUR", + ) + db.session.add(project) + db.session.commit() + + members = {} + for name in ("Amina", "Georg", "Alice"): + person = Person() + person.name = name + person.project = project + person.weight = 1 + db.session.add(person) + + members[name] = person + + db.session.commit() + + operations = ( + ("Georg", 200, ("Amina", "Georg", "Alice"), "Food shopping"), + ("Alice", 20, ("Amina", "Alice"), "Beer !"), + ("Amina", 50, ("Amina", "Alice", "Georg"), "AMAP"), + ) + for (payer, amount, owers, subject) in operations: + bill = Bill() + bill.payer_id = members[payer].id + bill.what = subject + bill.owers = [members[name] for name in owers] + bill.amount = amount + bill.original_currency = "EUR" + bill.converted_amount = amount + + db.session.add(bill) + + db.session.commit() + return project + class Person(db.Model): class PersonQuery(BaseQuery): |
