Skip to content

Commit 1cc72ab

Browse files
committed
minor fixes
1 parent 30d04ee commit 1cc72ab

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/pycamp_bot/commands/wizard.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import datetime, timedelta
44

55
from telegram.ext import CommandHandler
6+
from telegram.error import BadRequest
67
from pycamp_bot.models import Pycampista, WizardAtPycamp
78
from pycamp_bot.commands.auth import admin_needed
89
from pycamp_bot.commands.manage_pycamp import get_active_pycamp
@@ -56,7 +57,7 @@ def compute_wizards_slots(pycamp):
5657
wizard_end = pycamp.end
5758
slots = []
5859
current_period = wizard_start
59-
while current_period < wizard_end:
60+
while current_period < wizard_end: # TODO: check fields None
6061
slot_start = current_period
6162
slot_end = current_period + timedelta(minutes=pycamp.wizard_slot_duration)
6263
slots.append(
@@ -94,6 +95,7 @@ def define_wizards_schedule(pycamp):
9495
idx += 1
9596
return wizard_per_slot
9697

98+
9799
async def become_wizard(update, context):
98100
current_wizards = Pycampista.select().where(Pycampista.wizard is True)
99101

@@ -172,7 +174,11 @@ async def notify_schedule_to_wizards(update, context, pycamp):
172174
(WizardAtPycamp.pycamp == pycamp) & (WizardAtPycamp.wizard == wizard)
173175
).order_by(WizardAtPycamp.init)
174176

175-
await notify_scheduled_slots_to_wizard(update, context, pycamp, wizard, wizard_agenda)
177+
try:
178+
await notify_scheduled_slots_to_wizard(update, context, pycamp, wizard, wizard_agenda)
179+
logger.debug("Notified wizard schedule to {}".format(wizard.username))
180+
except BadRequest:
181+
logger.warn("Coulnd't notify its wizzard schedule to {}".format(wizard.username))
176182

177183

178184
def persist_wizards_schedule_in_db(pycamp):
@@ -190,7 +196,6 @@ def persist_wizards_schedule_in_db(pycamp):
190196
init=start,
191197
end=end
192198
)
193-
logger.debug("From {} to {} the wizard is {}".format(start, end, wizard.username))
194199

195200

196201
@admin_needed
@@ -201,6 +206,8 @@ async def schedule_wizards(update, context):
201206
logger.info("Deleted wizards schedule ({} records)".format(n))
202207

203208
persist_wizards_schedule_in_db(pycamp)
209+
logger.info("Wizards schedule persisted in the DB.")
210+
204211

205212
await notify_schedule_to_wizards(update, context, pycamp)
206213

@@ -215,7 +222,6 @@ async def schedule_wizards(update, context):
215222
)
216223

217224

218-
219225
def format_wizards_schedule(agenda):
220226
"""Aux function to render the wizards schedule as a friendly message."""
221227
per_day = defaultdict(list)
@@ -265,7 +271,7 @@ async def show_wizards_schedule(update, context):
265271
if not show_all:
266272
agenda = agenda.where(WizardAtPycamp.end > datetime.now())
267273
agenda = agenda.order_by(WizardAtPycamp.init)
268-
274+
269275
msg = format_wizards_schedule(agenda)
270276

271277
await context.bot.send_message(

src/pycamp_bot/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212
class BaseModel(pw.Model):
13-
1413
class Meta:
1514
database = db
1615

@@ -138,7 +137,7 @@ class Slot(BaseModel):
138137
'''
139138
code = pw.CharField() # For example A1 for first slot first day
140139
start = pw.DateTimeField()
141-
current_wizard = pw.ForeignKeyField(Pycampista)
140+
current_wizard = pw.ForeignKeyField(Pycampista, null=True)
142141

143142
def get_end_time(self):
144143
return self.start + timedelta(minutes=DEFAULT_SLOT_PERIOD)
@@ -185,4 +184,5 @@ def models_db_connection():
185184
WizardAtPycamp,
186185
Project,
187186
Slot,
188-
Vote])
187+
Vote], safe=True)
188+
db.close()

test/test_wizard.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,7 @@ def test_no_slot_after_last_day_lunch(self):
9696
print(start)
9797
if start.day == self.pycamp.end.day:
9898
assert start >= lunch_time_end
99+
100+
101+
class TestDefineWizardsSchedule:
102+
pass

0 commit comments

Comments
 (0)