<s> from mittab . apps . tab . models import * <EOL> from mittab . apps . tab . forms import RoomForm <EOL> from decimal import * <EOL> import xlrd <EOL> from xlwt import Workbook <EOL> def import_rooms ( fileToImport ) : <EOL> try : <EOL> sh = xlrd . open_workbook ( filename = None , file_contents = fileToImport . read ( ) ) . sheet_by_index ( <NUM_LIT:0> ) <EOL> except : <EOL> return [ "<STR_LIT>" ] <EOL> num_rooms = <NUM_LIT:0> <EOL> found_end = False <EOL> room_errors = [ ] <EOL> while found_end == False : <EOL> try : <EOL> sh . cell ( num_rooms , <NUM_LIT:0> ) . value <EOL> num_rooms += <NUM_LIT:1> <EOL> except IndexError : <EOL> found_end = True <EOL> try : <EOL> sh . cell ( <NUM_LIT:0> , <NUM_LIT:1> ) . value <EOL> except : <EOL> room_errors . append ( "<STR_LIT>" ) <EOL> return room_errors <EOL> for i in range ( <NUM_LIT:1> , num_rooms ) : <EOL> room_name = sh . cell ( i , <NUM_LIT:0> ) . value <EOL> if room_name == '<STR_LIT>' : <EOL> room_errors . append ( "<STR_LIT>" + str ( i ) + "<STR_LIT>" ) <EOL> continue <EOL> try : <EOL> Room . objects . get ( name = room_name ) <EOL> room_errors . append ( room_name + '<STR_LIT>' ) <EOL> continue <EOL> except : <EOL> pass <EOL> room_rank = sh . cell ( i , <NUM_LIT:1> ) . value <EOL> room_string = str ( room_rank ) <EOL> try : <EOL> room_rank = Decimal ( room_rank ) <EOL> except : <EOL> room_errors . append ( room_name + "<STR_LIT>" ) <EOL> continue <EOL> if len ( room_string ) > <NUM_LIT:5> or ( room_rank < <NUM_LIT:10> and len ( room_string ) > <NUM_LIT:4> ) : <EOL> room_errors . append ( room_name + "<STR_LIT>" ) <EOL> continue <EOL> if room_rank >= <NUM_LIT:100> or room_rank < <NUM_LIT:0> : <EOL> room_errors . append ( room_name + "<STR_LIT>" ) <EOL> continue <EOL> room = Room ( name = room_name , rank = room_rank ) ; <EOL> try : <EOL> room . save ( ) <EOL> except : <EOL> room_errors . append ( room_name + "<STR_LIT>" ) <EOL> return room_errors </s>
