Skip to content

Commit 74d02d7

Browse files
committed
add initial reindexing statuses
1 parent 1308ebc commit 74d02d7

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

sde_collections/admin.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
)
1111

1212
from .models.candidate_url import CandidateURL, ResolvedTitle
13-
from .models.collection import Collection, WorkflowHistory
13+
from .models.collection import Collection, ReindexingHistory, WorkflowHistory
1414
from .models.delta_url import CuratedUrl, DeltaUrl, DumpUrl
1515
from .models.pattern import DivisionPattern, IncludePattern, TitlePattern
1616
from .tasks import fetch_and_replace_full_text, import_candidate_urls_from_api
@@ -215,6 +215,7 @@ class CollectionAdmin(admin.ModelAdmin, ExportCsvMixin, UpdateConfigMixin):
215215
"source",
216216
"turned_on",
217217
"is_multi_division",
218+
"reindexing_status",
218219
),
219220
},
220221
),
@@ -248,9 +249,17 @@ class CollectionAdmin(admin.ModelAdmin, ExportCsvMixin, UpdateConfigMixin):
248249
"division",
249250
"new_collection",
250251
"is_multi_division",
252+
"reindexing_status",
251253
)
252254
readonly_fields = ("config_folder",)
253-
list_filter = ("division", "curation_status", "workflow_status", "turned_on", "is_multi_division")
255+
list_filter = (
256+
"division",
257+
"curation_status",
258+
"workflow_status",
259+
"turned_on",
260+
"is_multi_division",
261+
"reindexing_status",
262+
)
254263
search_fields = ("name", "url", "config_folder")
255264
actions = [
256265
generate_deployment_message,
@@ -310,6 +319,12 @@ class WorkflowHistoryAdmin(admin.ModelAdmin):
310319
list_filter = ["workflow_status", "old_status"]
311320

312321

322+
class ReindexingHistoryAdmin(admin.ModelAdmin):
323+
list_display = ("collection", "old_status", "reindexing_status", "created_at")
324+
search_fields = ["collection__name"]
325+
list_filter = ["reindexing_status", "old_status"]
326+
327+
313328
class ResolvedTitleAdmin(admin.ModelAdmin):
314329
list_display = ["title_pattern", "candidate_url", "resolved_title", "created_at"]
315330

@@ -365,6 +380,7 @@ class CuratedUrlAdmin(admin.ModelAdmin):
365380
list_filter = ("collection",)
366381

367382

383+
admin.site.register(ReindexingHistory, ReindexingHistoryAdmin)
368384
admin.site.register(WorkflowHistory, WorkflowHistoryAdmin)
369385
admin.site.register(CandidateURL, CandidateURLAdmin)
370386
admin.site.register(TitlePattern, TitlePatternAdmin)

sde_collections/models/collection.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
CurationStatusChoices,
2424
Divisions,
2525
DocumentTypes,
26+
ReindexingStatusChoices,
2627
SourceChoices,
2728
UpdateFrequencies,
2829
WorkflowStatusChoices,
@@ -75,6 +76,11 @@ class Collection(models.Model):
7576
choices=WorkflowStatusChoices.choices,
7677
default=WorkflowStatusChoices.RESEARCH_IN_PROGRESS,
7778
)
79+
reindexing_status = models.IntegerField(
80+
choices=ReindexingStatusChoices.choices,
81+
default=ReindexingStatusChoices.REINDEXING_NOT_NEEDED,
82+
verbose_name="Reindexing Status",
83+
)
7884
tracker = FieldTracker(fields=["workflow_status"])
7985

8086
curated_by = models.ForeignKey(User, on_delete=models.DO_NOTHING, null=True, blank=True)
@@ -155,6 +161,12 @@ def migrate_dump_to_delta(self):
155161
# self.refresh_url_lists_for_all_patterns() # TODO: I'm pretty confident we shouldn't be running this
156162
self.apply_all_patterns()
157163

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+
158170
def create_or_update_delta_url(self, url_instance, to_delete=False):
159171
"""
160172
Creates or updates a DeltaUrl entry based on the given DumpUrl or CuratedUrl object.
@@ -224,6 +236,12 @@ def promote_to_curated(self):
224236
# Step 4: Reapply patterns to DeltaUrls
225237
self.refresh_url_lists_for_all_patterns()
226238

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+
227245
def add_to_public_query(self):
228246
"""Add the collection to the public query."""
229247
if self.workflow_status not in [
@@ -349,6 +367,18 @@ def workflow_status_button_color(self) -> str:
349367
}
350368
return color_choices[self.workflow_status]
351369

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+
352382
def _process_exclude_list(self):
353383
"""Process the exclude list."""
354384
return [pattern._process_match_pattern() for pattern in self.excludepattern.all()]
@@ -654,6 +684,7 @@ def __init__(self, *args, **kwargs):
654684
# Create a cached version of the last workflow_status to compare against
655685
super().__init__(*args, **kwargs)
656686
self.old_workflow_status = self.workflow_status
687+
self.old_reindexing_status = self.reindexing_status
657688

658689

659690
class RequiredUrls(models.Model):
@@ -734,6 +765,40 @@ def log_workflow_history(sender, instance, created, **kwargs):
734765
old_status=instance.old_workflow_status,
735766
)
736767

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+
737802

738803
@receiver(post_save, sender=Collection)
739804
def create_configs_on_status_change(sender, instance, created, **kwargs):

sde_collections/models/collection_choice_fields.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,19 @@ class WorkflowStatusChoices(models.IntegerChoices):
9797
PROD_MAJOR = 16, "Prod: Major Issues"
9898
MERGE_PENDING = 17, "Code Merge Pending"
9999
NEEDS_DELETE = 19, "Delete from Prod"
100+
101+
102+
class ReindexingStatusChoices(models.IntegerChoices):
103+
REINDEXING_NOT_NEEDED = 1, "Reindexing Not Needed"
104+
REINDEXING_NEEDED_ON_DEV = 2, "Reindexing Needed on LRM Dev"
105+
REINDEXING_FINISHED_ON_DEV = 3, "Reindexing Finished on LRM Dev"
106+
REINDEXING_READY_FOR_CURATION = 4, "Ready for Curation"
107+
REINDEXING_CURATED = 5, "Curated"
108+
REINDEXING_INDEXED_ON_PROD = 6, "Indexed on Prod"
109+
110+
@classmethod
111+
def get_status_string(cls, value):
112+
for choice in cls.choices:
113+
if choice[0] == value:
114+
return choice[1]
115+
return "N/A"

0 commit comments

Comments
 (0)