Browse Source

fixup! server: Add Aardbei fields to Person

Maarten van den Berg 5 years ago
parent
commit
956a89a289

+ 6 - 6
piket_server/__init__.py

37
     consumptions = db.relationship("Consumption", backref="person", lazy=True)
37
     consumptions = db.relationship("Consumption", backref="person", lazy=True)
38
 
38
 
39
     def __repr__(self) -> str:
39
     def __repr__(self) -> str:
40
-        return f"<Person {self.person_id}: {self.name}>"
40
+        return f"<Person {self.person_id}: {self.full_name}>"
41
 
41
 
42
     @property
42
     @property
43
     def as_dict(self) -> dict:
43
     def as_dict(self) -> dict:
144
                 .filter_by(reversed=False)
144
                 .filter_by(reversed=False)
145
                 .filter_by(consumption_type=c_type)
145
                 .filter_by(consumption_type=c_type)
146
                 .group_by(Consumption.person_id)
146
                 .group_by(Consumption.person_id)
147
-                .order_by(Person.name)
147
+                .order_by(Person.full_name)
148
                 .outerjoin(Person)
148
                 .outerjoin(Person)
149
                 .with_entities(
149
                 .with_entities(
150
                     Person.person_id,
150
                     Person.person_id,
151
-                    Person.name,
151
+                    Person.full_name,
152
                     func.count(Consumption.consumption_id),
152
                     func.count(Consumption.consumption_id),
153
                 )
153
                 )
154
                 .all()
154
                 .all()
205
     reversed = db.Column(db.Boolean, default=False, nullable=False)
205
     reversed = db.Column(db.Boolean, default=False, nullable=False)
206
 
206
 
207
     def __repr__(self) -> str:
207
     def __repr__(self) -> str:
208
-        return f"<Consumption: {self.consumption_type.name} for {self.person.name}>"
208
+        return f"<Consumption: {self.consumption_type.name} for {self.person.full_name}>"
209
 
209
 
210
     @property
210
     @property
211
     def as_dict(self) -> dict:
211
     def as_dict(self) -> dict:
256
 @app.route("/people", methods=["GET"])
256
 @app.route("/people", methods=["GET"])
257
 def get_people():
257
 def get_people():
258
     """ Return a list of currently known people. """
258
     """ Return a list of currently known people. """
259
-    people = Person.query.order_by(Person.name).all()
260
-    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)
261
     if request.args.get("active"):
261
     if request.args.get("active"):
262
         active_status = request.args.get("active", type=int)
262
         active_status = request.args.get("active", type=int)
263
         q = q.filter_by(active=active_status)
263
         q = q.filter_by(active=active_status)

+ 2 - 2
piket_server/alembic/versions/cca57457a0a6_add_aardbei_fields.py

18
 
18
 
19
 def upgrade():
19
 def upgrade():
20
     with op.batch_alter_table("people") as batch_op:
20
     with op.batch_alter_table("people") as batch_op:
21
-        batch_op.alter_column("name", new_name="full_name")
21
+        batch_op.alter_column("name", new_column_name="full_name")
22
         batch_op.add_column(sa.Column("aardbei_id", sa.Integer(), nullable=True))
22
         batch_op.add_column(sa.Column("aardbei_id", sa.Integer(), nullable=True))
23
         batch_op.add_column(sa.Column("display_name", sa.String(), nullable=True))
23
         batch_op.add_column(sa.Column("display_name", sa.String(), nullable=True))
24
 
24
 
25
 
25
 
26
 def downgrade():
26
 def downgrade():
27
     with op.batch_alter_table("people") as batch_op:
27
     with op.batch_alter_table("people") as batch_op:
28
-        batch_op.alter_column("full_name", new_name="name")
28
+        batch_op.alter_column("full_name", new_column_name="name")
29
         batch_op.drop_column("aardbei_id")
29
         batch_op.drop_column("aardbei_id")
30
         batch_op.drop_column("display_name")
30
         batch_op.drop_column("display_name")