1+ from datetime import datetime , timedelta
12import peewee as pw
23
34
5+ DEFAULT_SLOT_PERIOD = 60 # Minutos
6+
47db = pw .SqliteDatabase ('pycamp_projects.db' )
58
69
@@ -37,11 +40,18 @@ def __str__(self):
3740 return rv_str
3841
3942 def is_busy (self , moment ):
40- import random
41- if random .random () > 0.5 :
42- return True
43+ """`moment` is a tuple (start, end) with two datetime objects."""
44+ target_period_start , target_period_end = moment
45+ project_presentation_slots = Slot .select ().where (Slot .current_wizard == self )
46+ for slot in project_presentation_slots :
47+ # https://stackoverflow.com/a/13403827/1161156
48+ latest_start = max (target_period_start , slot .start )
49+ earliest_end = min (target_period_end , slot .get_end_time ())
50+ if latest_start <= earliest_end : # Overlap
51+ return True
4352 return False
4453
54+
4555class Pycamp (BaseModel ):
4656 '''
4757 Representation of the pycamp
@@ -98,7 +108,6 @@ class WizardAtPycamp(BaseModel):
98108 slot_end = pw .DateTimeField ()
99109
100110
101-
102111class Slot (BaseModel ):
103112 '''
104113 Time slot representation
@@ -110,6 +119,9 @@ class Slot(BaseModel):
110119 start = pw .DateTimeField ()
111120 current_wizard = pw .ForeignKeyField (Pycampista )
112121
122+ def get_end_time (self ):
123+ return self .start + timedelta (minutes = DEFAULT_SLOT_PERIOD )
124+
113125
114126class Project (BaseModel ):
115127 '''
0 commit comments