diff --git a/smash/import_file.py b/smash/import_file.py index aca328dc0ec4deac59a4dcbf50e40e5abe7a2a0a..6eff049dc433c8aa9c7e53ffa7934e4acb7061e1 100644 --- a/smash/import_file.py +++ b/smash/import_file.py @@ -326,7 +326,7 @@ def create_appointment_types(assessments): return appointmentTypes -def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): +def parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_worker): # Languages if len(row['LANGUAGES']) == 0 and len(row['PREFERED WRITEN LANGUAGE']) == 0: logging.warn('No Languages available') @@ -500,8 +500,10 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): ''' If there are two Vx with the same date we put together the appointment types in the same appointment ''' + starting_hour = 9 for visit_date in set(visit_dates): - datetime_when = visit_date.strftime('%Y-%m-%d') + datetime_when = visit_date.replace(hour=starting_hour, minute=0, second=0, microsecond=0) + starting_hour+=1 # get the indices of each occurrence of the date and use them to get # the appointment types @@ -510,17 +512,17 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): # creatre appointment appointment, _ = Appointment.objects.update_or_create( - visit=visit, length=sum( - [a.default_duration for a in appointment_types]), + visit=visit, length=sum([a.default_duration for a in appointment_types]), flying_team=ft, location=location, - status=Appointment.APPOINTMENT_STATUS_FINISHED, datetime_when=datetime_when) + status=Appointment.APPOINTMENT_STATUS_FINISHED, datetime_when=datetime_when, + worker_assigned=lcsb_worker) date_when = visit_date.replace( hour=9, minute=0, second=0, microsecond=0) for appointment_type in appointment_types: app_type_link = AppointmentTypeLink( - appointment=appointment, date_when=date_when, - appointment_type=appointment_type) + appointment=appointment, date_when=date_when, + appointment_type=appointment_type, worker=lcsb_worker) date_when += datetime.timedelta( minutes=appointment_type.default_duration) app_type_link.save() @@ -554,7 +556,9 @@ def createWorker(password, email='', username='admin', first_name='LCSB', last_n # create workerStudyRole workerStudyRole, _ = WorkerStudyRole.objects.update_or_create(worker=worker, study_id=GLOBAL_STUDY_ID, role=ROLE_CHOICES_TECHNICIAN) + workerStudyRole.save() logging.info('SuperUser and Worker {} created'.format(username)) + return worker if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) @@ -565,6 +569,17 @@ if __name__ == '__main__': if not os.path.isfile(file): logging.warn('Please, execute the program with a valid file path.') sys.exit(1) + + #create worker and super user + pass1 = '' + pass2 = None + while pass1 != pass2: + pass1 = getpass.getpass('Please type a password for the Admin user: ') + pass2 = getpass.getpass('Please type your password again: ') + if pass1 != pass2: + print 'Password mismatch, please try again' + lcsb_worker = createWorker(pass1) + df = pd.read_excel(file, dtype=object) df = df.fillna('').astype(unicode) df.columns = [c.upper() for c in df.columns] @@ -596,13 +611,4 @@ if __name__ == '__main__': # process each row for index, row in df.iterrows(): - parse_row(index, row, visit_columns, appointmentTypes, voucher_types) - #create worker and super user - pass1 = '' - pass2 = None - while pass1 != pass2: - pass1 = getpass.getpass('Please type a password for the Admin user: ') - pass2 = getpass.getpass('Please type your password again: ') - if pass1 != pass2: - print 'Password mismatch, please try again' - createWorker(pass1) \ No newline at end of file + parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_worker) \ No newline at end of file diff --git a/smash/web/api_views/worker.py b/smash/web/api_views/worker.py index afc5e6c7b1a18eb025b52ee67cb00bff18c6e46a..dd87beccf1351f016ffd5a45039d7ade62be42be 100644 --- a/smash/web/api_views/worker.py +++ b/smash/web/api_views/worker.py @@ -35,7 +35,7 @@ def workers_for_daily_planning(request): role = unicode(worker.roles.filter(study_id=GLOBAL_STUDY_ID)[0].role) worker_dict_for_json = { 'id': worker.id, - 'flags' : [language.image.url for language in worker.languages.all()], + 'flags' : [language.image.url for language in worker.languages.all() if language.image], 'availability': worker.availability_percentage(start_date=start_date), 'title': u"{} ({})".format(unicode(worker), role[:1].upper()), 'role': role