This repository was archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathviews.py
More file actions
1648 lines (1470 loc) · 91.6 KB
/
views.py
File metadata and controls
1648 lines (1470 loc) · 91.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
from django.shortcuts import get_object_or_404, render, redirect
from .models import *
from .forms import *
from .graphics import *
import os, re
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import Group
from django.conf import settings
from django.template.loader import render_to_string
from django_utils.fusioncharts.fusioncharts import FusionCharts
from django.core.mail import send_mail
from django.http import HttpResponse
from django.core.files.storage import FileSystemStorage
import datetime
import statistics
from django.conf import settings
from iSkyLIMS_drylab import drylab_config
from iSkyLIMS_drylab.utils.testing_drylab_configuration import *
from iSkyLIMS_drylab.utils.drylab_common_functions import *
from smb.SMBConnection import SMBConnection
from iSkyLIMS_wetlab.models import RunProcess, Projects
####### Import libraries for static files
#from django.shortcuts import render_to_response
#from django.shortcuts import RequestContext
#pdb.set_trace()
@login_required
def index(request):
if Service.objects.all().exclude(serviceStatus = 'delivered').exclude(serviceStatus = 'rejected').exclude(serviceStatus = 'approved').exists():
ongoing_services = Service.objects.all().exclude(serviceStatus = 'delivered').exclude(serviceStatus = 'rejected').exclude(serviceStatus = 'approved').order_by('serviceCreatedOnDate')
service_list = []
for service in ongoing_services:
service_info = []
service_info.append(service.serviceRequestNumber)
service_info.append(service.serviceStatus)
if service.serviceStatus == 'recorded':
service_delivery_date = 'Not defined yet'
else:
if Resolution.objects.filter(resolutionServiceID = service).exists():
#import pdb; pdb.set_trace()
if Resolution.objects.filter(resolutionServiceID = service).last().resolutionEstimatedDate is not None:
service_delivery_date = Resolution.objects.filter(resolutionServiceID = service).last().resolutionEstimatedDate.strftime("%d %B, %Y")
else:
service_delivery_date = 'Not defined yet'
else:
service_delivery_date = 'Not defined yet'
service_info.append(service_delivery_date)
service_list.append(service_info)
#import pdb; pdb.set_trace()
return render(request, 'iSkyLIMS_drylab/index.html',{'service_list': service_list})
else:
return render(request, 'iSkyLIMS_drylab/index.html')
'''
def increment_service_number ( user_name):
# check user center
#import pdb; pdb.set_trace()
user_center = Profile.objects.get(profileUserID = user_name).profileCenter.centerAbbr
# get latest service used for user's center
if Service.objects.filter(serviceUserId__profile__profileCenter__centerAbbr=user_center).exists():
number_request = Service.objects.filter(serviceUserId__profile__profileCenter__centerAbbr=user_center).last().serviceRequestInt
service_number = str(int(number_request) + 1).zfill(3)
else:
service_number = '001'
return service_number
def create_service_id (service_number,user_name):
user_center = Profile.objects.get(profileUserID = user_name).profileCenter.centerAbbr
service_id = 'SRV' + user_center + service_number
return service_id
'''
'''
def pdf(request):
from weasyprint import HTML, CSS
from django.template.loader import get_template
from django.core.files.storage import FileSystemStorage
from django.http import HttpResponse
from weasyprint.fonts import FontConfiguration
information = {}
user = {}
service_data ={}
service = Service.objects.get(serviceRequestNumber = 'SRVIIER007')
service_number ,run_specs, center, platform = service.get_service_information().split(';')
information['service_number'] = service_number
information['requested_date'] = service.get_service_creation_time()
information['nodes']= service.serviceAvailableService.all()
user['name'] = 'Silvia'
user['surname'] = 'Valdezate Ramos'
user['position'] = 'Científico'
user['phone'] = '23734'
user['email'] = 'svaldezate@isciii.es'
information['user'] = user
service_data['platform'] = platform
service_data['run_specifications'] = run_specs
service_data['center'] = center
service_data['notes'] = service.serviceNotes
#import pdb; pdb.set_trace()
full_path_file = str(service.serviceFile).split('/')
stored_file = full_path_file[-1]
temp_string_file = re.search('^\d+_(.*)', stored_file)
service_data['file'] = temp_string_file.group(1)
information['service_data'] = service_data
paragraphs = ['first paragraph', 'second paragraph', 'third paragraph']
#font_config = FontConfiguration()
html_string = render_to_string('request_service_template.html', {'information': information})
html = HTML(string=html_string, base_url=request.build_absolute_uri()).write_pdf('documents/drylab/mypdf5.pdf',stylesheets=[CSS(settings.STATIC_ROOT +
drylab_config.CSS_FOR_PDF)])
# '/css/print_services.css')])
fs = FileSystemStorage('documents/drylab')
with fs.open('mypdf5.pdf') as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
# save pdf file as attachment
#response['Content-Disposition'] = 'attachment; filename="mypdf.pdf"'
response['Content-Disposition'] = 'inline;filename=mypdf5.pdf'
return response
return response
'''
'''
def get_data_for_service_confirmation (service_requested):
information = {}
user = {}
service_data ={}
service = Service.objects.get(serviceRequestNumber = service_requested)
service_number ,run_specs, center, platform = service.get_service_information().split(';')
information['service_number'] = service_number
information['requested_date'] = service.get_service_creation_time()
information['nodes']= service.serviceAvailableService.all()
user['name'] = service.serviceUserId.first_name
user['surname'] = service.serviceUserId.last_name
user_id = service.serviceUserId.id
user['area'] = Profile.objects.get(profileUserID = user_id).profileArea
user['center'] = Profile.objects.get(profileUserID = user_id).profileCenter
user['phone'] = Profile.objects.get(profileUserID = user_id).profileExtension
user['position'] = Profile.objects.get(profileUserID = user_id).profilePosition
user['email'] = service.serviceUserId.email
information['user'] = user
projects_in_service = []
projects_class = service.serviceProjectNames.all()
for project in projects_class:
projects_in_service.append(project.get_project_name())
service_data['projects'] = projects_in_service
service_data['platform'] = platform
service_data['run_specifications'] = run_specs
service_data['center'] = center
service_data['notes'] = service.serviceNotes
if str(service.serviceFile) != '':
full_path_file = str(service.serviceFile).split('/')
stored_file = full_path_file[-1]
temp_string_file = re.search('^\d+_(.*)', stored_file)
service_data['file'] = temp_string_file.group(1)
else:
service_data['file'] = 'Not provided'
information['service_data'] = service_data
return information
'''
'''
def create_pdf(request,information, template_file, pdf_file_name):
from weasyprint import HTML, CSS
from django.template.loader import get_template
from weasyprint.fonts import FontConfiguration
#import pdb; pdb.set_trace()
#font_config = FontConfiguration()
html_string = render_to_string(template_file, {'information': information})
pdf_file = os.path.join (settings.BASE_DIR, drylab_config.OUTPUT_DIR_TEMPLATE , pdf_file_name)
html = HTML(string=html_string, base_url=request.build_absolute_uri()).write_pdf(pdf_file,stylesheets=[CSS(settings.BASE_DIR + drylab_config.CSS_FOR_PDF)])
return pdf_file
'''
@login_required
def service_request(request, serviceRequestType):
if serviceRequestType == 'internal_sequencing':
if request.method == "POST":
##Create a form instance with POST data
# more information in:
# https://docs.djangoproject.com/en/2.0/topics/forms/modelforms/
form = ServiceRequestFormInternalSequencing(data=request.POST,files=request.FILES)
#import pdb; pdb.set_trace()
if form.is_valid():
# Create but dont save for following modif
new_service = form.save(commit=False)
# Modification of 'serviceStatus'
new_service.serviceStatus = "recorded"
# Local ("in these premises :-)") sequencing
new_service.serviceSeqCenter = "GENOMIC_SEQ_UNIT"
# Previous 'serviceUsername'refactored to 'serviceUserId' which describes better its real nature
new_service.serviceUserId = User.objects.get(id=request.user.id)
new_service.serviceRequestInt = increment_service_number(request.user)
new_service.serviceRequestNumber = create_service_id(new_service.serviceRequestInt,request.user)
#import pdb; pdb.set_trace()
# Save the new instance
new_service.save()
# Save the many-to-many data for the form
# (required for cases like this one where form.save(commit=False))
form.save_m2m()
#import pdb; pdb.set_trace()
## Send mail to user and bioinfo admins
subject = 'Service ' + new_service.serviceRequestNumber + " has been recorded"
body_message = 'Dear ' + request.user.username + "\n Your service " + new_service.serviceRequestNumber + " has been recorded. You will received the resolution of the request as soon as possible.\n Kind regards \n BU-ISCIII \n bioinformatica@isciii.es"
from_user = 'bioinformatica@isciii.es'
to_user = [request.user.email,'bioinformatica@isciii.es']
send_mail (subject, body_message, from_user, to_user)
#import pdb; pdb.set_trace()
# PDF preparation file for confirmation of service request
information_to_include = get_data_for_service_confirmation(str(new_service.serviceRequestNumber))
pdf_file_name = str(new_service.serviceRequestNumber) + '.pdf'
pdf_file = create_pdf(request, information_to_include, drylab_config.REQUESTED_CONFIRMATION_SERVICE, pdf_file_name)
'''
fs = FileSystemStorage(drylab_config.OUTPUT_DIR_TEMPLATE)
with fs.open(pdf_file_name) as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'inline;filename=' + pdf_file_name
return response
'''
#import pdb;pdb.set_trace()
pdf_url=pdf_file.replace(settings.BASE_DIR,'')
download_file = '<a href="'+ pdf_url + '">Download the service request confirmation file</a>'
return render(request,'django_utils/info_page.html',{'content':['Your service request has been successfully recorded.',
'The sequence number assigned for your request is: ', new_service.serviceRequestNumber,
'Keep this number safe for refering your request', download_file ,
'You will be contacted shortly.']})
else:
return render(request, 'django_utils/error_page.html',{'content':['Your service request cannot be recorded.',
'Check that all information is provided correctly.',
'If problem persist, contact your administrator']})
else:
form = ServiceRequestFormInternalSequencing()
# getting projects from user sharing list
user_groups = request.user.groups.values_list('name',flat=True)
if len (user_groups) > 0 :
sharing_list = []
for user in user_groups :
#import pdb; pdb.set_trace()
if User.objects.filter(username__exact = user).exists():
sharing_list.append(User.objects.get(username__exact = user).id)
sharing_list.append(request.user.id)
form.fields['serviceProjectNames'].queryset = Projects.objects.filter(user_id__in = sharing_list)
else:
form.fields['serviceProjectNames'].queryset = Projects.objects.filter(user_id__exact = request.user.id)
form.fields['serviceAvailableService'].queryset = AvailableService.objects.filter(availServiceDescription__exact="Genomic data analysis").get_descendants(include_self=True)
return render(request, 'iSkyLIMS_drylab/RequestForm.html' , { 'form' : form , 'request_internal': 'request_internal'})
if serviceRequestType == 'external_sequencing':
if request.method == "POST":
form = ServiceRequestFormExternalSequencing(data=request.POST,files=request.FILES)
if form.is_valid():
new_service = form.save(commit=False)
new_service.serviceStatus = "recorded"
new_service.serviceUserId = User.objects.get(id=request.user.id)
new_service.serviceRequestInt = increment_service_number(request.user)
new_service.serviceRequestNumber = create_service_id(new_service.serviceRequestInt,request.user)
new_service.save()
form.save_m2m()
## Send email
subject = 'Service ' + new_service.serviceRequestNumber + " has been recorded"
body_message = 'Dear ' + request.user.username + "\n Your service " + new_service.serviceRequestNumber + " has been recorded. You will received the resolution of the request as soon as possible.\n Kind regards \n BU-ISCIII \n bioinformatica@isciii.es"
from_user = 'bioinformatica@isciii.es'
to_user = [request.user.email,'bioinformatica@isciii.es']
send_mail (subject, body_message, from_user, to_user)
# PDF preparation file for confirmation of service request
information_to_include = get_data_for_service_confirmation(str(new_service.serviceRequestNumber))
pdf_file_name = str(new_service.serviceRequestNumber) + '.pdf'
pdf_file = create_pdf(request, information_to_include, drylab_config.REQUESTED_CONFIRMATION_SERVICE, pdf_file_name)
'''
fs = FileSystemStorage(drylab_config.OUTPUT_DIR_TEMPLATE)
with fs.open(pdf_file_name) as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'inline;filename=' + pdf_file_name
return response
'''
pdf_url = pdf_file.replace(settings.BASE_DIR,'')
download_file = '<a href="'+ pdf_url + '">Download the service request confirmation file</a>'
return render(request,'django_utils/info_page.html',{'content':['Your service request has been successfully recorded.',
'The sequence number assigned for your request is: ', new_service.serviceRequestNumber,
'Keep this number safe for refering your request', download_file ,
'You will be contacted shortly.']})
else: #No POST
form = ServiceRequestFormExternalSequencing()
form.fields['serviceAvailableService'].queryset = AvailableService.objects.filter(availServiceDescription__exact="Genomic data analysis").get_descendants(include_self=True)
return render(request, 'iSkyLIMS_drylab/RequestForm.html' , { 'form' : form , 'request_external': 'request_external' })
@login_required
def service_request_external_sequencing(request):
if request.method == "POST":
form = ServiceRequestFormExternalSequencing(data=request.POST,files=request.FILES)
if form.is_valid():
new_service = form.save(commit=False)
new_service.serviceStatus = "recorded"
new_service.serviceUserId = User.objects.get(id=request.user.id)
new_service.serviceRequestInt = increment_service_number(request.user)
new_service.serviceRequestNumber = create_service_id(new_service.serviceRequestInt,request.user)
new_service.save()
form.save_m2m()
# PDF preparation file for confirmation of service request
information_to_include = get_data_for_service_confirmation(str(new_service.serviceRequestNumber))
pdf_file_name = str(new_service.serviceRequestNumber) + '.pdf'
pdf_file = create_pdf(request, information_to_include, drylab_config.REQUESTED_CONFIRMATION_SERVICE, pdf_file_name)
'''
fs = FileSystemStorage(drylab_config.OUTPUT_DIR_TEMPLATE)
with fs.open(pdf_file_name) as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'inline;filename=' + pdf_file_name
return response
'''
pdf_url = pdf_file.replace(settings.BASE_DIR,'')
download_file = '<a href="'+ pdf_url + '">Download the service request confirmation file</a>'
return render(request,'django_utils/info_page.html',{'content':['Your service request has been successfully recorded.',
'The sequence number assigned for your request is: ', new_service.serviceRequestNumber,
'Keep this number safe for refering your request', download_file ,
'You will be contacted shortly.']})
else:
form = ServiceRequestFormExternalSequencing()
form.fields['serviceAvailableService'].queryset = AvailableService.objects.filter(availServiceDescription__exact="Genomic data analysis").get_descendants(include_self=True)
return render(request, 'iSkyLIMS_drylab/RequestForm.html' , { 'form' : form })
@login_required
def counseling_request(request):
if request.method == "POST":
form = ServiceRequestForm_extended(data=request.POST,files=request.FILES)
if form.is_valid():
new_service = form.save(commit=False)
new_service.serviceStatus = "recorded"
new_service.serviceUserId = User.objects.get(id=request.user.id)
new_service.serviceRequestInt = increment_service_number(request.user)
new_service.serviceRequestNumber = create_service_id(new_service.serviceRequestInt,request.user)
new_service.save()
form.save_m2m()
## Send email
subject = 'Service ' + new_service.serviceRequestNumber + " has been recorded"
body_message = 'Dear ' + request.user.username + "\n Your service " + new_service.serviceRequestNumber + " has been recorded. You will recieved the resolution of the request as soon as possible.\n Kind regards \n BU-ISCIII \n bioinformatica@isciii.es"
from_user = 'bioinformatica@isciii.es'
to_user = [request.user.email,'bioinformatica@isciii.es']
send_mail (subject, body_message, from_user, to_user)
# PDF preparation file for confirmation of service request
information_to_include = get_data_for_service_confirmation(str(new_service.serviceRequestNumber))
pdf_file_name = str(new_service.serviceRequestNumber) + '.pdf'
pdf_file = create_pdf(request, information_to_include, drylab_config.REQUESTED_CONFIRMATION_SERVICE, pdf_file_name)
'''
fs = FileSystemStorage(drylab_config.OUTPUT_DIR_TEMPLATE)
with fs.open(pdf_file_name) as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'inline;filename=' + pdf_file_name
return response
'''
pdf_url = pdf_file.replace(settings.BASE_DIR,'')
download_file = '<a href="'+ pdf_url + '">Download the service request confirmation file</a>'
return render(request,'django_utils/info_page.html',{'content':['Your service request has been successfully recorded.',
'The sequence number assigned for your request is: ', new_service.serviceRequestNumber,
'Keep this number safe for refering your request', download_file ,
'You will be contacted shortly.']})
else:
#import pdb; pdb.set_trace()
return render(request,'django_utils/error_page.html',{'content':['Your service request cannot be recorded.',
'Check that all information is provided correctly.']})
else:
form = ServiceRequestForm_extended()
form.fields['serviceAvailableService'].queryset = AvailableService.objects.filter(availServiceDescription__exact="Bioinformatics consulting and training").get_descendants(include_self=True)
return render(request, 'iSkyLIMS_drylab/RequestForm.html' , { 'form' : form , 'consulting_request': 'consulting_request'})
@login_required
def infrastructure_request(request):
if request.method == "POST":
form = ServiceRequestForm_extended(data=request.POST or None,files=request.FILES)
#import pdb; pdb.set_trace()
if form.is_valid():
new_service = form.save(commit=False)
new_service.serviceStatus = "recorded"
new_service.serviceUserId = User.objects.get(id=request.user.id)
new_service.serviceRequestInt = increment_service_number(request.user)
new_service.serviceRequestNumber = create_service_id(new_service.serviceRequestInt,request.user)
#import pdb; pdb.set_trace()
new_service.save()
form.save_m2m()
## Send email
subject = 'Service ' + new_service.serviceRequestNumber + " has been recorded"
body_message = 'Dear ' + request.user.username + "\n Your service " + new_service.serviceRequestNumber + " has been recorded. You will received the resolution of the request as soon as possible.\n Kind regards \n BU-ISCIII \n bioinformatica@isciii.es"
from_user = 'bioinformatica@isciii.es'
to_user = [request.user.email,'bioinformatica@isciii.es']
send_mail (subject, body_message, from_user, to_user)
information_to_include = get_data_for_service_confirmation(str(new_service.serviceRequestNumber))
pdf_file_name = str(new_service.serviceRequestNumber) + '.pdf'
pdf_file = create_pdf(request, information_to_include, drylab_config.REQUESTED_CONFIRMATION_SERVICE, pdf_file_name)
pdf_url = pdf_file.replace(settings.BASE_DIR,'')
download_file = '<a href="'+ pdf_url + '">Download the service request confirmation file</a>'
return render(request,'django_utils/info_page.html',{'content':['Your service request has been successfully recorded.',
'The sequence number assigned for your request is: ', new_service.serviceRequestNumber,
'Keep this number safe for refering your request',download_file,'You will be contacted shortly.']})
else:
#import pdb; pdb.set_trace()
return render(request,'django_utils/error_page.html',{'content':['Your service request cannot be recorded.',
'Check that all information is provided correctly.']})
else:
form = ServiceRequestForm_extended()
form.fields['serviceAvailableService'].queryset = AvailableService.objects.filter(availServiceDescription__exact="User support").get_descendants(include_self=True)
#pdb.set_trace()
#form.helper[1].update_atrributes(hidden="true")
return render(request, 'iSkyLIMS_drylab/RequestForm.html' , { 'form' : form , 'infrastructure_request': 'infrastructure_request'})
'''
def get_service_information (service_id):
service= Service.objects.get(pk=service_id)
display_service_details = {}
text_for_dates = ['Service Date Creation', 'Approval Service Date', 'Rejected Service Date']
service_dates = []
display_service_details['service_name'] = service.serviceRequestNumber
# get the list of projects
projects_in_service = {}
projects_class = service.serviceProjectNames.all()
for project in projects_class:
project_id = project.id
projects_in_service[project_id]=project.get_project_name()
display_service_details['projects'] = projects_in_service
display_service_details['user_name'] = service.serviceUserId.username
display_service_details['file'] = os.path.join(settings.MEDIA_URL,str(service.serviceFile))
display_service_details['state'] = service.serviceStatus
display_service_details['service_notes'] = service.serviceNotes
dates_for_services = service.get_service_dates()
for i in range(len(dates_for_services)):
service_dates.append([text_for_dates[i],dates_for_services[i]])
display_service_details['service_dates'] = service_dates
if service.serviceStatus != 'approved'and service.serviceStatus != 'recorded':
# get the proposal for the delivery date
#import pdb; pdb.set_trace()
resolution_folder = Resolution.objects.filter(resolutionServiceID = service).last().resolutionFullNumber
display_service_details['resolution_folder'] = resolution_folder
resolution_estimated_date = Resolution.objects.filter(resolutionServiceID = service).last().resolutionEstimatedDate
if resolution_estimated_date is None:
resolution_estimated_date = "Not defined yet"
display_service_details['estimated_delivery_date'] = resolution_estimated_date
# get all services
display_service_details['nodes']= service.serviceAvailableService.all()
# adding actions fields
if service.serviceStatus != 'rejected' or service.serviceStatus != 'archived':
display_service_details['add_resolution_action'] = service_id
if service.serviceStatus == 'queued':
resolution_id = Resolution.objects.filter(resolutionServiceID = service).last().id
display_service_details['add_in_progress_action'] = resolution_id
if service.serviceStatus == 'in_progress':
resolution_id = Resolution.objects.filter(resolutionServiceID = service).last().id
display_service_details['add_delivery_action'] = resolution_id
if Resolution.objects.filter(resolutionServiceID = service).exists():
resolution_list = Resolution.objects.filter(resolutionServiceID = service)
resolution_info =[]
for resolution_item in resolution_list :
resolution_info.append([resolution_item.get_resolution_information()])
display_service_details['resolutions'] = resolution_info
#import pdb; pdb.set_trace()
if Resolution.objects.filter(resolutionServiceID = service).exists():
resolution_list = Resolution.objects.filter(resolutionServiceID = service)
delivery_info = []
for resolution_id in resolution_list :
if Delivery.objects.filter(deliveryResolutionID = resolution_id).exists():
delivery = Delivery.objects.get(deliveryResolutionID = resolution_id)
delivery_info.append([delivery.get_delivery_information()])
display_service_details['delivery'] = delivery_info
return display_service_details
'''
@login_required
def display_service (request, service_id):
if request.user.is_authenticated:
try:
groups = Group.objects.get(name='Admin_iSkyLIMS')
if groups not in request.user.groups.all():
return render (request,'django_utils/error_page.html', {'content':['You do have the enough privileges to see this page ','Contact with your administrator .']})
except:
return render (request,'django_utils/error_page.html', {'content':['You do have the enough privileges to see this page ','Contact with your administrator .']})
else:
#redirect to login webpage
return redirect ('/accounts/login')
if Service.objects.filter(pk=service_id).exists():
# displays the service information with the latest changes done using the forms
display_service_details = get_service_information(service_id)
#import pdb; pdb.set_trace()
return render (request,'iSkyLIMS_drylab/display_service.html',{'display_service': display_service_details})
else:
return render (request,'django_utils/error_page.html', {'content':['The service that you are trying to get does not exist ','Contact with your administrator .']})
@login_required
def search_service (request):
if request.user.is_authenticated:
try:
groups = Group.objects.get(name='Admin_iSkyLIMS')
if groups not in request.user.groups.all():
return render (request,'django_utils/error_page.html', {'content':['You do have the enough privileges to see this page ','Contact with your administrator .']})
except:
return render (request,'django_utils/error_page.html', {'content':['You do have the enough privileges to see this page ','Contact with your administrator .']})
else:
#redirect to login webpage
return redirect ('/accounts/login')
if request.method == 'POST' and request.POST['action'] == 'searchservice':
service_number_request = request.POST['servicenumber']
service_state = request.POST['servicestate']
start_date=request.POST['startdate']
end_date=request.POST['enddate']
center = request.POST['center']
user_name = request.POST['username']
if service_number_request == '' and service_state == '' and start_date == '' and end_date == '' and center == '' and user_name =='':
services_search_list = {}
center_list_abbr = []
center_availables = Center.objects.all().order_by ('centerAbbr')
for center in center_availables:
center_list_abbr.append (center.centerAbbr)
services_search_list ['centers'] = center_list_abbr
services_search_list ['status'] = STATUS_CHOICES
#import pdb; pdb.set_trace()
return render( request,'iSkyLIMS_drylab/searchService.html',{'services_search_list': services_search_list })
### check the right format of start and end date
if start_date != '':
try:
datetime.datetime.strptime(start_date, '%Y-%m-%d')
except:
return render (request,'django_utils/error_page.html', {'content':['The format for the "Start Date Search" Field is incorrect ',
'ADVICE:', 'Use the format (DD-MM-YYYY)']})
if end_date != '':
try:
datetime.datetime.strptime(end_date, '%Y-%m-%d')
except:
return render (request,'django_utils/error_page.html', {'content':['The format for the "End Date Search" Field is incorrect ',
'ADVICE:', 'Use the format (DD-MM-YYYY)']})
if service_number_request == '' and service_state == '':
services_found = Service.objects.all()
if service_number_request != '':
# check if the requested service in the form matches exactly with the existing service in DB
if Service.objects.filter(serviceRequestNumber__exact = service_number_request).exists():
#import pdb; pdb.set_trace()
services_found = Service.objects.get(serviceRequestNumber__exact = service_number_request)
redirect_page = '/drylab/display_service=' + str(services_found.id)
return redirect (redirect_page)
if Service.objects.filter(serviceRequestNumber__icontains = service_number_request).exists():
services_found = Service.objects.filter(serviceRequestNumber__icontains = service_number_request)
else:
return render (request,'django_utils/error_page.html', {'content':['No matches have been found for the service number ', service_number_request ]})
if service_state != '':
if service_number_request =='':
services_found = Service.objects.all()
if services_found.filter(serviceStatus__exact = service_state).exists():
services_found = services_found.filter(serviceStatus__exact = service_state)
else:
return render (request,'django_utils/error_page.html', {'content':['No matches have been found for the service number in state', service_state ]})
if start_date !='' and end_date != '':
if services_found.filter(serviceCreatedOnDate__range=(start_date, end_date)).exists():
services_found = services_found.filter(serviceCreatedOnDate__range=(start_date, end_date))
else:
return render (request,'django_utils/error_page.html', {'content':['There are no services containing ', service_number_request,
' created between ', start_date, 'and the ', end_date]})
if start_date !='' and end_date == '':
if services_found.filter(serviceCreatedOnDate__gte = start_date).exists():
services_found = services_found.filter(serviceCreatedOnDate__gte = start_date)
else:
return render (request,'django_utils/error_page.html', {'content':['There are no services containing ', service_number_request,
' created before ', start_date]})
if start_date =='' and end_date != '':
if services_found.filter(serviceCreatedOnDate__lte = end_date).exists():
services_found = services_found.filter(serviceCreatedOnDate__lte = end_date)
else:
return render (request,'django_utils/error_page.html', {'content':['There are no services containing ', service_number_request,
' finish before ', end_date]})
if center != '':
if services_found.filter(serviceRequestNumber__icontains = center).exists():
services_found = services_found.filter(serviceRequestNumber__icontains = center)
else:
return render (request,'django_utils/error_page.html', {'content':['There are no services related to the requested center', center]})
if user_name != '':
if User.objects.filter (username__icontains = user_name).exists():
user_id = User.objects.get (username__icontains = user_name).id
else:
return render (request,'django_utils/error_page.html', {'content':['The user name ', user_name, 'is not defined in iSkyLIMS']})
if services_found.filter(serviceUserId = user_id).exists():
services_found = services_found.filter(serviceUserId = user_id)
else:
return render (request,'django_utils/error_page.html', {'content':['There are no services requested by the user', center]})
#If only 1 service mathes the user conditions, then get the user information
if len(services_found) == 1 :
redirect_page = '/drylab/display_service=' + str(services_found[0].id)
return redirect (redirect_page)
else:
display_multiple_services ={}
s_list = {}
for service_item in services_found:
service_id = service_item.id
service_number = service_item.serviceRequestNumber
service_status = service_item.serviceStatus
service_center = service_item.serviceSeqCenter
s_list [service_id]=[[service_number, service_status, service_center]]
display_multiple_services['s_list'] = s_list
return render (request,'iSkyLIMS_drylab/searchService.html', {'display_multiple_services': display_multiple_services})
services_search_list = {}
#import pdb; pdb.set_trace()
center_list_abbr = []
center_availables = Center.objects.all().order_by ('centerAbbr')
for center in center_availables:
center_list_abbr.append (center.centerAbbr)
services_search_list ['centers'] = center_list_abbr
services_search_list ['status'] = STATUS_CHOICES
#import pdb; pdb.set_trace()
return render( request,'iSkyLIMS_drylab/searchService.html',{'services_search_list': services_search_list })
@login_required
def pending_services (request):
if request.user.is_authenticated:
try:
groups = Group.objects.get(name='Admin_iSkyLIMS')
if groups not in request.user.groups.all():
return render (request,'django_utils/error_page.html', {'content':['You do have the enough privileges to see this page ','Contact with your administrator .']})
except:
return render (request,'django_utils/error_page.html', {'content':['You do have the enough privileges to see this page ','Contact with your administrator .']})
else:
#redirect to login webpage
return redirect ('/accounts/login')
pending_services_details = {}
recorded, queued, in_progress = {}, {}, {}
if Service.objects.filter(serviceStatus__exact = 'recorded').exists():
services_in_request = Service.objects.filter(serviceStatus__exact = 'recorded').order_by('-serviceCreatedOnDate')
for services in services_in_request:
recorded[services.id]= [services.get_service_information().split(';')]
pending_services_details['recorded'] = recorded
if Service.objects.filter(serviceStatus__exact = 'queued').exists():
services_in_queued = Service.objects.filter(serviceStatus__exact = 'queued').order_by('-serviceCreatedOnDate')
for services in services_in_queued:
queued[services.id]= [services.get_service_information_with_service_name().split(';')]
pending_services_details['queued'] = queued
if Service.objects.filter(serviceStatus__exact = 'in_progress').exists():
services_in_progress = Service.objects.filter(serviceStatus__exact = 'in_progress').order_by('-serviceCreatedOnDate')
for services in services_in_progress:
in_progress[services.id]= [services.get_service_information_with_service_name().split(';')]
pending_services_details['in_progress'] = in_progress
number_of_services = {}
number_of_services ['RECORDED'] = len (recorded)
number_of_services ['QUEUED'] = len (queued)
number_of_services ['IN PROGRESS'] = len (in_progress)
data_source = graphic_3D_pie('Number of Pending Services', '', '', '','fint',number_of_services)
graphic_pending_services = FusionCharts("pie3d", "ex1" , "425", "350", "chart-1", "json", data_source)
pending_services_details ['graphic_pending_services'] = graphic_pending_services.render()
#import pdb ; pdb.set_trace()
return render (request, 'iSkyLIMS_drylab/pendingServices.html', {'pending_services': pending_services_details})
@login_required
def add_resolution (request, service_id):
if request.user.is_authenticated:
try:
groups = Group.objects.get(name='Admin_iSkyLIMS')
if groups not in request.user.groups.all():
return render (request,'django_utils/error_page.html', {'content':['You do have the enough privileges to see this page ','Contact with your administrator .']})
except:
return render (request,'django_utils/error_page.html', {'content':['You do have the enough privileges to see this page ','Contact with your administrator .']})
else:
#redirect to login webpage
return redirect ('/accounts/login')
if request.method == "POST":
form = AddResolutionService(data=request.POST)
#import pdb ; pdb.set_trace()
if form.is_valid():
service_acepted_rejected = request.POST['radio_buttons']
new_resolution = form.save(commit=False)
#import pdb ; pdb.set_trace()
service_reference = Service.objects.get(pk=service_id)
if len(Resolution.objects.filter(resolutionServiceID = service_reference)) == 0:
service_reference.serviceOnApprovedDate = datetime.date.today()
number_list = []
number_list.append(str(service_reference.serviceRequestNumber))
number_list.append(str(datetime.date.today()).replace('-',''))
number_list.append(new_resolution.resolutionFullNumber)
number_list.append(str(service_reference.serviceUserId))
number_list.append('S')
new_resolution.resolutionFullNumber = '_'.join(number_list)
else:
new_resolution.resolutionFullNumber = Resolution.objects.filter(resolutionServiceID = service_reference).last().resolutionFullNumber
if service_acepted_rejected == 'accepted':
service_reference.serviceStatus = "approved"
else:
service_reference.serviceStatus = "rejected"
service_reference.serviceOnRejectedDate = datetime.date.today()
service_reference.save()
if Resolution.objects.filter(resolutionServiceID = service_reference).exists():
resolution_count = Resolution.objects.filter(resolutionServiceID = service_reference).count()
resolution_number = str(service_reference.serviceRequestNumber) + '.' + str(resolution_count +1 )
else:
resolution_number = str(service_reference.serviceRequestNumber) + '.1'
new_resolution.resolutionServiceID = service_reference
new_resolution.resolutionNumber = resolution_number
new_resolution.resolutionOnQueuedDate = datetime.date.today()
if service_reference.serviceStatus == "approved":
service_reference.serviceStatus = "queued"
service_reference.save()
new_resolution.save()
form.save_m2m()
# create a new resolution to be added to the service folder including the path where file is stored
information = get_data_for_resolution(str(service_reference.serviceRequestNumber), resolution_number )
pdf_name = resolution_number + ".pdf"
resolution_file = create_pdf(request,information, drylab_config.RESOLUTION_TEMPLATE, pdf_name)
if len(Resolution.objects.filter(resolutionServiceID = service_reference)) == 1:
## create service folder structure on the samba server. It is the first time to create a resolution
# move the resolution and the service request to the right folders
service_request_file =os.path.join (settings.BASE_DIR, drylab_config.OUTPUT_DIR_TEMPLATE,str(service_reference.serviceRequestNumber+ '.pdf'))
if service_reference.serviceFile != '' :
service_file_uploaded = os.path.join (settings.MEDIA_ROOT, str(service_reference.serviceFile))
else :
service_file_uploaded = ''
conn = open_samba_connection()
if conn is False:
return render (request, 'django_utils/error_page.html', {'content': ['Creation of the structure can not be done because there is not communication to : ', drylab_config.SAMBA_REMOTE_SERVER_NAME]})
#import pdb ; pdb.set_trace()
result_creation_structure = create_service_structure (conn, service_request_file , service_file_uploaded, new_resolution.resolutionFullNumber ,resolution_file)
if result_creation_structure != True:
return render (request, 'django_utils/error_page.html', {'content': ['Creation of the structure can not be done because of ' , result_creation_structure]})
else:
# connect to SAMBA server and copy the new resolution file into resolution folder
conn = open_samba_connection()
if conn is False:
return render (request, 'django_utils/error_page.html', {'content': ['Creation of the structure can not be done because there is not communication to : ', drylab_config.SAMBA_REMOTE_SERVER_NAME]})
result_adding_resolution_file = add_new_resolution_file (conn, new_resolution.resolutionFullNumber,resolution_file,service_reference.serviceCreatedOnDate.year)
if result_adding_resolution_file is not True:
return render (request, 'django_utils/error_page.html', {'content':['Error when adding the new resolution file ', result_adding_resolution_file]})
## Send email
service_user_mail = service_reference.serviceUserId.email
subject = 'Service ' + service_reference.serviceRequestNumber + " has been updated"
if service_acepted_rejected == "accepted":
body_message = 'Dear ' + service_reference.serviceUserId.username + "\n A new resolution has been added for your service: " + resolution_number + "\n. Your service has been "+ service_reference.serviceStatus + " and your delivery estimated date is " + new_resolution.resolutionEstimatedDate.strftime('%d %B %Y') + ".\n Your service is now queued and you will be notified when it is updated. \n Kind regards \n BU-ISCIII \n bioinformatica@isciii.es"
else:
body_message= 'Dear ' + service_reference.serviceUserId.username + "\n A new resolution has been added for your service: " + resolution_number + "\n. Your service has been "+ service_reference.serviceStatus + " because it does not fullfil our requirements or is not in our services portfolio. If you have any question please contact us. \n Kind regards \n BU-ISCIII \n bioinformatica@isciii.es"
from_user = 'bioinformatica@isciii.es'
to_user = [service_user_mail,'bioinformatica@isciii.es']
send_mail (subject, body_message, from_user, to_user)
#import pdb ; pdb.set_trace()
return render(request,'django_utils/info_page.html',{'content':['Your resolution proposal has been successfully recorded with Resolution Number.', resolution_number]})
else:
if Service.objects.filter(pk=service_id).exists():
service_id= Service.objects.get(pk=service_id)
service_number = service_id.serviceRequestNumber
#import pdb ; pdb.set_trace()
if Resolution.objects.filter(resolutionServiceID__exact = service_id).exists():
existing_resolution = Resolution.objects.filter(resolutionServiceID__exact = service_id).last()
resolutionFullNumber = existing_resolution.resolutionFullNumber
else :
resolutionFullNumber =''
form = AddResolutionService(initial= {'resolutionFullNumber': resolutionFullNumber})
#import pdb ; pdb.set_trace()
return render(request, 'iSkyLIMS_drylab/addResolution.html' , { 'form' : form ,'prueba':'pepe'})
'''
def open_samba_connection():
## open samba connection
try:
conn=SMBConnection(drylab_config.SAMBA_USER_ID, drylab_config.SAMBA_USER_PASSWORD, drylab_config.SAMBA_SHARED_FOLDER_NAME,
drylab_config.SAMBA_REMOTE_SERVER_NAME, use_ntlm_v2=drylab_config.SAMBA_NTLM_USED, domain = drylab_config.SAMBA_DOMAIN)
conn.connect(drylab_config.SAMBA_IP_SERVER, int(drylab_config.SAMBA_PORT_SERVER))
except:
return False
return conn
'''
def get_data_for_resolution(service_requested, resolution_number ):
information, user, resolution_data = {}, {}, {}
# get service object
service = Service.objects.get(serviceRequestNumber = service_requested)
service_number ,run_specs, center, platform = service.get_service_information().split(';')
# get resolution object
resolution = Resolution.objects.get(resolutionNumber = resolution_number)
resolution_info = resolution.get_resolution_information()
# get profile object
user_id = service.serviceUserId.id
information['resolution_number'] = resolution_number
information['requested_date'] = service.get_service_creation_time()
information['resolution_date'] = resolution_info[4]
information['nodes']= service.serviceAvailableService.all()
user['name'] = service.serviceUserId.first_name
user['surname'] = service.serviceUserId.last_name
user['area'] = Profile.objects.get(profileUserID = user_id).profileArea
user['center'] = Profile.objects.get(profileUserID = user_id).profileCenter
user['position'] = Profile.objects.get(profileUserID = user_id).profilePosition
user['phone'] = Profile.objects.get(profileUserID = user_id).profileExtension
user['email'] = service.serviceUserId.email
information['user'] = user
resolution_info_split = resolution_info[1].split('_')
resolution_data['acronym'] = resolution_info_split[2]
resolution_data['estimated_date'] = resolution_info[3]
resolution_data['notes'] = resolution_info[6]
resolution_data['decission'] = service.serviceStatus
information['service_data'] = service.serviceNotes
resolution_data['folder'] = resolution_info[1]
information['resolution_data'] = resolution_data
return information
'''
def test (request):
resolution_number = 'SRVIIER001.1'
service_requested = 'SRVIIER001'
from weasyprint import HTML, CSS
from django.template.loader import get_template
from django.core.files.storage import FileSystemStorage
from django.http import HttpResponse
from weasyprint.fonts import FontConfiguration
information, user, resolution_data = {}, {}, {}
# get service object
service = Service.objects.get(serviceRequestNumber = service_requested)
service_number ,run_specs, center, platform = service.get_service_information().split(';')
# get resolution object
resolution = Resolution.objects.get(resolutionNumber = resolution_number)
resolution_info = resolution.get_resolution_information()
# get profile object
user_id = service.serviceUserId.id
information['resolution_number'] = resolution_number
information['requested_date'] = service.get_service_creation_time()
information['resolution_date'] = resolution_info[4]
information['nodes']= service.serviceAvailableService.all()
user['name'] = service.serviceUserId.first_name
user['surname'] = service.serviceUserId.last_name
user_id = service.serviceUserId.id
user['area'] = Profile.objects.get(profileUserID = user_id).profileArea
user['center'] = Profile.objects.get(profileUserID = user_id).profileCenter
user['position'] = Profile.objects.get(profileUserID = user_id).profilePosition
user['phone'] = Profile.objects.get(profileUserID = user_id).profileExtension
user['email'] = service.serviceUserId.email
information['user'] = user
resolution_data['folder'] = resolution_info[1]
resolution_data['estimated_date'] = resolution_info[3]
resolution_data['notes'] = resolution_info[6]
resolution_data['decission'] = service.serviceStatus
information['service_data'] = service.serviceNotes
resolution_data['folder'] = resolution_info[1]
information['resolution_data'] = resolution_data
html_string = render_to_string('resolution_template.html', {'information': information})
html = HTML(string=html_string, base_url=request.build_absolute_uri()).write_pdf('documents/drylab/res_pdf.pdf',stylesheets=[CSS(settings.STATIC_ROOT +
drylab_config.CSS_FOR_PDF)])
fs = FileSystemStorage('documents/drylab')
with fs.open('res_pdf.pdf') as pdf:
response = HttpResponse(pdf, content_type='application/pdf')
# save pdf file as attachment
#response['Content-Disposition'] = 'attachment; filename="mypdf.pdf"'
response['Content-Disposition'] = 'inline;filename=res_pdf.pdf'
return response
'''
def add_new_resolution_file (conn, full_service_path,resolution_file,year):
temp_file=resolution_file.split('/')
resolution_name_file = temp_file[-1]
resolution_remote_file = os.path.join(drylab_config.SAMBA_SERVICE_FOLDER,str(year),full_service_path,drylab_config.FOLDERS_FOR_SERVICES[1],resolution_name_file)
try:
with open(resolution_file ,'rb') as res_samba_fp:
conn.storeFile(drylab_config.SAMBA_SHARED_FOLDER_NAME, resolution_remote_file, res_samba_fp)
except:
return ( 'Unable to copy the resolution file ',resolution_remote_file,resolution_name_file)
return True
def create_service_structure (conn, service_request_file, service_file_uploaded, full_service_path, resolution_file):
## service_request_file and resolution_file contains the full path where these files
## are stored on iSkyLIMS. It means that OUTPUT_DIR_TEMPLATE value is added to thes variable
## to store the files on the remote system we need to have the full pathe where these files
## are located, but also the file name without including the path, in order to add only
## the file name to the remote path. To get only the file name we split the variable (containing
## path and file name ) to fetch only the file name
# get the information for creating the subfolders
time_now = datetime.datetime.now()
year = str(time_now.year)
# check if year directory already exists on remote server
file_list = conn.listPath( drylab_config.SAMBA_SHARED_FOLDER_NAME, drylab_config.SAMBA_SERVICE_FOLDER)
year_folder_exists = False
for sh_file in file_list:
if sh_file.filename == year:
year_folder_exists = True
year_folder = os.path.join(drylab_config.SAMBA_SERVICE_FOLDER, year)
if not year_folder_exists :
conn.createDirectory (drylab_config.SAMBA_SHARED_FOLDER_NAME, year_folder)
#import pdb ; pdb.set_trace()
service_path = os.path.join(year_folder, full_service_path)
#create the directory for the new service
conn.createDirectory (drylab_config.SAMBA_SHARED_FOLDER_NAME, service_path)
for sub_folder in drylab_config.FOLDERS_FOR_SERVICES:
sub_folder_path = os.path.join(service_path,sub_folder)
conn.createDirectory(drylab_config.SAMBA_SHARED_FOLDER_NAME, sub_folder_path)
#import pdb ; pdb.set_trace()
#copy service confirmation file into request folder
temp_file=resolution_file.split('/')
resolution_name_file = temp_file[-1]
resolution_remote_file = os.path.join(service_path,drylab_config.FOLDERS_FOR_SERVICES[1],resolution_name_file)
try:
with open(resolution_file ,'rb') as res_samba_fp:
conn.storeFile(drylab_config.SAMBA_SHARED_FOLDER_NAME, resolution_remote_file, res_samba_fp)
except:
return 'ERROR:: Unable to copy resolution file'
temp_file=service_request_file.split('/')
#import pdb; pdb.set_trace()
request_name_file = temp_file[-1]
request_remote_file = os.path.join(service_path,drylab_config.FOLDERS_FOR_SERVICES[0],request_name_file)
#import pdb; pdb.set_trace()
try:
with open(service_request_file ,'rb') as req_samba_fp:
conn.storeFile(drylab_config.SAMBA_SHARED_FOLDER_NAME, request_remote_file, req_samba_fp)
except:
return 'ERROR:: Unable to copy service requested file '
if service_file_uploaded != '':
temp_file_name = service_file_uploaded.split('/')
uploaded_name_file = temp_file_name [-1]
uploaded_remote_file = os.path.join(service_path, drylab_config.FOLDERS_FOR_SERVICES[0],uploaded_name_file)
#import pdb; pdb.set_trace()
try:
with open(service_file_uploaded ,'rb') as upload_samba_fp:
conn.storeFile(drylab_config.SAMBA_SHARED_FOLDER_NAME, uploaded_remote_file, upload_samba_fp)
except:
return 'ERROR:: Unable to copy file uploaded by the investigator'
# deleting the service_request_file and resolution_file from iSkyLIMS
try:
os.remove(service_request_file)
os.remove(resolution_file)
except:
return 'ERROR:: Unable to delete the service_requested_file/ resolution_file'
return True
@login_required
def add_in_progress (request, resolution_id):
if request.user.is_authenticated: