|
9 | 9 | from goathacks import db, mail
|
10 | 10 | from goathacks.models import User
|
11 | 11 |
|
| 12 | +from tabulate import tabulate |
| 13 | + |
12 | 14 | gr = AppGroup("user")
|
13 | 15 |
|
14 | 16 | @gr.command('create')
|
@@ -122,3 +124,56 @@ def drop_user(email, confirm):
|
122 | 124 | db.session.commit()
|
123 | 125 | click.echo(f"Dropped {user.first_name}'s registration")
|
124 | 126 |
|
| 127 | +@gr.command("list") |
| 128 | +def list_users(): |
| 129 | + """ |
| 130 | + Gets a list of all users |
| 131 | + """ |
| 132 | + users = User.query.all() |
| 133 | + |
| 134 | + def make_table_content(user): |
| 135 | + return [user.email, f"{user.first_name} {user.last_name}", user.waitlisted, user.is_admin] |
| 136 | + |
| 137 | + table = map(make_table_content, users) |
| 138 | + |
| 139 | + print(tabulate(table, headers=["Email", "Name", "Waitlisted", "Admin"])) |
| 140 | + |
| 141 | + |
| 142 | +@gr.command("autopromote") |
| 143 | +def autopromote_users(): |
| 144 | + """ |
| 145 | + Runs through and automatically promotes users up to the waitlist limit |
| 146 | + """ |
| 147 | + WAITLIST_LIMIT = current_app.config['MAX_BEFORE_WAITLIST'] |
| 148 | + num_confirmed = db.session.query(User).filter(User.waitlisted == False).count() |
| 149 | + click.echo(f"Got {num_confirmed} confirmed attendees") |
| 150 | + num_waitlisted = db.session.query(User).filter(User.waitlisted == True).count() |
| 151 | + click.echo(f"Got {num_waitlisted} waitlisted attendees") |
| 152 | + |
| 153 | + num_to_promote = WAITLIST_LIMIT - num_confirmed |
| 154 | + |
| 155 | + if num_to_promote > num_waitlisted: |
| 156 | + num_to_promote = num_waitlisted |
| 157 | + |
| 158 | + click.echo(f"About to promote {str(num_to_promote)} attendees from waitlist") |
| 159 | + |
| 160 | + users = db.session.query(User).filter(User.waitlisted == True).all() |
| 161 | + |
| 162 | + num_promoted = 0 |
| 163 | + num_to_promote_orig = num_to_promote |
| 164 | + |
| 165 | + for u in users: |
| 166 | + if num_to_promote > 0: |
| 167 | + click.echo(f"Attempting to promote {u.email} ({u.id})") |
| 168 | + u.waitlisted = False |
| 169 | + db.session.commit() |
| 170 | + msg = Message("Waitlist Promotion") |
| 171 | + msg.add_recipient(u.email) |
| 172 | + msg. sender = ( "GoatHacks Team", "[email protected]") |
| 173 | + msg.body = render_template("emails/waitlist_promotion.txt", user=u) |
| 174 | + mail.send(msg) |
| 175 | + num_promoted += 1 |
| 176 | + num_to_promote -= 1 |
| 177 | + |
| 178 | + click.echo(f"Promoted {num_promoted}/{num_to_promote_orig} attendees off the waitlist!") |
| 179 | + |
0 commit comments