Skip to content
Snippets Groups Projects
Commit fbe0ba62 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch 'fix/import_file' into 'master'

Fix/import file

Closes #268

See merge request NCER-PD/scheduling-system!184
parents 8207c5c6 3c512e1c
No related branches found
No related tags found
1 merge request!184Fix/import file
Pipeline #7350 passed
...@@ -326,7 +326,7 @@ def create_appointment_types(assessments): ...@@ -326,7 +326,7 @@ def create_appointment_types(assessments):
return appointmentTypes 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 # Languages
if len(row['LANGUAGES']) == 0 and len(row['PREFERED WRITEN LANGUAGE']) == 0: if len(row['LANGUAGES']) == 0 and len(row['PREFERED WRITEN LANGUAGE']) == 0:
logging.warn('No Languages available') logging.warn('No Languages available')
...@@ -500,8 +500,10 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): ...@@ -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 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): 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 # get the indices of each occurrence of the date and use them to get
# the appointment types # the appointment types
...@@ -510,17 +512,17 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types): ...@@ -510,17 +512,17 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types):
# creatre appointment # creatre appointment
appointment, _ = Appointment.objects.update_or_create( appointment, _ = Appointment.objects.update_or_create(
visit=visit, length=sum( visit=visit, length=sum([a.default_duration for a in appointment_types]),
[a.default_duration for a in appointment_types]),
flying_team=ft, location=location, 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( date_when = visit_date.replace(
hour=9, minute=0, second=0, microsecond=0) hour=9, minute=0, second=0, microsecond=0)
for appointment_type in appointment_types: for appointment_type in appointment_types:
app_type_link = AppointmentTypeLink( app_type_link = AppointmentTypeLink(
appointment=appointment, date_when=date_when, appointment=appointment, date_when=date_when,
appointment_type=appointment_type) appointment_type=appointment_type, worker=lcsb_worker)
date_when += datetime.timedelta( date_when += datetime.timedelta(
minutes=appointment_type.default_duration) minutes=appointment_type.default_duration)
app_type_link.save() app_type_link.save()
...@@ -554,7 +556,9 @@ def createWorker(password, email='', username='admin', first_name='LCSB', last_n ...@@ -554,7 +556,9 @@ def createWorker(password, email='', username='admin', first_name='LCSB', last_n
# create workerStudyRole # create workerStudyRole
workerStudyRole, _ = WorkerStudyRole.objects.update_or_create(worker=worker, workerStudyRole, _ = WorkerStudyRole.objects.update_or_create(worker=worker,
study_id=GLOBAL_STUDY_ID, role=ROLE_CHOICES_TECHNICIAN) study_id=GLOBAL_STUDY_ID, role=ROLE_CHOICES_TECHNICIAN)
workerStudyRole.save()
logging.info('SuperUser and Worker {} created'.format(username)) logging.info('SuperUser and Worker {} created'.format(username))
return worker
if __name__ == '__main__': if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
...@@ -565,6 +569,17 @@ if __name__ == '__main__': ...@@ -565,6 +569,17 @@ if __name__ == '__main__':
if not os.path.isfile(file): if not os.path.isfile(file):
logging.warn('Please, execute the program with a valid file path.') logging.warn('Please, execute the program with a valid file path.')
sys.exit(1) 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 = pd.read_excel(file, dtype=object)
df = df.fillna('').astype(unicode) df = df.fillna('').astype(unicode)
df.columns = [c.upper() for c in df.columns] df.columns = [c.upper() for c in df.columns]
...@@ -596,13 +611,4 @@ if __name__ == '__main__': ...@@ -596,13 +611,4 @@ if __name__ == '__main__':
# process each row # process each row
for index, row in df.iterrows(): for index, row in df.iterrows():
parse_row(index, row, visit_columns, appointmentTypes, voucher_types) parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_worker)
#create worker and super user \ No newline at end of file
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
...@@ -35,7 +35,7 @@ def workers_for_daily_planning(request): ...@@ -35,7 +35,7 @@ def workers_for_daily_planning(request):
role = unicode(worker.roles.filter(study_id=GLOBAL_STUDY_ID)[0].role) role = unicode(worker.roles.filter(study_id=GLOBAL_STUDY_ID)[0].role)
worker_dict_for_json = { worker_dict_for_json = {
'id': worker.id, '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), 'availability': worker.availability_percentage(start_date=start_date),
'title': u"{} ({})".format(unicode(worker), role[:1].upper()), 'title': u"{} ({})".format(unicode(worker), role[:1].upper()),
'role': role 'role': role
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment