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

Merge branch 'fix/allow_cancelled_appointments_to_be_dragged_out' into 'devel_0.13.x'

ASAP Fixes #305 cancelled events can be now dragged out of the daily planning

See merge request NCER-PD/scheduling-system!214
parents 8f4cf940 a4b920d6
No related branches found
No related tags found
2 merge requests!2180.13.1 into master,!214ASAP Fixes #305 cancelled events can be now dragged out of the daily planning
Pipeline #9721 passed
......@@ -141,8 +141,8 @@ def parse_boolean(boolean_Y_N):
else:
return False
except Exception as e:
logging.warn('parse_boolean failed for {}.'.format(boolean_Y_N))
logging.warn('{} {}'.format(e.message, e.args))
logging.warn(u'parse_boolean failed for {}.'.format(boolean_Y_N))
logging.warn(u'{} {}'.format(e.message, e.args))
return False
# birth date
......@@ -204,6 +204,8 @@ language_table = {
'L': 'Luxembourgish',
'LT': 'Lithuanian',
'IT': 'Italian',
'I': 'Italian',
'NL': 'Dutch',
'F': 'French',
'D': 'German',
'G': 'German',
......@@ -211,6 +213,7 @@ language_table = {
'P': 'Portuguese',
'A': 'Arabic',
'SP': 'Spanish',
'S': 'Spanish',
'FIN': 'Finnish'
}
......@@ -222,6 +225,7 @@ locale_table = {
'German': ('de_DE', 'DE'),
'English': ('en_GB', 'GB'),
'Portuguese': ('pt_PT', 'PT'),
'Dutch': ('nl_BE', 'NL'),
'Arabic': ('ar_sa', None),
'Spanish': ('es_ES', 'ES') ,
'Finnish': ('fi_FI', 'FI')
......@@ -245,10 +249,12 @@ def apply_column_languages(languages):
languages = languages.strip()
if type(languages) != float and len(languages) > 0:
# replacements and transformations
languages = unicode(languages).upper().translate(
languages = unicode(languages).upper().strip().translate(
language_translation_table)
new_list = []
for language in languages.split(';'):
if len(language) == 0:
continue
if language in language_table:
language = language_table[language]
new_list.append(language)
......@@ -271,7 +277,9 @@ def apply_column_country(country):
try:
return country_table[country]
except:
logging.warn('Invalid Country: {}'.format(country))
if country in country_table.values():
return country
logging.warn(u'Invalid Country: {}'.format(country))
return country
'''
......@@ -314,18 +322,18 @@ def add_subject_vouchers(voucher_reference, referral, voucher_types, subject_nd_
usage_partner.save()
if created:
logging.warn('New Voucher Partner created: {}'.format(voucher_partner))
logging.warn(u'New Voucher Partner created: {}'.format(voucher_partner))
vt = VoucherType.objects.get(code=voucher_type)
if nd_number != subject_nd_number:
logging.warn('voucher reference nd_number is not the same! {} != {}'.format(nd_number, subject_nd_number))
logging.warn(u'voucher reference nd_number is not the same! {} != {}'.format(nd_number, subject_nd_number))
study_subject = StudySubject.objects.get(nd_number=subject_nd_number)
voucher, created = Voucher.objects.update_or_create(number=voucher_reference, issue_date=issue_date,
expiry_date=expiry_date, voucher_type=vt, study_subject=study_subject,
status=VOUCHER_STATUS_IN_USE, usage_partner=usage_partner, issue_worker=referral)
logging.warn('New Voucher added: {}'.format(voucher_reference))
logging.warn(u'New Voucher added: {}'.format(voucher_reference))
return voucher
# create voucher types
......@@ -367,10 +375,11 @@ def create_languages(languages_cell):
os.makedirs(MEDIA_ROOT)
for language in languages_cell:
logging.warn('iteration {} {}'.format(language, languages_cell))
lang, created = Language.objects.get_or_create(
name=language, locale=locale_table.get(language,(None, None))[0])
if created:
logging.warn('New Language added: {}'.format(language))
logging.warn(u'New Language added: {}'.format(language))
lang.save()
......@@ -379,7 +388,7 @@ def create_languages(languages_cell):
language_flags[language])
basename = os.path.basename(src)
dst = os.path.join(MEDIA_ROOT, basename)
logging.warn('Copying file {} to {}'.format(src, dst))
logging.warn(u'Copying file {} to {}'.format(src, dst))
copyfile(src, dst)
# .save(basename, File(open(dst, 'rb'))) #SimpleUploadedFile(name=path, content=open(path, 'rb').read(), content_type='image/png')
lang.image = basename
......@@ -392,7 +401,7 @@ def create_languages(languages_cell):
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')
logging.warn(u'No Languages available for row {} {}'.format(index, row['FIRST NAME']+row['LAST NAME']))
elif len(row['LANGUAGES']) == 0 and len(row['PREFERED WRITEN LANGUAGE']) > 0:
row['LANGUAGES'] = row['PREFERED WRITEN LANGUAGE']
elif len(row['LANGUAGES']) > 0 and len(row['PREFERED WRITEN LANGUAGE']) == 0:
......@@ -409,7 +418,7 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_w
country = row['COUNTRY']
country, created = Country.objects.get_or_create(name=country)
if created:
logging.warn('New Country added: {}'.format(row['COUNTRY']))
logging.warn(u'New Country added: {}'.format(row['COUNTRY']))
country.save()
# Location and Flying Team
......@@ -422,20 +431,20 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_w
location, created = Location.objects.get_or_create(
name=DEFAULT_LOCATION, prefix=prefix)
if created:
logging.warn('New location added: {}'.format(DEFAULT_LOCATION))
logging.warn(u'New location added: {}'.format(DEFAULT_LOCATION))
location.save()
else:
prefix = 'F'
location, created = Location.objects.get_or_create(
name='Flying Team', prefix=prefix)
if created:
logging.warn('New location added: Flying Team')
logging.warn(u'New location added: Flying Team')
location.save()
# Create Flying Team
ft, created = FlyingTeam.objects.get_or_create(
place=row['LOCATION OF FT'])
if created:
logging.warn('New Flying Team added: {}'.format(
logging.warn(u'New Flying Team added: {}'.format(
row['LOCATION OF FT']))
ft.save()
......@@ -443,7 +452,7 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_w
# create health partner (Referral)
health_partner = None
if row['REFERRAL'].strip() != '':
logging.warn('Trying to get or create Worker: {}'.format(row['REFERRAL']))
logging.warn(u'Trying to get or create Worker: {}'.format(row['REFERRAL']))
health_partner, created = Worker.objects.get_or_create(name=row['REFERRAL'])
health_partner.roles.update(name=ROLE_CHOICES_HEALTH_PARTNER)
# create workerStudyRole
......@@ -451,7 +460,7 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_w
worker=health_partner, study_id=GLOBAL_STUDY_ID, name=ROLE_CHOICES_HEALTH_PARTNER)
health_partner.save()
if created:
logging.warn('New Health Partner added: {}'.format(row['REFERRAL']))
logging.warn(u'New Health Partner added: {}'.format(row['REFERRAL']))
if row['SS NUMBER'] is None:
row['SS NUMBER'] = ''
......@@ -479,7 +488,7 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_w
subject.save()
if created:
logging.warn('New Subject added with SS number: {}'.format(row['SS NUMBER']))
logging.warn(u'New Subject added with SS number: {}'.format(row['SS NUMBER']))
# StudySubject
study = Study.objects.filter(id=GLOBAL_STUDY_ID)[0]
......@@ -508,7 +517,7 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_w
studySubject.save()
if created:
logging.warn('New StudySubject added with ND number: {}'.format(nd_number))
logging.warn(u'New StudySubject added with ND number: {}'.format(nd_number))
#VOUCHERS
voucher_references = row['VOUCHER REFERENCE']
......@@ -543,7 +552,7 @@ def parse_row(index, row, visit_columns, appointmentTypes, voucher_types, lcsb_w
subject=studySubject, datetime_begin=datetime_begin, datetime_end=datetime_end, defaults={
'is_finished': True})
if created:
logging.warn('New Visit added for ND number {} starting on {}'.format(
logging.warn(u'New Visit added for ND number {} starting on {}'.format(
nd_number, datetime_begin))
appointment_types = appointmentTypes[:len(set(visit_dates))] #in this case appointment types are incremental
......@@ -632,11 +641,11 @@ def createWorker(password, email='', username='admin', first_name='LCSB', last_n
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
if len(sys.argv) < 2:
logging.warn('Please, execute the program as: python {} file_path.xlsx'.format(sys.argv[0]))
logging.warn(u'Please, execute the program as: python {} file_path.xlsx'.format(sys.argv[0]))
sys.exit(1)
file = sys.argv[1]
if not os.path.isfile(file):
logging.warn('Please, execute the program with a valid file path.')
logging.warn(u'Please, execute the program with a valid file path.')
sys.exit(1)
admin_password = None
......@@ -681,10 +690,11 @@ if __name__ == '__main__':
df = pd.read_excel(file, dtype=object, sheet_name='Voucher Partners')
#convert column name to upper case
df.columns = [c.upper() for c in df.columns]
logging.warn(u'COLUMNS IN VOUCHER_PARTNER: {}'.format(df.columns))
df['ROLE'] = df['ROLE'].apply(parse_role)
logging.warn('Voucher Partners')
logging.warn(u'Voucher Partners')
for index, row in df.iterrows():
logging.warn('Voucher Partner: {}'.format(row['NAME']))
logging.warn(u'Voucher Partner: {}'.format(row['NAME']))
worker = createWorker(None, email='', username=None, first_name='', last_name='', specialization=row['ROLE'],
role_name=row['ROLE'], unit='CHL', languages=[], name=row['NAME'], comment=row.get('COMMENT', ''))
if type(row['OFFER']) != float:
......@@ -701,9 +711,10 @@ if __name__ == '__main__':
worker.save()
#READ FIRST SHEET
df = pd.read_excel(file, dtype=object)
df = pd.read_excel(file, dtype=object, sheet_name='Subjects')
df = df.fillna('').astype(unicode)
df.columns = [c.upper() for c in df.columns]
df.columns = [c.upper().strip() for c in df.columns]
logging.warn(u'COLUMNS IN Subjects: {}'.format(df.columns))
# make transformations
for column, function in converters.items():
logging.warn(column)
......
......@@ -21,7 +21,6 @@ var overlaps = (function () {
return function (x, y, element) {
var pos1 = [[x, x + 100], [y, y + 20]],
pos2 = getPositions(element);
console.log(x, y, element);
return comparePositions(pos1[0], pos2[0]) && comparePositions(pos1[1], pos2[1]);
};
})();
......@@ -83,7 +82,6 @@ function add_event(event, color, subjectId, locationId, boxBody) {
revert: true,
revertDuration: 0,
start: function (event, ui) {
console.log('Ey');
$(this).popover('disable');
}
});
......@@ -247,7 +245,7 @@ function are_events_overlapping(start_a, end_a, start_b, end_b){
start_b = moment(start_b.format("Y-MM-DD-HH-mm"), "Y-MM-DD-HH-mm");
end_b = moment(end_b.format("Y-MM-DD-HH-mm"), "Y-MM-DD-HH-mm");
console.log('checking', start_a, end_a, start_b, end_b);
//console.log('checking', start_a, end_a, start_b, end_b);
var rangeA = moment.range( start_a, end_a );
var rangeB = moment.range( start_b, end_b );
......@@ -410,6 +408,14 @@ function is_event_not_finished(event){
}
}
function is_event_cancelled(event){
if( event.status === 'CANCELLED' ){
return true;
}else{
return false;
}
}
function addDailyPlanningCalendar(calendar_selector, replace_all, calendar_dict_props){
var customButtons = {
......@@ -568,6 +574,12 @@ function addDailyPlanningCalendar(calendar_selector, replace_all, calendar_dict_
'text-shadow': '0px 0px 12px #000000'
});
}
//for those finished events that are cancelled
if(is_event_cancelled(event)){
event.editable = true;
}
element.popover({
title: event.short_title,
container: 'body',
......@@ -605,6 +617,10 @@ function addDailyPlanningCalendar(calendar_selector, replace_all, calendar_dict_
},
eventDrop: function ( event, delta, revertFunc, jsEvent, ui, view ){
var resourceId = event.resourceId;
if(is_event_cancelled(event)){
alert("This event is cancelled and can't be modified. Only dragged out outside the calendar.");
return revertFunc();
}
//this case applies when the event is moved from resource to resource (change of worker)
checkResourceAvailability(calendar_selector, resourceId, event); // in this case we have the event
},
......
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