|
38 | 38 | DOCUMENT_TYPES_ENDPOINT = "/api/document_types/"
|
39 | 39 | PROFILE_ENDPOINT = "/api/profile/"
|
40 | 40 |
|
| 41 | +PAPERLESS_NGX_DATE_FORMAT = "%Y-%m-%dT%H:%M:%S+00:00" |
| 42 | + |
41 | 43 | # TODO: handle custom fields?
|
42 | 44 | # CUSTOM_FIELDS_ENDPOINT = "/api/custom_fields/"
|
43 | 45 |
|
@@ -124,24 +126,26 @@ def __init__(
|
124 | 126 | break
|
125 | 127 | except ValueError:
|
126 | 128 | continue
|
127 |
| - if not hasattr(self, "ui_min_start_date"): |
| 129 | + if not self.master_start_date: |
128 | 130 | raise ValueError("Could not parse date with any format")
|
129 | 131 | except ValueError as e:
|
130 | 132 | raise ConnectorValidationError(
|
131 | 133 | f"Could not parse ui_min_start_date: {ui_min_start_date}. Error: {e}"
|
132 | 134 | )
|
133 | 135 |
|
134 | 136 | # match ui_name in Datefield from ui_date_field str from UI
|
| 137 | + self.master_date_field: Optional[DateField] = DateField.MODIFIED_DATE |
135 | 138 | if ui_date_field:
|
| 139 | + found = False |
136 | 140 | for date_field in DateField:
|
137 | 141 | if date_field.ui_name == ui_date_field:
|
138 | 142 | self.master_date_field = date_field
|
| 143 | + found = True |
139 | 144 | break
|
140 |
| - raise ConnectorValidationError( |
141 |
| - f"Could not parse ui_date_field: {ui_date_field}." |
142 |
| - ) |
143 |
| - else: |
144 |
| - self.master_date_field = DateField.MODIFIED_DATE |
| 145 | + if not found: |
| 146 | + raise ConnectorValidationError( |
| 147 | + f"Could not parse ui_date_field: {ui_date_field}." |
| 148 | + ) |
145 | 149 |
|
146 | 150 | logger.info("Initialized PaperlessNgxConnector")
|
147 | 151 |
|
@@ -499,7 +503,9 @@ def _parse_document(self, doc_data: Dict[str, Any]) -> Optional[Document]:
|
499 | 503 | logger.warning(
|
500 | 504 | f"Could not parse timestamp for document {doc_id}: {modified_timestamp_str}"
|
501 | 505 | )
|
502 |
| - updated_at = datetime.now(timezone.utc) |
| 506 | + raise ValueError( |
| 507 | + f"Invalid timestamp found in document data {doc_id}: {modified_timestamp_str}" |
| 508 | + ) |
503 | 509 |
|
504 | 510 | doc_owner = next(
|
505 | 511 | (user for user in self.all_users if user["id"] == doc_data.get("owner")),
|
@@ -625,8 +631,8 @@ def poll_source(
|
625 | 631 | end_dt = datetime.fromtimestamp(end, timezone.utc)
|
626 | 632 |
|
627 | 633 | # Format dates for API query in ISO format
|
628 |
| - start_iso = start_dt.strftime("%Y-%m-%dT%H:%M:%S+00:00") |
629 |
| - end_iso = end_dt.strftime("%Y-%m-%dT%H:%M:%S+00:00") |
| 634 | + start_iso = start_dt.strftime(PAPERLESS_NGX_DATE_FORMAT) |
| 635 | + end_iso = end_dt.strftime(PAPERLESS_NGX_DATE_FORMAT) |
630 | 636 |
|
631 | 637 | logger.info(
|
632 | 638 | f"Polling Paperless-ngx for documents modified between {start_iso} and {end_iso}."
|
@@ -680,12 +686,12 @@ def retrieve_all_slim_documents(
|
680 | 686 | # Apply date filtering if provided
|
681 | 687 | if start is not None:
|
682 | 688 | start_dt = datetime.fromtimestamp(start, timezone.utc)
|
683 |
| - start_iso = start_dt.strftime("%Y-%m-%d") |
| 689 | + start_iso = start_dt.strftime(PAPERLESS_NGX_DATE_FORMAT) |
684 | 690 | logger.info(f"Filtering slim documents from {start_iso}")
|
685 | 691 |
|
686 | 692 | if end is not None:
|
687 | 693 | end_dt = datetime.fromtimestamp(end, timezone.utc)
|
688 |
| - end_iso = end_dt.strftime("%Y-%m-%d") |
| 694 | + end_iso = end_dt.strftime(PAPERLESS_NGX_DATE_FORMAT) |
689 | 695 | logger.info(f"Filtering slim documents until {end_iso}")
|
690 | 696 |
|
691 | 697 | # Get only the IDs by making the request and extracting minimal information
|
|
0 commit comments