|
@@ -29,20 +29,23 @@ class Person(db.Model):
|
29
|
29
|
__tablename__ = "people"
|
30
|
30
|
|
31
|
31
|
person_id = db.Column(db.Integer, primary_key=True)
|
32
|
|
- name = db.Column(db.String, nullable=False)
|
|
32
|
+ full_name = db.Column(db.String, nullable=False)
|
|
33
|
+ display_name = db.Column(db.String, nullable=True)
|
|
34
|
+ aardbei_id = db.Column(db.Integer, nullable=True)
|
33
|
35
|
active = db.Column(db.Boolean, nullable=False, default=False)
|
34
|
36
|
|
35
|
37
|
consumptions = db.relationship("Consumption", backref="person", lazy=True)
|
36
|
38
|
|
37
|
39
|
def __repr__(self) -> str:
|
38
|
|
- return f"<Person {self.person_id}: {self.name}>"
|
|
40
|
+ return f"<Person {self.person_id}: {self.full_name}>"
|
39
|
41
|
|
40
|
42
|
@property
|
41
|
43
|
def as_dict(self) -> dict:
|
42
|
44
|
return {
|
43
|
45
|
"person_id": self.person_id,
|
44
|
46
|
"active": self.active,
|
45
|
|
- "name": self.name,
|
|
47
|
+ "full_name": self.full_name,
|
|
48
|
+ "display_name": self.display_name,
|
46
|
49
|
"consumptions": {
|
47
|
50
|
ct.consumption_type_id: Consumption.query.filter_by(person=self)
|
48
|
51
|
.filter_by(settlement=None)
|
|
@@ -141,11 +144,11 @@ class Settlement(db.Model):
|
141
|
144
|
.filter_by(reversed=False)
|
142
|
145
|
.filter_by(consumption_type=c_type)
|
143
|
146
|
.group_by(Consumption.person_id)
|
144
|
|
- .order_by(Person.name)
|
|
147
|
+ .order_by(Person.full_name)
|
145
|
148
|
.outerjoin(Person)
|
146
|
149
|
.with_entities(
|
147
|
150
|
Person.person_id,
|
148
|
|
- Person.name,
|
|
151
|
+ Person.full_name,
|
149
|
152
|
func.count(Consumption.consumption_id),
|
150
|
153
|
)
|
151
|
154
|
.all()
|
|
@@ -202,7 +205,7 @@ class Consumption(db.Model):
|
202
|
205
|
reversed = db.Column(db.Boolean, default=False, nullable=False)
|
203
|
206
|
|
204
|
207
|
def __repr__(self) -> str:
|
205
|
|
- return f"<Consumption: {self.consumption_type.name} for {self.person.name}>"
|
|
208
|
+ return f"<Consumption: {self.consumption_type.name} for {self.person.full_name}>"
|
206
|
209
|
|
207
|
210
|
@property
|
208
|
211
|
def as_dict(self) -> dict:
|
|
@@ -253,8 +256,8 @@ def status() -> None:
|
253
|
256
|
@app.route("/people", methods=["GET"])
|
254
|
257
|
def get_people():
|
255
|
258
|
""" Return a list of currently known people. """
|
256
|
|
- people = Person.query.order_by(Person.name).all()
|
257
|
|
- q = Person.query.order_by(Person.name)
|
|
259
|
+ people = Person.query.order_by(Person.full_name).all()
|
|
260
|
+ q = Person.query.order_by(Person.full_name)
|
258
|
261
|
if request.args.get("active"):
|
259
|
262
|
active_status = request.args.get("active", type=int)
|
260
|
263
|
q = q.filter_by(active=active_status)
|