コード例 #1
0
 def options(self) -> List[Option]:
     with get_connection(
     ) as connection:  #better option to the above: use context manager that was created in connection_pool.py
         options = database.get_poll_options(connection, self.id)
         return [
             Option(option[1], option[2], option[0]) for option in options
         ]
コード例 #2
0
 def get_info_for_plt(cls, poll_id: int):
     with get_connection() as connection:
         polls = database.get_poll_options_for_plt(connection, poll_id)
         for poll in polls:
             print(f'{poll[0]}: {poll[1]}')
         options = [poll[0] for poll in polls]
         vote_count = [poll[1] for poll in polls]
         return options, vote_count
コード例 #3
0
def menu():
    with get_connection() as connection:
        database.create_tables(connection)

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