Browse Source

server: Black

Maarten van den Berg 2 months ago
parent
commit
9e756ac796
1 changed files with 21 additions and 21 deletions
  1. 21 21
      piket_server/__init__.py

+ 21 - 21
piket_server/__init__.py

25
 
25
 
26
 # ---------- Models ----------
26
 # ---------- Models ----------
27
 class Person(db.Model):
27
 class Person(db.Model):
28
-    """ Represents a person to be shown on the lists. """
28
+    """Represents a person to be shown on the lists."""
29
 
29
 
30
     __tablename__ = "people"
30
     __tablename__ = "people"
31
 
31
 
56
 
56
 
57
 
57
 
58
 class Export(db.Model):
58
 class Export(db.Model):
59
-    """ Represents a set of exported Settlements. """
59
+    """Represents a set of exported Settlements."""
60
 
60
 
61
     __tablename__ = "exports"
61
     __tablename__ = "exports"
62
 
62
 
77
 
77
 
78
 
78
 
79
 class Settlement(db.Model):
79
 class Settlement(db.Model):
80
-    """ Represents a settlement of the list. """
80
+    """Represents a settlement of the list."""
81
 
81
 
82
     __tablename__ = "settlements"
82
     __tablename__ = "settlements"
83
 
83
 
159
 
159
 
160
 
160
 
161
 class ConsumptionType(db.Model):
161
 class ConsumptionType(db.Model):
162
-    """ Represents a type of consumption to be counted. """
162
+    """Represents a type of consumption to be counted."""
163
 
163
 
164
     __tablename__ = "consumption_types"
164
     __tablename__ = "consumption_types"
165
 
165
 
183
 
183
 
184
 
184
 
185
 class Consumption(db.Model):
185
 class Consumption(db.Model):
186
-    """ Represent one consumption to be counted. """
186
+    """Represent one consumption to be counted."""
187
 
187
 
188
     __tablename__ = "consumptions"
188
     __tablename__ = "consumptions"
189
 
189
 
222
 
222
 
223
 @app.route("/ping")
223
 @app.route("/ping")
224
 def ping() -> None:
224
 def ping() -> None:
225
-    """ Return a status ping. """
225
+    """Return a status ping."""
226
     return "Pong"
226
     return "Pong"
227
 
227
 
228
 
228
 
229
 @app.route("/status")
229
 @app.route("/status")
230
 def status() -> None:
230
 def status() -> None:
231
-    """ Return a status dict with info about the database. """
231
+    """Return a status dict with info about the database."""
232
     unsettled_q = Consumption.query.filter_by(settlement=None).filter_by(reversed=False)
232
     unsettled_q = Consumption.query.filter_by(settlement=None).filter_by(reversed=False)
233
 
233
 
234
     unsettled = unsettled_q.count()
234
     unsettled = unsettled_q.count()
253
 # Person
253
 # Person
254
 @app.route("/people", methods=["GET"])
254
 @app.route("/people", methods=["GET"])
255
 def get_people():
255
 def get_people():
256
-    """ Return a list of currently known people. """
256
+    """Return a list of currently known people."""
257
     q = Person.query.order_by(Person.name)
257
     q = Person.query.order_by(Person.name)
258
     if request.args.get("active"):
258
     if request.args.get("active"):
259
         active_status = request.args.get("active", type=int)
259
         active_status = request.args.get("active", type=int)
261
     people = q.all()
261
     people = q.all()
262
 
262
 
263
     engine = db.get_engine()
263
     engine = db.get_engine()
