diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2024-02-29 21:10:43 +0200 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2024-12-21 19:43:13 +0200 |
| commit | 5c64529e77f150f8b83930f17e792b2cb8e38a87 (patch) | |
| tree | 89b28f50812fb735dfdaa0bca24764959168d84d /db.py | |
| parent | 3661c687f0c54bd9f4e1075aa651bc612d634a13 (diff) | |
Add whole day mode, various improvements
Diffstat (limited to 'db.py')
| -rw-r--r-- | db.py | 24 |
1 files changed, 19 insertions, 5 deletions
@@ -70,9 +70,19 @@ class Choice: def end_datetime_notz(self): return self.end_datetime.replace(tzinfo=None) + def start_date_notz(self): + return self.start_datetime.date() + + def end_date_notz(self): + return self.end_datetime.date() + def ends_on_same_day(self): return self.start_datetime.date() == self.end_datetime.date() + def ends_at_same_datetime(self): + return self.start_datetime.date() == self.end_datetime.date() \ + and self.start_datetime.time() == self.end_datetime.time() + @dataclass class Poll: id: str @@ -83,6 +93,7 @@ class Poll: author_email: str | None choices: list[Choice] manage_code: str + is_whole_day: bool def share_url(self): return f"{BASE_URL}/poll/{self.id}" @@ -99,6 +110,7 @@ def tuple_to_poll(poll_t: tuple) -> Poll: author_name=poll_t[4], author_email=poll_t[5], manage_code=poll_t[6], + is_whole_day=poll_t[7], choices=[] ) @@ -159,13 +171,14 @@ def create_poll(title: str, description: str, author_name: str, author_email: str, + is_whole_day: bool, choices: list[Choice]): with db.cursor() as (conn, cur): try: - cur.execute("INSERT INTO polls (title, description, author_name, author_email)" - "VALUES (%s, %s, %s, %s) RETURNING *", - (title, description, author_name, author_email)) + cur.execute("INSERT INTO polls (title, description, author_name, author_email, whole_day)" + "VALUES (%s, %s, %s, %s, %s) RETURNING *", + (title, description, author_name, author_email, is_whole_day)) poll_t = cur.fetchone() if poll_t is None: @@ -228,12 +241,13 @@ def update_poll_info( description, author_name, author_email, + is_whole_day, ) -> None: with db.cursor() as (conn, cur): try: - cur.execute("UPDATE polls SET title = %s, description = %s, author_name = %s, author_email = %s " + cur.execute("UPDATE polls SET title = %s, description = %s, author_name = %s, author_email = %s, whole_day = %s " "WHERE manage_code = %s", - (title, description, author_name, author_email, code)) + (title, description, author_name, author_email, is_whole_day, code)) conn.commit() except Exception as e: conn.rollback() |
