documente_shared 0.1.37__py3-none-any.whl → 0.1.39__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of documente_shared might be problematic. Click here for more details.
- documente_shared/application/digest.py +7 -7
- documente_shared/application/exceptions.py +23 -0
- documente_shared/application/time_utils.py +9 -9
- documente_shared/domain/base_enum.py +53 -53
- documente_shared/domain/entities/document_process.py +226 -203
- documente_shared/domain/entities/document_process_metadata.py +64 -64
- documente_shared/domain/enums.py +22 -22
- documente_shared/domain/repositories.py +24 -24
- documente_shared/infrastructure/dynamo_repositories.py +43 -43
- documente_shared/infrastructure/dynamo_table.py +75 -75
- documente_shared/infrastructure/s3_bucket.py +57 -57
- documente_shared/infrastructure/sqs_queue.py +47 -47
- {documente_shared-0.1.37.dist-info → documente_shared-0.1.39.dist-info}/METADATA +2 -1
- documente_shared-0.1.39.dist-info/RECORD +20 -0
- documente_shared-0.1.37.dist-info/RECORD +0 -19
- {documente_shared-0.1.37.dist-info → documente_shared-0.1.39.dist-info}/WHEEL +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import hashlib
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def get_file_digest(file_bytes: bytes) -> str:
|
|
5
|
-
sha256_hash = hashlib.sha256()
|
|
6
|
-
sha256_hash.update(file_bytes)
|
|
7
|
-
return sha256_hash.hexdigest()
|
|
1
|
+
import hashlib
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_file_digest(file_bytes: bytes) -> str:
|
|
5
|
+
sha256_hash = hashlib.sha256()
|
|
6
|
+
sha256_hash.update(file_bytes)
|
|
7
|
+
return sha256_hash.hexdigest()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import sentry_sdk
|
|
2
|
+
from functools import wraps
|
|
3
|
+
from typing import Callable, Any, TypeVar
|
|
4
|
+
|
|
5
|
+
F = TypeVar("F", bound=Callable[..., Any])
|
|
6
|
+
|
|
7
|
+
def initialize_sentry(dsn: str, environment: str = "dev") -> None:
|
|
8
|
+
if not sentry_sdk.Hub.current.client:
|
|
9
|
+
sentry_sdk.init(
|
|
10
|
+
dsn=dsn,
|
|
11
|
+
environment=environment,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
def track_exceptions(func: F) -> F:
|
|
15
|
+
@wraps(func)
|
|
16
|
+
def wrapper(*args: Any, **kwargs: Any) -> Any:
|
|
17
|
+
try:
|
|
18
|
+
return func(*args, **kwargs)
|
|
19
|
+
except Exception as e:
|
|
20
|
+
sentry_sdk.capture_exception(e)
|
|
21
|
+
sentry_sdk.flush()
|
|
22
|
+
raise
|
|
23
|
+
return wrapper # type: ignore
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
from typing import Union
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def get_datetime_from_data(input_datetime: Union[datetime, str]):
|
|
6
|
-
if isinstance(input_datetime, datetime):
|
|
7
|
-
return input_datetime
|
|
8
|
-
elif isinstance(input_datetime, str):
|
|
9
|
-
return datetime.fromisoformat(input_datetime)
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import Union
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def get_datetime_from_data(input_datetime: Union[datetime, str]):
|
|
6
|
+
if isinstance(input_datetime, datetime):
|
|
7
|
+
return input_datetime
|
|
8
|
+
elif isinstance(input_datetime, str):
|
|
9
|
+
return datetime.fromisoformat(input_datetime)
|
|
10
10
|
return None
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
from enum import Enum
|
|
2
|
-
from typing import Union, Optional
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class BaseEnum(Enum):
|
|
6
|
-
"""Provides the common functionalties to multiple model choices."""
|
|
7
|
-
|
|
8
|
-
@classmethod
|
|
9
|
-
def get_members(cls):
|
|
10
|
-
return [tag for tag in cls if type(tag.value) in [int, str, float]]
|
|
11
|
-
|
|
12
|
-
@classmethod
|
|
13
|
-
def choices(cls):
|
|
14
|
-
"""Generate choice options for models."""
|
|
15
|
-
return [
|
|
16
|
-
(option.value, option.value)
|
|
17
|
-
for option in cls
|
|
18
|
-
if type(option.value) in [int, str, float]
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
@classmethod
|
|
22
|
-
def values(cls):
|
|
23
|
-
"""Returns values from choices."""
|
|
24
|
-
return [option.value for option in cls]
|
|
25
|
-
|
|
26
|
-
def __str__(self): # noqa: D105
|
|
27
|
-
return str(self.value)
|
|
28
|
-
|
|
29
|
-
def __repr__(self):
|
|
30
|
-
return self.__str__()
|
|
31
|
-
|
|
32
|
-
def __hash__(self):
|
|
33
|
-
return hash(self.value)
|
|
34
|
-
|
|
35
|
-
@classmethod
|
|
36
|
-
def as_list(cls):
|
|
37
|
-
"""Returns properties as a list."""
|
|
38
|
-
return [
|
|
39
|
-
value
|
|
40
|
-
for key, value in cls.__dict__.items()
|
|
41
|
-
if isinstance(value, str) and not key.startswith('__')
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
@classmethod
|
|
45
|
-
def from_value(
|
|
46
|
-
cls,
|
|
47
|
-
value: Union[str, int],
|
|
48
|
-
) -> Optional['BaseEnum']:
|
|
49
|
-
for tag in cls:
|
|
50
|
-
if isinstance(tag.value, str) and str(tag.value).upper() == str(value).upper():
|
|
51
|
-
return tag
|
|
52
|
-
elif not isinstance(tag.value, str) and tag.value == value:
|
|
53
|
-
return tag
|
|
1
|
+
from enum import Enum
|
|
2
|
+
from typing import Union, Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class BaseEnum(Enum):
|
|
6
|
+
"""Provides the common functionalties to multiple model choices."""
|
|
7
|
+
|
|
8
|
+
@classmethod
|
|
9
|
+
def get_members(cls):
|
|
10
|
+
return [tag for tag in cls if type(tag.value) in [int, str, float]]
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def choices(cls):
|
|
14
|
+
"""Generate choice options for models."""
|
|
15
|
+
return [
|
|
16
|
+
(option.value, option.value)
|
|
17
|
+
for option in cls
|
|
18
|
+
if type(option.value) in [int, str, float]
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
@classmethod
|
|
22
|
+
def values(cls):
|
|
23
|
+
"""Returns values from choices."""
|
|
24
|
+
return [option.value for option in cls]
|
|
25
|
+
|
|
26
|
+
def __str__(self): # noqa: D105
|
|
27
|
+
return str(self.value)
|
|
28
|
+
|
|
29
|
+
def __repr__(self):
|
|
30
|
+
return self.__str__()
|
|
31
|
+
|
|
32
|
+
def __hash__(self):
|
|
33
|
+
return hash(self.value)
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def as_list(cls):
|
|
37
|
+
"""Returns properties as a list."""
|
|
38
|
+
return [
|
|
39
|
+
value
|
|
40
|
+
for key, value in cls.__dict__.items()
|
|
41
|
+
if isinstance(value, str) and not key.startswith('__')
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
@classmethod
|
|
45
|
+
def from_value(
|
|
46
|
+
cls,
|
|
47
|
+
value: Union[str, int],
|
|
48
|
+
) -> Optional['BaseEnum']:
|
|
49
|
+
for tag in cls:
|
|
50
|
+
if isinstance(tag.value, str) and str(tag.value).upper() == str(value).upper():
|
|
51
|
+
return tag
|
|
52
|
+
elif not isinstance(tag.value, str) and tag.value == value:
|
|
53
|
+
return tag
|
|
54
54
|
return None
|
|
@@ -1,203 +1,226 @@
|
|
|
1
|
-
from dataclasses import dataclass
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
from decimal import Decimal
|
|
4
|
-
from typing import Optional, List
|
|
5
|
-
|
|
6
|
-
from documente_shared.application.time_utils import get_datetime_from_data
|
|
7
|
-
from documente_shared.domain.entities.document_process_metadata import DocumentProcessMetadata
|
|
8
|
-
from documente_shared.domain.enums import (
|
|
9
|
-
DocumentProcessStatus,
|
|
10
|
-
DocumentProcessSubCategory,
|
|
11
|
-
DocumentProcessCategory,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
def remove_slash_from_path(path: str) -> str:
|
|
15
|
-
if path and path.startswith('/'):
|
|
16
|
-
return path[1:]
|
|
17
|
-
return path
|
|
18
|
-
|
|
19
|
-
@dataclass
|
|
20
|
-
class DocumentProcess(object):
|
|
21
|
-
digest: str
|
|
22
|
-
status: DocumentProcessStatus
|
|
23
|
-
file_path: Optional[str] = None
|
|
24
|
-
file_bytes: Optional[bytes] = None
|
|
25
|
-
category: Optional[DocumentProcessCategory] = None
|
|
26
|
-
sub_category: Optional[DocumentProcessSubCategory] = None
|
|
27
|
-
processed_csv_path: Optional[str] = None
|
|
28
|
-
processed_csv_bytes: Optional[bytes] = None
|
|
29
|
-
processed_xlsx_path: Optional[str] = None
|
|
30
|
-
processed_xlsx_bytes: Optional[bytes] = None
|
|
31
|
-
processed_metadata_path: Optional[str] = None
|
|
32
|
-
processing_time: Optional[Decimal] = None
|
|
33
|
-
uploaded_at: Optional[datetime] = None
|
|
34
|
-
enqueued_at: Optional[datetime] = None
|
|
35
|
-
started_at: Optional[datetime] = None
|
|
36
|
-
failed_at: Optional[datetime] = None
|
|
37
|
-
failed_reason: Optional[str] = None
|
|
38
|
-
completed_at: Optional[datetime] = None
|
|
39
|
-
metadata_items: Optional[List[DocumentProcessMetadata]] = None
|
|
40
|
-
|
|
41
|
-
def __post_init__(self):
|
|
42
|
-
self.metadata_items = self.metadata_items or []
|
|
43
|
-
|
|
44
|
-
@property
|
|
45
|
-
def is_pending(self) -> bool:
|
|
46
|
-
return self.status == DocumentProcessStatus.PENDING
|
|
47
|
-
|
|
48
|
-
@property
|
|
49
|
-
def is_enqueued(self) -> bool:
|
|
50
|
-
return self.status == DocumentProcessStatus.ENQUEUED
|
|
51
|
-
|
|
52
|
-
@property
|
|
53
|
-
def is_processing(self) -> bool:
|
|
54
|
-
return self.status == DocumentProcessStatus.PROCESSING
|
|
55
|
-
|
|
56
|
-
@property
|
|
57
|
-
def is_completed(self) -> bool:
|
|
58
|
-
return self.status == DocumentProcessStatus.COMPLETED
|
|
59
|
-
|
|
60
|
-
@property
|
|
61
|
-
def is_failed(self) -> bool:
|
|
62
|
-
return self.status == DocumentProcessStatus.FAILED
|
|
63
|
-
|
|
64
|
-
@property
|
|
65
|
-
def is_valid(self) -> bool:
|
|
66
|
-
return all([
|
|
67
|
-
self.digest,
|
|
68
|
-
self.status,
|
|
69
|
-
self.file_path,
|
|
70
|
-
])
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
self.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
self.
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
self.
|
|
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
|
-
'enqueued_at'
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
if
|
|
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
|
-
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from decimal import Decimal
|
|
4
|
+
from typing import Optional, List
|
|
5
|
+
|
|
6
|
+
from documente_shared.application.time_utils import get_datetime_from_data
|
|
7
|
+
from documente_shared.domain.entities.document_process_metadata import DocumentProcessMetadata
|
|
8
|
+
from documente_shared.domain.enums import (
|
|
9
|
+
DocumentProcessStatus,
|
|
10
|
+
DocumentProcessSubCategory,
|
|
11
|
+
DocumentProcessCategory,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
def remove_slash_from_path(path: str) -> str:
|
|
15
|
+
if path and path.startswith('/'):
|
|
16
|
+
return path[1:]
|
|
17
|
+
return path
|
|
18
|
+
|
|
19
|
+
@dataclass
|
|
20
|
+
class DocumentProcess(object):
|
|
21
|
+
digest: str
|
|
22
|
+
status: DocumentProcessStatus
|
|
23
|
+
file_path: Optional[str] = None
|
|
24
|
+
file_bytes: Optional[bytes] = None
|
|
25
|
+
category: Optional[DocumentProcessCategory] = None
|
|
26
|
+
sub_category: Optional[DocumentProcessSubCategory] = None
|
|
27
|
+
processed_csv_path: Optional[str] = None
|
|
28
|
+
processed_csv_bytes: Optional[bytes] = None
|
|
29
|
+
processed_xlsx_path: Optional[str] = None
|
|
30
|
+
processed_xlsx_bytes: Optional[bytes] = None
|
|
31
|
+
processed_metadata_path: Optional[str] = None
|
|
32
|
+
processing_time: Optional[Decimal] = None
|
|
33
|
+
uploaded_at: Optional[datetime] = None
|
|
34
|
+
enqueued_at: Optional[datetime] = None
|
|
35
|
+
started_at: Optional[datetime] = None
|
|
36
|
+
failed_at: Optional[datetime] = None
|
|
37
|
+
failed_reason: Optional[str] = None
|
|
38
|
+
completed_at: Optional[datetime] = None
|
|
39
|
+
metadata_items: Optional[List[DocumentProcessMetadata]] = None
|
|
40
|
+
|
|
41
|
+
def __post_init__(self):
|
|
42
|
+
self.metadata_items = self.metadata_items or []
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def is_pending(self) -> bool:
|
|
46
|
+
return self.status == DocumentProcessStatus.PENDING
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def is_enqueued(self) -> bool:
|
|
50
|
+
return self.status == DocumentProcessStatus.ENQUEUED
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def is_processing(self) -> bool:
|
|
54
|
+
return self.status == DocumentProcessStatus.PROCESSING
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def is_completed(self) -> bool:
|
|
58
|
+
return self.status == DocumentProcessStatus.COMPLETED
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def is_failed(self) -> bool:
|
|
62
|
+
return self.status == DocumentProcessStatus.FAILED
|
|
63
|
+
|
|
64
|
+
@property
|
|
65
|
+
def is_valid(self) -> bool:
|
|
66
|
+
return all([
|
|
67
|
+
self.digest,
|
|
68
|
+
self.status,
|
|
69
|
+
self.file_path,
|
|
70
|
+
])
|
|
71
|
+
|
|
72
|
+
@property
|
|
73
|
+
def is_finished(self) -> bool:
|
|
74
|
+
return self.status in [
|
|
75
|
+
DocumentProcessStatus.COMPLETED,
|
|
76
|
+
DocumentProcessStatus.FAILED,
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
def enqueue(self):
|
|
80
|
+
self.status = DocumentProcessStatus.ENQUEUED
|
|
81
|
+
self.enqueued_at = datetime.now()
|
|
82
|
+
|
|
83
|
+
def processing(self):
|
|
84
|
+
self.status = DocumentProcessStatus.PROCESSING
|
|
85
|
+
self.started_at = datetime.now()
|
|
86
|
+
|
|
87
|
+
def failed(self, error_message: Optional[str] = None):
|
|
88
|
+
self.failed_reason = error_message
|
|
89
|
+
self.status = DocumentProcessStatus.FAILED
|
|
90
|
+
self.failed_at = datetime.now()
|
|
91
|
+
|
|
92
|
+
def completed(self):
|
|
93
|
+
self.status = DocumentProcessStatus.COMPLETED
|
|
94
|
+
self.completed_at = datetime.now()
|
|
95
|
+
|
|
96
|
+
def deleted(self):
|
|
97
|
+
self.status = DocumentProcessStatus.DELETED
|
|
98
|
+
|
|
99
|
+
@property
|
|
100
|
+
def file_key(self) -> str:
|
|
101
|
+
return remove_slash_from_path(self.file_path)
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def processed_csv_key(self) -> str:
|
|
105
|
+
return remove_slash_from_path(self.processed_csv_path)
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def processed_xlsx_key(self) -> str:
|
|
109
|
+
return remove_slash_from_path(self.processed_xlsx_path)
|
|
110
|
+
|
|
111
|
+
@property
|
|
112
|
+
def processed_metadata_key(self) -> str:
|
|
113
|
+
return remove_slash_from_path(self.processed_metadata_path)
|
|
114
|
+
|
|
115
|
+
@property
|
|
116
|
+
def extended_filename(self) -> str:
|
|
117
|
+
return self.file_path.split('/')[-1]
|
|
118
|
+
|
|
119
|
+
@property
|
|
120
|
+
def filename(self) -> str:
|
|
121
|
+
filename_with_extension = self.extended_filename
|
|
122
|
+
return filename_with_extension.split('.')[0]
|
|
123
|
+
|
|
124
|
+
def __eq__(self, other: 'DocumentProcess') -> bool:
|
|
125
|
+
if not other:
|
|
126
|
+
return False
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
self.digest == other.digest
|
|
130
|
+
and self.status == other.status
|
|
131
|
+
and self.file_path == other.file_path
|
|
132
|
+
and self.uploaded_at == other.uploaded_at
|
|
133
|
+
and self.enqueued_at == other.enqueued_at
|
|
134
|
+
and self.started_at == other.started_at
|
|
135
|
+
and self.failed_at == other.failed_at
|
|
136
|
+
and self.completed_at == other.completed_at
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def to_dict(self) -> dict:
|
|
142
|
+
return {
|
|
143
|
+
'digest': self.digest,
|
|
144
|
+
'status': str(self.status),
|
|
145
|
+
'file_path': self.file_path,
|
|
146
|
+
'category': (
|
|
147
|
+
str(self.category)
|
|
148
|
+
if self.category else None
|
|
149
|
+
),
|
|
150
|
+
'sub_category': (
|
|
151
|
+
str(self.sub_category)
|
|
152
|
+
if self.sub_category else None
|
|
153
|
+
),
|
|
154
|
+
'processed_csv_path': self.processed_csv_path,
|
|
155
|
+
'processed_xlsx_path': self.processed_xlsx_path,
|
|
156
|
+
'processed_metadata_path': self.processed_metadata_path,
|
|
157
|
+
'processing_time': (
|
|
158
|
+
str(self.processing_time.quantize(Decimal('0.00001')))
|
|
159
|
+
if self.processing_time else None
|
|
160
|
+
),
|
|
161
|
+
'uploaded_at': self.uploaded_at.isoformat() if self.uploaded_at else None,
|
|
162
|
+
'enqueued_at': self.enqueued_at.isoformat() if self.enqueued_at else None,
|
|
163
|
+
'started_at': self.started_at.isoformat() if self.started_at else None,
|
|
164
|
+
'failed_at': self.failed_at.isoformat() if self.failed_at else None,
|
|
165
|
+
'failed_reason': self.failed_reason,
|
|
166
|
+
'completed_at': self.completed_at.isoformat() if self.completed_at else None,
|
|
167
|
+
'metadata_items': [metadata.to_dict for metadata in self.metadata_items],
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def to_simple_dict(self) -> dict:
|
|
172
|
+
simple_dict = self.to_dict.copy()
|
|
173
|
+
simple_dict.pop('metadata_items')
|
|
174
|
+
return simple_dict
|
|
175
|
+
|
|
176
|
+
def overload(
|
|
177
|
+
self,
|
|
178
|
+
new_instance: 'DocumentProcess',
|
|
179
|
+
properties: List[str] = None,
|
|
180
|
+
):
|
|
181
|
+
instance_properties = properties or [
|
|
182
|
+
'status', 'metadata', 'file_path', 'file_bytes', 'category', 'sub_category',
|
|
183
|
+
'processed_csv_path', 'processed_csv_bytes', 'processed_xlsx_path', 'processed_metadata_path',
|
|
184
|
+
'processed_xlsx_bytes', 'processing_time', 'uploaded_at',
|
|
185
|
+
'enqueued_at', 'started_at', 'failed_at', 'failed_reason', 'completed_at',
|
|
186
|
+
]
|
|
187
|
+
for _property in instance_properties:
|
|
188
|
+
property_value = getattr(new_instance, _property)
|
|
189
|
+
if not hasattr(self, _property):
|
|
190
|
+
continue
|
|
191
|
+
setattr(self, _property, property_value)
|
|
192
|
+
return self
|
|
193
|
+
|
|
194
|
+
@classmethod
|
|
195
|
+
def from_dict(cls, data: dict) -> 'DocumentProcess':
|
|
196
|
+
return cls(
|
|
197
|
+
digest=data.get('digest'),
|
|
198
|
+
status=DocumentProcessStatus.from_value(data.get('status')),
|
|
199
|
+
file_path=data.get('file_path'),
|
|
200
|
+
category=(
|
|
201
|
+
DocumentProcessCategory.from_value(data.get('category'))
|
|
202
|
+
if data.get('category') else None
|
|
203
|
+
),
|
|
204
|
+
sub_category=(
|
|
205
|
+
DocumentProcessSubCategory.from_value(data.get('sub_category'))
|
|
206
|
+
if data.get('sub_category') else None
|
|
207
|
+
),
|
|
208
|
+
processed_csv_path=data.get('processed_csv_path'),
|
|
209
|
+
processed_xlsx_path=data.get('processed_xlsx_path'),
|
|
210
|
+
processed_metadata_path=data.get('processed_metadata_path'),
|
|
211
|
+
processing_time=(
|
|
212
|
+
Decimal(data.get('processing_time'))
|
|
213
|
+
if data.get('processing_time') else None
|
|
214
|
+
),
|
|
215
|
+
uploaded_at=get_datetime_from_data(input_datetime=data.get('uploaded_at')),
|
|
216
|
+
enqueued_at=get_datetime_from_data(input_datetime=data.get('enqueued_at')),
|
|
217
|
+
started_at=get_datetime_from_data(input_datetime=data.get('started_at')),
|
|
218
|
+
failed_at=get_datetime_from_data(input_datetime=data.get('failed_at')),
|
|
219
|
+
failed_reason=data.get('failed_reason'),
|
|
220
|
+
completed_at=get_datetime_from_data(input_datetime=data.get('completed_at')),
|
|
221
|
+
metadata_items=[
|
|
222
|
+
DocumentProcessMetadata.from_dict(metadata)
|
|
223
|
+
for metadata in data.get('metadata_items', [])
|
|
224
|
+
],
|
|
225
|
+
)
|
|
226
|
+
|