Note that there are some explanatory texts on larger screens.

plurals
  1. POInfinite looping in Django view
    primarykey
    data
    text
    <p>I am writing an application for time_slot in python </p> <p>please look at this code </p> <pre><code>from datetime import datetime ,timedelta appointments = [(datetime(2012, 5, 22, 10), datetime(2012, 5, 22, 10, 30)), (datetime(2012, 5, 22, 12), datetime(2012, 5, 22, 13)), (datetime(2012, 5, 22, 15, 30), datetime(2012, 5, 22, 17, 10))] hours = (datetime(2012, 5, 22, 9), datetime(2012, 5, 24, 18)) duration = timedelta(minutes = 120) def get_slots(hours, appointments,duration): slots = sorted([(hours[0], hours[0])] + appointments + [(hours[1], hours[1])]) for start, end in ((slots[i][1], slots[i+1][0]) for i in range(len(slots)-1)): assert start &lt;= end, "Cannot attend all appointments" while start + duration &lt;= end: dt_obj = start date_str = dt_obj.strftime("%Y-%m-%d %H:%M:%S") today18 = start.replace(hour=17, minute=59, second=59, microsecond=0) if start &lt; today18: print "{:%d:%H:%M} - {:%d:%H:%M}".format(start, start + duration) start += duration else: start += timedelta(hours = 15) if __name__ == "__main__": get_slots(hours, appointments,duration) </code></pre> <p>The above code is working fine for me when i am running it like python time_slots.py</p> <p>But when i am using above code in djanog view like </p> <pre><code>from datetime importdatetime ,timedelta duration = timedelta(minutes = 60) appointments = [(datetime(2012, 5, 22, 10), datetime(2012, 5, 22, 10, 30)), (datetime(2012, 5, 22, 12), datetime(2012, 5, 22, 13)), (datetime(2012, 5, 22, 15, 30), datetime(2012, 5, 22, 17, 10))] # hours = (datetime.datetime(2012, 5, 24, 18), datetime.datetime(2012, 5, 22, 9)) hours = (datetime(2012, 5, 22, 9), datetime(2012, 5, 24, 18)) slots = sorted([(hours[0], hours[0])] + appointments + [(hours[1], hours[1])]) for start, end in ((slots[i][1], slots[i+1][0]) for i in range(len(slots)-1)): assert start &lt;= end, "Cannot attend all appointments" while start + duration &lt;= end: today18 = start.replace(hour=17, minute=59, second=59, microsecond=0) if start &lt; today18: print "{:%H:%M} - {:%H:%M}".format(start, start + duration) else: start += timedelta(hours = 15) </code></pre> <p>and when i am calling this view it's returning an infinite loop in console </p> <p>Please help me what i am doing wrong here i want the available time slots as i am getting in time_slots.py </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload