33
33
from coldfront .plugins .slurm .utils import SlurmError
34
34
35
35
from coldfront .core .project .models import ProjectUser , Project
36
+ from pandas .io .clipboard import is_available
36
37
37
38
logger = logging .getLogger (__name__ )
38
39
@@ -188,6 +189,18 @@ def test_func(self):
188
189
messages .error (
189
190
self .request , 'You do not have permission to add resource attributes.' )
190
191
192
+ def dispatch (self , request , * args , ** kwargs ):
193
+ resource_obj = get_object_or_404 (Resource , pk = self .kwargs .get ('pk' ))
194
+ err = None
195
+ if resource_obj .is_available is False :
196
+ err = 'You cannot add resource attributes to retired allocations.'
197
+ if err :
198
+ messages .error (request , err )
199
+ return HttpResponseRedirect (
200
+ reverse ('resource-detail' , kwargs = {'pk' : resource_obj .pk })
201
+ )
202
+ return super ().dispatch (request , * args , ** kwargs )
203
+
191
204
def get_context_data (self , ** kwargs ):
192
205
context = super ().get_context_data (** kwargs )
193
206
pk = self .kwargs .get ('pk' )
@@ -222,6 +235,18 @@ def test_func(self):
222
235
messages .error (
223
236
self .request , 'You do not have permission to delete resource attributes.' )
224
237
238
+ def dispatch (self , request , * args , ** kwargs ):
239
+ resource_obj = get_object_or_404 (Resource , pk = self .kwargs .get ('pk' ))
240
+ err = None
241
+ if resource_obj .is_available is False :
242
+ err = 'You cannot delete resource attributes from retired allocations.'
243
+ if err :
244
+ messages .error (request , err )
245
+ return HttpResponseRedirect (
246
+ reverse ('resource-detail' , kwargs = {'pk' : resource_obj .pk })
247
+ )
248
+ return super ().dispatch (request , * args , ** kwargs )
249
+
225
250
def get (self , request , * args , ** kwargs ):
226
251
pk = self .kwargs .get ('pk' )
227
252
resource_obj = get_object_or_404 (Resource , pk = pk )
@@ -370,15 +395,86 @@ def get_queryset(self):
370
395
resource_attribute_type__name = 'Owner' ,
371
396
resource__resource_type__name = 'Compute Node'
372
397
).exclude (value__in = project_title_list )]
398
+ if self .request .user .is_superuser :
399
+ return resources .distinct ()
373
400
return resources .exclude (pk__in = not_owned_compute_nodes ).distinct ()
374
401
375
-
376
402
def get_context_data (self , ** kwargs ):
377
403
context = super ().get_context_data (
378
404
SearchFormClass = ResourceSearchForm , ** kwargs )
379
405
return context
380
406
381
407
408
+ class ResourceArchivedListView (ResourceListView ):
409
+ template_name = 'resource_archived_list.html'
410
+
411
+ def get_queryset (self ):
412
+
413
+ order_by = self .return_order ()
414
+ resource_search_form = ResourceSearchForm (self .request .GET )
415
+
416
+ if order_by == 'name' :
417
+ direction = self .request .GET .get ('direction' )
418
+ if direction == 'asc' :
419
+ resources = Resource .objects .all ().order_by (Lower ('name' ))
420
+ elif direction == 'des' :
421
+ resources = (Resource .objects .all ().order_by (Lower ('name' )).reverse ())
422
+ else :
423
+ resources = Resource .objects .all ().order_by (order_by )
424
+ else :
425
+ resources = Resource .objects .all ().order_by (order_by )
426
+ if resource_search_form .is_valid ():
427
+ data = resource_search_form .cleaned_data
428
+
429
+ if data .get ('show_allocatable_resources' ):
430
+ resources = resources .filter (is_allocatable = True )
431
+ if data .get ('resource_name' ):
432
+ resources = resources .filter (
433
+ name__icontains = data .get ('resource_name' )
434
+ )
435
+ if data .get ('resource_type' ):
436
+ resources = resources .filter (
437
+ resource_type = data .get ('resource_type' )
438
+ )
439
+
440
+ if data .get ('model' ):
441
+ resources = resources .filter (
442
+ Q (resourceattribute__resource_attribute_type__name = 'Model' ) &
443
+ Q (resourceattribute__value = data .get ('model' ))
444
+ )
445
+ if data .get ('serialNumber' ):
446
+ resources = resources .filter (
447
+ Q (resourceattribute__resource_attribute_type__name = 'SerialNumber' ) &
448
+ Q (resourceattribute__value = data .get ('serialNumber' ))
449
+ )
450
+ if data .get ('installDate' ):
451
+ resources = resources .filter (
452
+ Q (resourceattribute__resource_attribute_type__name = 'InstallDate' ) &
453
+ Q (resourceattribute__value = data .get ('installDate' ).strftime ('%m/%d/%Y' ))
454
+ )
455
+ if data .get ('serviceStart' ):
456
+ resources = resources .filter (
457
+ Q (resourceattribute__resource_attribute_type_name = 'ServiceStart' ) &
458
+ Q (resourceattribute__value = data .get ('serviceStart' ).strftime ('%m/%d/%Y' ))
459
+ )
460
+ if data .get ('serviceEnd' ):
461
+ resources = resources .filter (
462
+ Q (resourceattribute__resource_attribute_type__name = 'ServiceEnd' ) &
463
+ Q (resourceattribute__value = data .get ('serviceEnd' ).strftime ('%m/%d/%Y' ))
464
+ )
465
+ if data .get ('warrantyExpirationDate' ):
466
+ resources = resources .filter (
467
+ Q (resourceattribute__resource_attribute_type__name = 'WarrantyExpirationDate' ) &
468
+ Q (resourceattribute__value = data .get ('warrantyExpirationDate' ).strftime ('%m/%d/%Y' ))
469
+ )
470
+ if data .get ('vendor' ):
471
+ resources = resources .filter (
472
+ Q (resourceattribute__resource_attribute_type__name = 'Vendor' ) &
473
+ Q (resourceattribute__value = data .get ('vendor' ))
474
+ )
475
+ return resources .exclude (is_available = True ).distinct ()
476
+
477
+
382
478
class ResourceAllocationsEditView (LoginRequiredMixin , UserPassesTestMixin , TemplateView ):
383
479
template_name = 'resource_allocations_edit.html'
384
480
@@ -396,6 +492,8 @@ def dispatch(self, request, *args, **kwargs):
396
492
err = None
397
493
if 'Storage' in resource_obj .resource_type .name :
398
494
err = 'You cannot bulk-edit storage allocations.'
495
+ if resource_obj .is_available is False :
496
+ err = 'You cannot edit retired allocations.'
399
497
if err :
400
498
messages .error (request , err )
401
499
return HttpResponseRedirect (
0 commit comments