Browse Source

Add settlements create command

Maarten van den Berg 5 years ago
parent
commit
3eef683673
3 changed files with 20 additions and 2 deletions
  1. 18 1
      piket_client/cli.py
  2. 1 0
      piket_server/models.py
  3. 1 1
      piket_server/routes/settlements.py

+ 18 - 1
piket_client/cli.py

56
         print_error(f"Could not get Settlement: {s.value}")
56
         print_error(f"Could not get Settlement: {s.value}")
57
         return
57
         return
58
 
58
 
59
-    click.echo(f"Settlement {settlement_id}, \"{s.name}\"")
59
+    output_settlement_info(s)
60
+
61
+
62
+@settlements.command("create")
63
+@click.argument("name")
64
+def create_settlement(name: str) -> None:
65
+    """Create a new Settlement."""
66
+    s = Settlement.create(name)
67
+
68
+    if isinstance(s, NetworkError):
69
+        print_error(f"Could not create Settlement: {s.value}")
70
+        return
71
+
72
+    output_settlement_info(s)
73
+
74
+
75
+def output_settlement_info(s: Settlement) -> None:
76
+    click.echo(f'Settlement {s.settlement_id}, "{s.name}"')
60
 
77
 
61
     click.echo(f"Summary:")
78
     click.echo(f"Summary:")
62
     for key, value in s.consumption_summary.items():
79
     for key, value in s.consumption_summary.items():

+ 1 - 0
piket_server/models.py

89
             "consumption_summary": self.consumption_summary,
89
             "consumption_summary": self.consumption_summary,
90
             "unique_people": self.unique_people,
90
             "unique_people": self.unique_people,
91
             "per_person_counts": self.per_person_counts,
91
             "per_person_counts": self.per_person_counts,
92
+            "count_info": self.per_person,
92
         }
93
         }
93
 
94
 
94
     @property
95
     @property

+ 1 - 1
piket_server/routes/settlements.py

46
 
46
 
47
     db.session.commit()
47
     db.session.commit()
48
 
48
 
49
-    return jsonify(settlement=s.as_dict)
49
+    return jsonify(settlement=s.as_dict, count_info=s.per_person)