mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 18:38:26 -04:00
Use default dict for default job stats
This is just some refactoring. `defaultdict` is a data structure which won’t raise a `KeyError` if you try to access a key that doesn’t exist. By passing `int` as the first argument, trying to access the value of any key that doesn’t exists will return the value of `int()`, ie `0`
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from notifications_python_client.base import BaseAPIClient
|
from notifications_python_client.base import BaseAPIClient
|
||||||
from app.notify_client import _attach_current_user
|
from app.notify_client import _attach_current_user
|
||||||
@@ -16,12 +17,7 @@ class JobApiClient(BaseAPIClient):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __convert_statistics(job):
|
def __convert_statistics(job):
|
||||||
results = {
|
results = defaultdict(int)
|
||||||
'sending': 0,
|
|
||||||
'delivered': 0,
|
|
||||||
'failed': 0,
|
|
||||||
'requested': 0
|
|
||||||
}
|
|
||||||
if 'statistics' in job:
|
if 'statistics' in job:
|
||||||
for outcome in job['statistics']:
|
for outcome in job['statistics']:
|
||||||
if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', 'permanent-failure']:
|
if outcome['status'] in ['failed', 'technical-failure', 'temporary-failure', 'permanent-failure']:
|
||||||
|
|||||||
Reference in New Issue
Block a user