<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from django . db import transaction <EOL> from . models import Schedule , Day , Room , Slot , SlotKind , SlotRoom <EOL> @ transaction . commit_on_success <EOL> def create_slot ( section_slug , date , kind , start , end , rooms ) : <EOL> schedule = Schedule . objects . get ( section__slug = section_slug ) <EOL> slot = Slot ( ) <EOL> slot . day = Day . objects . get ( schedule = schedule , date = date ) <EOL> slot . kind = SlotKind . objects . get ( schedule = schedule , label = kind ) <EOL> slot . start = start <EOL> slot . end = end <EOL> slot . save ( force_insert = True ) <EOL> if rooms == "<STR_LIT:all>" : <EOL> rooms_qs = Room . objects . filter ( schedule = schedule ) . order_by ( "<STR_LIT>" ) <EOL> else : <EOL> rooms_qs = Room . objects . filter ( schedule = schedule , name__in = rooms ) . order_by ( "<STR_LIT>" ) <EOL> if rooms_qs . count ( ) != len ( rooms ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> for room in rooms_qs : <EOL> slot_room = SlotRoom ( ) <EOL> slot_room . slot = slot <EOL> slot_room . room = room <EOL> slot_room . save ( force_insert = True ) <EOL> print "<STR_LIT>" . format ( slot . kind . label , slot . start , slot . end ) </s>