264
-    query = '''
264
+    query = """
265
         SELECT
265
         SELECT
266
             consumptions.person_id,
266
             consumptions.person_id,
267
             consumptions.consumption_type_id,
267
             consumptions.consumption_type_id,
273
             consumptions.settlement_id IS NULL
273
             consumptions.settlement_id IS NULL
274
             AND consumptions.reversed = 0
274
             AND consumptions.reversed = 0
275
         GROUP BY consumptions.person_id, consumptions.consumption_type_id;
275
         GROUP BY consumptions.person_id, consumptions.consumption_type_id;
276
-    '''
276
+    """
277
     raw_counts = engine.execute(query)
277
     raw_counts = engine.execute(query)
278
 
278
 
279
-    counts: 'Dict[int, Dict[str, int]]' = defaultdict(dict)
279
+    counts: "Dict[int, Dict[str, int]]" = defaultdict(dict)
280
     for person_id, consumption_type_id, count in raw_counts:
280
     for person_id, consumption_type_id, count in raw_counts:
281
         counts[person_id][str(consumption_type_id)] = count
281
         counts[person_id][str(consumption_type_id)] = count
282
 
282
 
285
             "name": person.name,
285
             "name": person.name,
286
             "active": person.active,
286
             "active": person.active,
287
             "person_id": person.person_id,
287
             "person_id": person.person_id,
288
-            "consumptions": counts[person.person_id]
288
+            "consumptions": counts[person.person_id],
289
         }
289
         }
290
         for person in people
290
         for person in people
291
     ]
291
     ]
381
 
381
 
382
 @app.route("/consumptions/<int:consumption_id>", methods=["DELETE"])
382
 @app.route("/consumptions/<int:consumption_id>", methods=["DELETE"])
383
 def reverse_consumption(consumption_id: int):
383
 def reverse_consumption(consumption_id: int):
384
-    """ Reverse a consumption. """
384
+    """Reverse a consumption."""
385
     consumption = Consumption.query.get_or_404(consumption_id)
385
     consumption = Consumption.query.get_or_404(consumption_id)
386
 
386
 
387
     if consumption.reversed:
387
     if consumption.reversed:
409
 # ConsumptionType
409
 # ConsumptionType
410
 @app.route("/consumption_types", methods=["GET"])
410
 @app.route("/consumption_types", methods=["GET"])
411
 def get_consumption_types():
411
 def get_consumption_types():
412
-    """ Return a list of currently active consumption types. """
412
+    """Return a list of currently active consumption types."""
413
     ctypes = ConsumptionType.query.filter_by(active=True).all()
413
     ctypes = ConsumptionType.query.filter_by(active=True).all()
414
     result = [ct.as_dict for ct in ctypes]
414
     result = [ct.as_dict for ct in ctypes]
415
     return jsonify(consumption_types=result)
415
     return jsonify(consumption_types=result)
424
 
424
 
425
 @app.route("/consumption_types", methods=["POST"])
425
 @app.route("/consumption_types", methods=["POST"])
426
 def add_consumption_type():
426
 def add_consumption_type():
427
-    """ Add a new ConsumptionType.  """
427
+    """Add a new ConsumptionType."""
428
     json = request.get_json()
428
     json = request.get_json()
429
 
429
 
430
     if not json:
430
     if not json:
445
 # Settlement
445
 # Settlement
446
 @app.route("/settlements", methods=["GET"])
446
 @app.route("/settlements", methods=["GET"])
447
 def get_settlements():
447
 def get_settlements():
448
-    """ Return a list of the active Settlements. """
448
+    """Return a list of the active Settlements."""
449
     result = Settlement.query.all()
449
     result = Settlement.query.all()
450
     return jsonify(settlements=[s.as_dict for s in result])
450
     return jsonify(settlements=[s.as_dict for s in result])
451
 
451
 
452
 
452
 
453
 @app.route("/settlements/<int:settlement_id>", methods=["GET"])
453
 @app.route("/settlements/<int:settlement_id>", methods=["GET"])
454
 def get_settlement(settlement_id: int):
454
 def get_settlement(settlement_id: int):
455
-    """ Show full details for a single Settlement. """
455
+    """Show full details for a single Settlement."""
456
     s = Settlement.query.get_or_404(settlement_id)
456
     s = Settlement.query.get_or_404(settlement_id)
457
 
457
 
458
     per_person = s.per_person
458
     per_person = s.per_person
462
 
462
 
463
 @app.route("/settlements", methods=["POST"])
463
 @app.route("/settlements", methods=["POST"])
464
 def add_settlement():
464
 def add_settlement():
465
-    """ Create a Settlement, and link all un-settled Consumptions to it. """
465
+    """Create a Settlement, and link all un-settled Consumptions to it."""
466
     json = request.get_json()
466
     json = request.get_json()
467
 
467
 
468
     if not json:
468
     if not json:
486
 # Export
486
 # Export
487
 @app.route("/exports", methods=["GET"])
487
 @app.route("/exports", methods=["GET"])
488
 def get_exports():
488
 def get_exports():
489
-    """ Return a list of the created Exports. """
489
+    """Return a list of the created Exports."""
490
     result = Export.query.all()
490
     result = Export.query.all()
491
     return jsonify(exports=[e.as_dict for e in result])
491
     return jsonify(exports=[e.as_dict for e in result])
492
 
492
 
493
 
493
 
494
 @app.route("/exports/<int:export_id>", methods=["GET"])
494
 @app.route("/exports/<int:export_id>", methods=["GET"])
495
 def get_export(export_id: int):
495
 def get_export(export_id: int):
496
-    """ Return an overview for the given Export. """
496
+    """Return an overview for the given Export."""
497
     e = Export.query.get_or_404(export_id)
497
     e = Export.query.get_or_404(export_id)
498
 
498
 
499
     ss = [s.as_dict for s in e.settlements]
499
     ss = [s.as_dict for s in e.settlements]
503
 
503
 
504
 @app.route("/exports", methods=["POST"])
504
 @app.route("/exports", methods=["POST"])
505
 def add_export():
505
 def add_export():
506
-    """ Create an Export, and link all un-exported Settlements to it. """
506
+    """Create an Export, and link all un-exported Settlements to it."""
507
     # Assert that there are Settlements to be exported.
507
     # Assert that there are Settlements to be exported.
508
     s_count = Settlement.query.filter_by(export=None).count()
508
     s_count = Settlement.query.filter_by(export=None).count()
509
     if s_count == 0:
509
     if s_count == 0: