add poll db commands to init, fix db poll commands
This commit is contained in:
parent
6f4c6b33f2
commit
32596ab4e5
@ -62,6 +62,8 @@ def create_app(test_config: None = None) -> Flask:
|
|||||||
app.cli.add_command(db.refresh_milestones_command)
|
app.cli.add_command(db.refresh_milestones_command)
|
||||||
app.cli.add_command(db.reset_milestone_command)
|
app.cli.add_command(db.reset_milestone_command)
|
||||||
app.cli.add_command(db.hard_reset_milestone_command)
|
app.cli.add_command(db.hard_reset_milestone_command)
|
||||||
|
app.cli.add_command(db.refresh_polls_command)
|
||||||
|
app.cli.add_command(db.reset_poll_command)
|
||||||
|
|
||||||
# scheduler job for giving points to users
|
# scheduler job for giving points to users
|
||||||
def proxy_job() -> None:
|
def proxy_job() -> None:
|
||||||
|
|||||||
@ -105,16 +105,24 @@ def refresh_polls() -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def reset_poll(poll: str) -> bool:
|
def reset_poll(poll: str) -> bool:
|
||||||
|
if poll not in current_app.config['POLLS']:
|
||||||
|
print(f"Failed resetting poll, {poll} not in polls file.")
|
||||||
|
return False
|
||||||
try:
|
try:
|
||||||
db = get_db()
|
db = get_db()
|
||||||
db.execute(
|
db.execute(
|
||||||
"UPDATE polls SET points = 0 WHERE poll_name = ?",
|
"DELETE FROM polls WHERE poll_name = ?",
|
||||||
(poll,)
|
(poll,)
|
||||||
)
|
)
|
||||||
|
for option in current_app.config['POLLS'][poll]:
|
||||||
|
db.execute(
|
||||||
|
"INSERT INTO polls(poll_name, points, option) VALUES(?, ?, ?)",
|
||||||
|
(poll, 0, option)
|
||||||
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
return True
|
return True
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
current_app.logger.error(f"Error occurred adding a milestone: {e.args[0]}")
|
current_app.logger.error(f"Error occurred resetting poll: {e.args[0]}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -257,8 +265,8 @@ def refresh_polls_command() -> None:
|
|||||||
click.echo('Refreshed polls.')
|
click.echo('Refreshed polls.')
|
||||||
|
|
||||||
|
|
||||||
@click.command('reset-polls')
|
@click.command('reset-poll')
|
||||||
@click.argument('milestone')
|
@click.argument('poll')
|
||||||
def reset_poll_command(poll: str) -> None:
|
def reset_poll_command(poll: str) -> None:
|
||||||
"""Resets polls progress back to zero."""
|
"""Resets polls progress back to zero."""
|
||||||
if reset_poll(poll):
|
if reset_poll(poll):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user