This is an automated email from the ASF dual-hosted git repository.

gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit a49490787ba8f97fda8a79cf16b54152ac74c954
Author: Greg Stein <[email protected]>
AuthorDate: Sun May 29 20:33:36 2022 -0500

    clarify states. add is_editable().
---
 v3/schema.sql        | 16 +++++++++++++++-
 v3/steve/election.py | 11 ++++++++---
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/v3/schema.sql b/v3/schema.sql
index 73b12a9..be57aba 100644
--- a/v3/schema.sql
+++ b/v3/schema.sql
@@ -25,7 +25,21 @@
 /* --------------------------------------------------------------------- */
 
 /* Various metadata about the Election contained in this database.
-   Only one row will exist.  */
+   Only one row will exist.
+
+   An Election has three states:
+
+     1. Editable. The election is being set up. Issues and voters of
+        record can be added, edited, and deleted. The Election's title
+        may be changed (EID is fixed, however).
+        DEFINITION: salt and opened_key are NULL. closed is n/a.
+
+     2. Open. The election is now open for voting.
+        DEFINITION: salt and opened_key are NOT NULL. closed is n/a.
+
+     3. Closed. The election is closed.
+        DEFINITION: salt and opened_key are NOT NULL. closed is 1.
+*/
 CREATE TABLE METADATA (
 
     /* The Election ID. This value might be replicated in the
diff --git a/v3/steve/election.py b/v3/steve/election.py
index 2d8aa1c..3e3c281 100644
--- a/v3/steve/election.py
+++ b/v3/steve/election.py
@@ -51,9 +51,9 @@ class Election:
             'SELECT * FROM RECORD ORDER BY rid')
 
     def open(self):
-        # Double-check that the election is not already open.
-        md = self.q_metadata.first_row()
-        assert md.salt is None and md.opened_key is None
+
+        # Double-check the election is in the editing state.
+        assert self.is_editable()
 
         edata = self.gather_election_data()
         print('EDATA:', edata)
@@ -132,6 +132,11 @@ class Election:
         # The computed key should be unchanged.
         return opened_key != md.opened_key
 
+    def is_editable(self):
+        "Can this election be edited?"
+        md = self.q_metadata.first_row()
+        return md.salt is None and md.opened_key is None
+
 
 def new_eid():
     "Create a new ElectionID."

Reply via email to