Exemplo n.º 1
0
def menu():
    with get_connection() as connection:
        pollDatabase.create_tables(connection)

    while (selection := input(MENU_PROMPT)) != "6":
        try:
            MENU_OPTIONS[selection]()
        except KeyError:
            print("Invalid input selected. Please try again.")
Exemplo n.º 2
0
 def all(cls) -> List["Poll"]:
     with get_connection() as connection:
         polls = pollDatabase.get_polls(connection)
         return [cls(poll[1], poll[2], poll[0]) for poll in polls]
Exemplo n.º 3
0
 def latest(cls) -> "Poll":
     with get_connection() as connection:
         poll = pollDatabase.get_latest_poll(connection)
         return cls(poll[1], poll[2], poll[0])
Exemplo n.º 4
0
 def options(self) -> List[Option]:
     with get_connection() as connection:
         options = pollDatabase.get_poll_options(connection, self.id)
         return [
             Option(option[1], option[2], option[0]) for option in options
         ]
Exemplo n.º 5
0
 def get(cls, poll_id: int) -> "Poll":
     with get_connection() as connection:
         poll = pollDatabase.get_poll(connection, poll_id)
         return cls(poll[1], poll[2], poll[0])
Exemplo n.º 6
0
 def save(self):
     with get_connection() as connection:
         new_poll_id = pollDatabase.create_poll(connection, self.title,
                                                self.owner)
         self.id = new_poll_id
Exemplo n.º 7
0
 def votes(self) -> List[pollDatabase.vote]:
     with get_connection() as connection:
         votes = pollDatabase.get_votes_for_option(connection, self.id)
         return votes
Exemplo n.º 8
0
 def vote(self, username: str):
     with get_connection() as connection:
         current_datetime_utc = datetime.datetime.now(tz=pytz.utc)
         current_timestamp = current_datetime_utc.timestamp()
         pollDatabase.add_poll_vote(connection, username, current_timestamp,
                                    self.id)
Exemplo n.º 9
0
 def get(cls, option_id: int) -> "Option":
     with get_connection() as connection:
         poll = pollDatabase.get_option(connection, option_id)
         return cls(poll[1], poll[2], poll[0])
Exemplo n.º 10
0
 def save(self):
     with get_connection() as connection:
         new_option_id = pollDatabase.add_option(connection, self.text,
                                                 self.poll_id)
         self.id = new_option_id