コード例 #1
0
def menu():
    connection = pool.getconn()
    database.create_tables(connection)
    pool.putconn(connection)
    while (selection := input(MENU_PROMPT)) != "6":
        try:
            MENU_OPTIONS[selection]()
        except KeyError:
            print("Invalid input selected. Please try again.")
コード例 #2
0
 def get(cls, option_id: int) -> "Option":
     connection = pool.getconn()
     option = database.get_option(connection, option_id)
     pool.putconn(connection)
     return cls(option[1], option[2], option[0])
コード例 #3
0
 def votes(self) -> List[database.Vote]:
     connection = pool.getconn()
     votes = database.get_votes_for_option(connection, self.id)
     pool.putconn(connection)
     return votes
コード例 #4
0
 def vote(self, username: str):
     connection = pool.getconn()
     database.add_poll_vote(connection, username, self.id)
     pool.putconn(connection)
コード例 #5
0
 def save(self):
     connection = pool.getconn()
     new_option_id = database.add_option(self.text, self.poll_id)
     pool.putconn(connection)
     self.id = new_option_id
コード例 #6
0
 def latest(cls) -> "Poll":
     connection = pool.getconn()
     poll = database.get_latest_poll()
     pool.putconn(connection)
     return cls(poll[1], poll[2], poll[0])
コード例 #7
0
 def all(cls) -> List["Poll"]:
     connection = pool.getconn()
     polls = database.get_polls(connection)
     pool.putconn(connection)
     return [cls(poll[1], poll[2], poll[0]) for poll in polls]
コード例 #8
0
 def get(cls, poll_id: int) -> "Poll":
     connection = pool.getconn()
     poll = database.get_poll(connection, poll_id)
     pool.putconn(connection)
     return cls(poll[1], poll[2], poll[0])
コード例 #9
0
 def options(self) -> List[Option]:
     connection = pool.getconn()
     options = database.get_poll_options(connection, self.id)
     pool.putconn(connection)
     return [Option(option[1], option[2], option[0]) for option in options]
コード例 #10
0
 def save(self):
     connection = pool.getconn()
     new_poll_id = database.create_poll(connection, self.title, self.owner)
     pool.putconn(connection)
     self.id = new_poll_id