|
23 | 23 | CurationStatusChoices,
|
24 | 24 | Divisions,
|
25 | 25 | DocumentTypes,
|
| 26 | + ReindexingStatusChoices, |
26 | 27 | SourceChoices,
|
27 | 28 | UpdateFrequencies,
|
28 | 29 | WorkflowStatusChoices,
|
@@ -75,6 +76,11 @@ class Collection(models.Model):
|
75 | 76 | choices=WorkflowStatusChoices.choices,
|
76 | 77 | default=WorkflowStatusChoices.RESEARCH_IN_PROGRESS,
|
77 | 78 | )
|
| 79 | + reindexing_status = models.IntegerField( |
| 80 | + choices=ReindexingStatusChoices.choices, |
| 81 | + default=ReindexingStatusChoices.REINDEXING_NOT_NEEDED, |
| 82 | + verbose_name="Reindexing Status", |
| 83 | + ) |
78 | 84 | tracker = FieldTracker(fields=["workflow_status"])
|
79 | 85 |
|
80 | 86 | curated_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, null=True, blank=True)
|
@@ -155,6 +161,12 @@ def migrate_dump_to_delta(self):
|
155 | 161 | # self.refresh_url_lists_for_all_patterns() # TODO: I'm pretty confident we shouldn't be running this
|
156 | 162 | self.apply_all_patterns()
|
157 | 163 |
|
| 164 | + # After migrating, check if we should update reindexing status |
| 165 | + curated_urls_count = self.curated_urls.count() |
| 166 | + if curated_urls_count > 0: |
| 167 | + self.reindexing_status = ReindexingStatusChoices.REINDEXING_READY_FOR_CURATION |
| 168 | + self.save() |
| 169 | + |
158 | 170 | def create_or_update_delta_url(self, url_instance, to_delete=False):
|
159 | 171 | """
|
160 | 172 | Creates or updates a DeltaUrl entry based on the given DumpUrl or CuratedUrl object.
|
@@ -224,6 +236,12 @@ def promote_to_curated(self):
|
224 | 236 | # Step 4: Reapply patterns to DeltaUrls
|
225 | 237 | self.refresh_url_lists_for_all_patterns()
|
226 | 238 |
|
| 239 | + # After promoting, check if we should update reindexing status |
| 240 | + curated_urls_count = self.curated_urls.count() |
| 241 | + if curated_urls_count > 0: |
| 242 | + self.reindexing_status = ReindexingStatusChoices.REINDEXING_CURATED |
| 243 | + self.save() |
| 244 | + |
227 | 245 | def add_to_public_query(self):
|
228 | 246 | """Add the collection to the public query."""
|
229 | 247 | if self.workflow_status not in [
|
@@ -349,6 +367,18 @@ def workflow_status_button_color(self) -> str:
|
349 | 367 | }
|
350 | 368 | return color_choices[self.workflow_status]
|
351 | 369 |
|
| 370 | + @property |
| 371 | + def reindexing_status_button_color(self) -> str: |
| 372 | + color_choices = { |
| 373 | + 1: "btn-light", # NOT_NEEDED |
| 374 | + 2: "btn-warning", # NEEDED |
| 375 | + 3: "btn-secondary", # FINISHED |
| 376 | + 4: "btn-info", # READY_FOR_CURATION |
| 377 | + 5: "btn-primary", # CURATED |
| 378 | + 6: "btn-success", # INDEXED_ON_PROD |
| 379 | + } |
| 380 | + return color_choices[self.reindexing_status] |
| 381 | + |
352 | 382 | def _process_exclude_list(self):
|
353 | 383 | """Process the exclude list."""
|
354 | 384 | return [pattern._process_match_pattern() for pattern in self.excludepattern.all()]
|
@@ -654,6 +684,7 @@ def __init__(self, *args, **kwargs):
|
654 | 684 | # Create a cached version of the last workflow_status to compare against
|
655 | 685 | super().__init__(*args, **kwargs)
|
656 | 686 | self.old_workflow_status = self.workflow_status
|
| 687 | + self.old_reindexing_status = self.reindexing_status |
657 | 688 |
|
658 | 689 |
|
659 | 690 | class RequiredUrls(models.Model):
|
@@ -734,6 +765,40 @@ def log_workflow_history(sender, instance, created, **kwargs):
|
734 | 765 | old_status=instance.old_workflow_status,
|
735 | 766 | )
|
736 | 767 |
|
| 768 | + if instance.reindexing_status != instance.old_reindexing_status: |
| 769 | + ReindexingHistory.objects.create( |
| 770 | + collection=instance, |
| 771 | + reindexing_status=instance.reindexing_status, |
| 772 | + curated_by=instance.curated_by, |
| 773 | + old_status=instance.old_reindexing_status, |
| 774 | + ) |
| 775 | + |
| 776 | + |
| 777 | +class ReindexingHistory(models.Model): |
| 778 | + collection = models.ForeignKey(Collection, on_delete=models.CASCADE, related_name="reindexing_history", null=True) |
| 779 | + reindexing_status = models.IntegerField( |
| 780 | + choices=ReindexingStatusChoices.choices, |
| 781 | + default=ReindexingStatusChoices.REINDEXING_NOT_NEEDED, |
| 782 | + ) |
| 783 | + old_status = models.IntegerField(choices=ReindexingStatusChoices.choices, null=True) |
| 784 | + curated_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, null=True, blank=True) |
| 785 | + created_at = models.DateTimeField(auto_now_add=True) |
| 786 | + |
| 787 | + def __str__(self): |
| 788 | + return str(self.collection) + str(self.reindexing_status) |
| 789 | + |
| 790 | + @property |
| 791 | + def reindexing_status_button_color(self) -> str: |
| 792 | + color_choices = { |
| 793 | + 1: "btn-light", # REINDEXING_NOT_NEEDED |
| 794 | + 2: "btn-warning", # REINDEXING_NEEDED_ON_DEV |
| 795 | + 3: "btn-secondary", # REINDEXING_FINISHED_ON_DEV |
| 796 | + 4: "btn-info", # REINDEXING_READY_FOR_CURATION |
| 797 | + 5: "btn-primary", # REINDEXING_CURATED |
| 798 | + 6: "btn-success", # REINDEXING_INDEXED_ON_PROD |
| 799 | + } |
| 800 | + return color_choices[self.reindexing_status] |
| 801 | + |
737 | 802 |
|
738 | 803 | @receiver(post_save, sender=Collection)
|
739 | 804 | def create_configs_on_status_change(sender, instance, created, **kwargs):
|
|
0 commit comments