Skip to content

Commit c7e74b2

Browse files
committed
Allow individual URL inclusion to override multi-URL excludes
1 parent 8df561a commit c7e74b2

File tree

3 files changed

+74
-5
lines changed

3 files changed

+74
-5
lines changed

sde_collections/serializers.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class DeltaURLSerializer(serializers.ModelSerializer):
7373
match_pattern_type = serializers.SerializerMethodField(read_only=True)
7474
delta_urls_count = serializers.SerializerMethodField(read_only=True)
7575
tdamm_tag = serializers.SerializerMethodField()
76+
exclude_pattern_type = serializers.IntegerField(required=False)
77+
include_pattern_id = serializers.IntegerField(read_only=True)
7678

7779
def get_tdamm_tag(self, obj):
7880
tags = obj.tdamm_tag
@@ -108,6 +110,8 @@ class Meta:
108110
"division_display",
109111
"visited",
110112
"tdamm_tag",
113+
"exclude_pattern_type",
114+
"include_pattern_id",
111115
)
112116

113117

sde_collections/views.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,30 @@ def _filter_by_is_excluded(self, queryset, is_excluded):
276276
def get_queryset(self):
277277
queryset = super().get_queryset()
278278
if self.request.method == "GET":
279+
collection_id = self.request.GET.get("collection_id")
279280
# Filter based on exclusion status
280281
is_excluded = self.request.GET.get("is_excluded")
281282
if is_excluded:
282283
queryset = self._filter_by_is_excluded(queryset, is_excluded)
284+
285+
# Annotate queryset with two pieces of information:
286+
# 1. exclude_pattern_type: Type of exclude pattern (1=Individual URL, 2=Multi-URL Pattern)
287+
# Ordered by -match_pattern_type to prioritize multi-url patterns (type 2)
288+
# 2. include_pattern_id: ID of any include pattern affecting this URL
289+
# Used when we need to delete the include pattern during re-exclusion
290+
queryset = queryset.annotate(
291+
exclude_pattern_type=models.Subquery(
292+
DeltaExcludePattern.objects.filter(delta_urls=models.OuterRef("pk"), collection_id=collection_id)
293+
.order_by("-match_pattern_type")
294+
.values("match_pattern_type")[:1]
295+
),
296+
include_pattern_id=models.Subquery(
297+
DeltaIncludePattern.objects.filter(
298+
delta_urls=models.OuterRef("pk"), collection_id=collection_id
299+
).values("id")[:1]
300+
),
301+
)
302+
283303
return queryset.order_by("url")
284304

285305
def update_division(self, request, pk=None):

sde_indexing_helper/static/js/delta_url_list.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ function initializeDataTable() {
259259
getDocumentTypeColumn(),
260260
getDivisionColumn(),
261261
{ data: "id", visible: false, searchable: false },
262+
{ data: "exclude_pattern_type", visible: false, searchable: false },
263+
{ data: "include_pattern_id", visible: false, searchable: false },
262264
{ data: "generated_title_id", visible: false, searchable: false },
263265
{ data: "match_pattern_type", visible: false, searchable: false },
264266
{ data: "delta_urls_count", visible: false, searchable: false },
@@ -1456,11 +1458,54 @@ function handleUrlPartButton() {
14561458

14571459
function handleExcludeIndividualUrlClick() {
14581460
$("body").on("click", ".exclude_individual_url", function () {
1459-
postExcludePatterns(
1460-
(match_pattern = $(this).attr("value")),
1461-
(match_pattern_type = 1),
1462-
true
1463-
);
1461+
const url = $(this).attr("value");
1462+
// "check" for excluded, "close" for not excluded
1463+
const isExcluded = $(this).children("i").text() === "check";
1464+
const row = $(this).closest("tr");
1465+
const table = $("#delta_urls_table").DataTable();
1466+
const rowData = table.row(row).data();
1467+
const isAffectedByMultiPattern = rowData.exclude_pattern_type === MULTI_URL_PATTERN;
1468+
const patternId = rowData.include_pattern_id;
1469+
1470+
if (isAffectedByMultiPattern) {
1471+
// For URLs affected by multi-URL exclude patterns:
1472+
// - If excluded: Create individual include pattern to override
1473+
// - If not excluded: Delete the override include pattern
1474+
if (isExcluded) {
1475+
postIncludePatterns((match_pattern = url), (match_pattern_type = 1));
1476+
} else {
1477+
deletePatternWithoutPrompt(`/api/include-patterns/${patternId}/`);
1478+
}
1479+
} else {
1480+
// For URLs not affected by multi-URL patterns:
1481+
// Toggle individual exclude pattern
1482+
postExcludePatterns(
1483+
(match_pattern = url),
1484+
(match_pattern_type = 1),
1485+
true
1486+
);
1487+
}
1488+
});
1489+
}
1490+
1491+
function deletePatternWithoutPrompt(url) {
1492+
$.ajax({
1493+
url: url,
1494+
type: "DELETE",
1495+
data: {
1496+
csrfmiddlewaretoken: csrftoken,
1497+
},
1498+
headers: {
1499+
"X-CSRFToken": csrftoken,
1500+
},
1501+
success: function (data) {
1502+
$("#delta_urls_table").DataTable().ajax.reload(null, false);
1503+
$("#exclude_patterns_table").DataTable().ajax.reload(null, false);
1504+
$("#include_patterns_table").DataTable().ajax.reload(null, false);
1505+
$("#title_patterns_table").DataTable().ajax.reload(null, false);
1506+
$("#document_type_patterns_table").DataTable().ajax.reload(null, false);
1507+
$("#division_patterns_table").DataTable().ajax.reload(null, false);
1508+
},
14641509
});
14651510
}
14661511

0 commit comments

Comments
 (0)