38
38
# Supported periodicities for evolution charts
39
39
PERIODICITY_DAILY = "d"
40
40
PERIODICITY_WEEKLY = "w"
41
- PERIODICITY_MONTHLY = "m"
42
- PERIODICITY_QUARTERLY = "q"
41
+ PERIODICITY_MONTHLY = "m"
42
+ PERIODICITY_QUARTERLY = "q"
43
43
PERIODICITY_BIANNUAL = "b"
44
44
PERIODICITY_YEARLY = "y"
45
45
PERIODICITY_ALL = "a"
@@ -182,7 +182,7 @@ def __call__(self):
182
182
return
183
183
184
184
self .member = mtool .getAuthenticatedMember ()
185
- self .periodicity = self .request .get ('p' , PERIODICITY_WEEKLY )
185
+ self .periodicity = self .request .get ('p' , PERIODICITY_WEEKLY )
186
186
self .dashboard_cookie = self .check_dashboard_cookie ()
187
187
date_range = self .get_date_range (self .periodicity )
188
188
self .date_from = date_range [0 ]
@@ -260,47 +260,47 @@ def get_date_range(self, periodicity=PERIODICITY_WEEKLY):
260
260
:rtype: [(DateTime, DateTime)]
261
261
"""
262
262
today = datetime .date .today ()
263
- if ( periodicity == PERIODICITY_DAILY ) :
263
+ if periodicity == PERIODICITY_DAILY :
264
264
# Daily, load last 30 days
265
265
date_from = DateTime () - 30
266
266
date_to = DateTime () + 1
267
- return ( date_from , date_to )
267
+ return date_from , date_to
268
268
269
- if ( periodicity == PERIODICITY_MONTHLY ) :
269
+ if periodicity == PERIODICITY_MONTHLY :
270
270
# Monthly, load last 2 years
271
271
min_year = today .year - 1 if today .month == 12 else today .year - 2
272
272
min_month = 1 if today .month == 12 else today .month
273
273
date_from = DateTime (min_year , min_month , 1 )
274
274
date_to = DateTime (today .year , today .month ,
275
275
monthrange (today .year , today .month )[1 ],
276
276
23 , 59 , 59 )
277
- return ( date_from , date_to )
277
+ return date_from , date_to
278
278
279
- if ( periodicity == PERIODICITY_QUARTERLY ) :
279
+ if periodicity == PERIODICITY_QUARTERLY :
280
280
# Quarterly, load last 4 years
281
281
m = (((today .month - 1 ) / 3 ) * 3 ) + 1
282
282
min_year = today .year - 4 if today .month == 12 else today .year - 5
283
283
date_from = DateTime (min_year , m , 1 )
284
284
date_to = DateTime (today .year , m + 2 ,
285
285
monthrange (today .year , m + 2 )[1 ], 23 , 59 ,
286
286
59 )
287
- return ( date_from , date_to )
288
- if ( periodicity == PERIODICITY_BIANNUAL ) :
287
+ return date_from , date_to
288
+ if periodicity == PERIODICITY_BIANNUAL :
289
289
# Biannual, load last 10 years
290
290
m = (((today .month - 1 ) / 6 ) * 6 ) + 1
291
291
min_year = today .year - 10 if today .month == 12 else today .year - 11
292
292
date_from = DateTime (min_year , m , 1 )
293
293
date_to = DateTime (today .year , m + 5 ,
294
294
monthrange (today .year , m + 5 )[1 ], 23 , 59 ,
295
295
59 )
296
- return ( date_from , date_to )
296
+ return date_from , date_to
297
297
298
- if ( periodicity in [PERIODICITY_YEARLY , PERIODICITY_ALL ]) :
298
+ if periodicity in [PERIODICITY_YEARLY , PERIODICITY_ALL ]:
299
299
# Yearly or All time, load last 15 years
300
300
min_year = today .year - 15 if today .month == 12 else today .year - 16
301
301
date_from = DateTime (min_year , 1 , 1 )
302
302
date_to = DateTime (today .year , 12 , 31 , 23 , 59 , 59 )
303
- return ( date_from , date_to )
303
+ return date_from , date_to
304
304
305
305
# Default Weekly, load last six months
306
306
year , weeknum , dow = today .isocalendar ()
@@ -309,7 +309,7 @@ def get_date_range(self, periodicity=PERIODICITY_WEEKLY):
309
309
else (today .month - 6 ) + 12
310
310
date_from = DateTime (min_year , min_month , 1 )
311
311
date_to = DateTime () - dow + 7
312
- return ( date_from , date_to )
312
+ return date_from , date_to
313
313
314
314
def get_sections (self ):
315
315
""" Returns an array with the sections to be displayed.
@@ -356,7 +356,7 @@ def _getStatistics(self, name, description, url, catalog, criterias, total):
356
356
results = results if total >= results else total
357
357
ratio = (float (results )/ float (total ))* 100 if results > 0 else 0
358
358
ratio = str ("%%.%sf" % 1 ) % ratio
359
- out ['legend' ] = _ ('of' ) + " " + str (total ) + ' (' + ratio + '%)'
359
+ out ['legend' ] = _ ('of' ) + " " + str (total ) + ' (' + ratio + '%)'
360
360
out ['number' ] = results
361
361
out ['percentage' ] = float (ratio )
362
362
return out
@@ -373,7 +373,7 @@ def get_analysisrequests_section(self):
373
373
filtering_allowed = self .context .bika_setup .getAllowDepartmentFiltering ()
374
374
if filtering_allowed :
375
375
cookie_dep_uid = self .request .get (FILTER_BY_DEPT_COOKIE_ID , '' ).split (',' ) if filtering_allowed else ''
376
- query ['getDepartmentUIDs' ] = { "query" : cookie_dep_uid ,"operator" :"or" }
376
+ query ['getDepartmentUIDs' ] = {"query" : cookie_dep_uid , "operator" : "or" }
377
377
378
378
# Check if dashboard_cookie contains any values to query
379
379
# elements by
@@ -383,70 +383,70 @@ def get_analysisrequests_section(self):
383
383
total = self .search_count (query , catalog .id )
384
384
385
385
# Sampling workflow enabled?
386
- if ( self .context .bika_setup .getSamplingWorkflowEnabled () ):
386
+ if self .context .bika_setup .getSamplingWorkflowEnabled ():
387
387
# Analysis Requests awaiting to be sampled or scheduled
388
388
name = _ ('Analysis Requests to be sampled' )
389
389
desc = _ ("To be sampled" )
390
390
purl = 'samples?samples_review_state=to_be_sampled'
391
391
query ['review_state' ] = ['to_be_sampled' , ]
392
- query ['cancellation_state' ] = ['active' ,]
392
+ query ['cancellation_state' ] = ['active' , ]
393
393
out .append (self ._getStatistics (name , desc , purl , catalog , query , total ))
394
394
395
395
# Analysis Requests awaiting to be preserved
396
396
name = _ ('Analysis Requests to be preserved' )
397
397
desc = _ ("To be preserved" )
398
398
purl = 'samples?samples_review_state=to_be_preserved'
399
399
query ['review_state' ] = ['to_be_preserved' , ]
400
- query ['cancellation_state' ] = ['active' ,]
400
+ query ['cancellation_state' ] = ['active' , ]
401
401
out .append (self ._getStatistics (name , desc , purl , catalog , query , total ))
402
402
403
403
# Analysis Requests scheduled for Sampling
404
404
name = _ ('Analysis Requests scheduled for sampling' )
405
405
desc = _ ("Sampling scheduled" )
406
406
purl = 'samples?samples_review_state=scheduled_sampling'
407
407
query ['review_state' ] = ['scheduled_sampling' , ]
408
- query ['cancellation_state' ] = ['active' ,]
408
+ query ['cancellation_state' ] = ['active' , ]
409
409
out .append (self ._getStatistics (name , desc , purl , catalog , query , total ))
410
410
411
411
# Analysis Requests awaiting for reception
412
412
name = _ ('Analysis Requests to be received' )
413
413
desc = _ ("Reception pending" )
414
414
purl = 'analysisrequests?analysisrequests_review_state=sample_due'
415
415
query ['review_state' ] = ['sample_due' , ]
416
- query ['cancellation_state' ] = ['active' ,]
416
+ query ['cancellation_state' ] = ['active' , ]
417
417
out .append (self ._getStatistics (name , desc , purl , catalog , query , total ))
418
418
419
419
# Analysis Requests under way
420
420
name = _ ('Analysis Requests with results pending' )
421
421
desc = _ ("Results pending" )
422
422
purl = 'analysisrequests?analysisrequests_review_state=sample_received'
423
423
query ['review_state' ] = ['attachment_due' ,
424
- 'sample_received' ,]
425
- query ['cancellation_state' ] = ['active' ,]
424
+ 'sample_received' , ]
425
+ query ['cancellation_state' ] = ['active' , ]
426
426
out .append (self ._getStatistics (name , desc , purl , catalog , query , total ))
427
427
428
428
# Analysis Requests to be verified
429
429
name = _ ('Analysis Requests to be verified' )
430
430
desc = _ ("To be verified" )
431
431
purl = 'analysisrequests?analysisrequests_review_state=to_be_verified'
432
432
query ['review_state' ] = ['to_be_verified' , ]
433
- query ['cancellation_state' ] = ['active' ,]
433
+ query ['cancellation_state' ] = ['active' , ]
434
434
out .append (self ._getStatistics (name , desc , purl , catalog , query , total ))
435
435
436
436
# Analysis Requests verified (to be published)
437
437
name = _ ('Analysis Requests verified' )
438
438
desc = _ ("Verified" )
439
439
purl = 'analysisrequests?analysisrequests_review_state=verified'
440
440
query ['review_state' ] = ['verified' , ]
441
- query ['cancellation_state' ] = ['active' ,]
441
+ query ['cancellation_state' ] = ['active' , ]
442
442
out .append (self ._getStatistics (name , desc , purl , catalog , query , total ))
443
443
444
444
# Analysis Requests published
445
445
name = _ ('Analysis Requests published' )
446
446
desc = _ ("Published" )
447
447
purl = 'analysisrequests?analysisrequests_review_state=published'
448
448
query ['review_state' ] = ['published' , ]
449
- query ['cancellation_state' ] = ['active' ,]
449
+ query ['cancellation_state' ] = ['active' , ]
450
450
out .append (self ._getStatistics (name , desc , purl , catalog , query , total ))
451
451
452
452
# Analysis Requests to be printed
@@ -456,7 +456,7 @@ def get_analysisrequests_section(self):
456
456
purl = 'analysisrequests?analysisrequests_getPrinted=0'
457
457
query ['getPrinted' ] = '0'
458
458
query ['review_state' ] = ['published' , ]
459
- query ['cancellation_state' ] = ['active' ,]
459
+ query ['cancellation_state' ] = ['active' , ]
460
460
out .append (
461
461
self ._getStatistics (name , desc , purl , catalog , query , total ))
462
462
@@ -481,11 +481,11 @@ def get_worksheets_section(self):
481
481
"""
482
482
out = []
483
483
bc = getToolByName (self .context , CATALOG_WORKSHEET_LISTING )
484
- query = {'portal_type' :"Worksheet" ,}
484
+ query = {'portal_type' : "Worksheet" , }
485
485
filtering_allowed = self .context .bika_setup .getAllowDepartmentFiltering ()
486
486
if filtering_allowed :
487
487
cookie_dep_uid = self .request .get (FILTER_BY_DEPT_COOKIE_ID , '' ).split (',' ) if filtering_allowed else ''
488
- query ['getDepartmentUIDs' ] = { "query" : cookie_dep_uid ,"operator" :"or" }
488
+ query ['getDepartmentUIDs' ] = {"query" : cookie_dep_uid , "operator" : "or" }
489
489
490
490
# Check if dashboard_cookie contains any values to query
491
491
# elements by
@@ -503,14 +503,14 @@ def get_worksheets_section(self):
503
503
504
504
# Worksheets to be verified
505
505
name = _ ('To be verified' )
506
- desc = _ ('To be verified' )
506
+ desc = _ ('To be verified' )
507
507
purl = 'worksheets?list_review_state=to_be_verified'
508
508
query ['review_state' ] = ['to_be_verified' , ]
509
509
out .append (self ._getStatistics (name , desc , purl , bc , query , total ))
510
510
511
511
# Worksheets verified
512
512
name = _ ('Verified' )
513
- desc = _ ('Verified' )
513
+ desc = _ ('Verified' )
514
514
purl = 'worksheets?list_review_state=verified'
515
515
query ['review_state' ] = ['verified' , ]
516
516
out .append (self ._getStatistics (name , desc , purl , bc , query , total ))
@@ -793,7 +793,7 @@ def fill_dates_evo(self, catalog, query):
793
793
def _fill_dates_evo_cachekey (method , self , query_json , catalog_name ,
794
794
periodicity ):
795
795
hour = time () // (60 * 60 * 2 )
796
- return ( hour , catalog_name , query_json , periodicity )
796
+ return hour , catalog_name , query_json , periodicity
797
797
798
798
@ram .cache (_fill_dates_evo_cachekey )
799
799
def _fill_dates_evo (self , query_json , catalog_name , periodicity ):
@@ -834,14 +834,14 @@ def _fill_dates_evo(self, query_json, catalog_name, periodicity):
834
834
stats = statesmap .values ()
835
835
stats .sort ()
836
836
stats .append (otherstate )
837
- statscount = {s :0 for s in stats }
837
+ statscount = {s : 0 for s in stats }
838
838
# Add first all periods, cause we want all segments to be displayed
839
839
curr = date_from .asdatetime ()
840
840
end = date_to .asdatetime ()
841
841
while curr < end :
842
842
currstr = self ._getDateStr (periodicity , DateTime (curr ))
843
843
if currstr not in outevoidx :
844
- outdict = {'date' :currstr }
844
+ outdict = {'date' : currstr }
845
845
for k in stats :
846
846
outdict [k ] = 0
847
847
outevo .append (outdict )
@@ -866,11 +866,11 @@ def _fill_dates_evo(self, query_json, catalog_name, periodicity):
866
866
else :
867
867
# Create new row
868
868
currow = {'date' : created ,
869
- state : 1 }
869
+ state : 1 }
870
870
outevo .append (currow )
871
871
872
872
# Remove all those states for which there is no data
873
- rstates = [k for k ,v in statscount .items () if v == 0 ]
873
+ rstates = [k for k , v in statscount .items () if v == 0 ]
874
874
for o in outevo :
875
875
for r in rstates :
876
876
if r in o :
0 commit comments