Skip to content

Commit e8b0cf0

Browse files
committed
delete is_tdamm switch functionality
1 parent a5a408c commit e8b0cf0

File tree

5 files changed

+18
-51
lines changed

5 files changed

+18
-51
lines changed

sde_collections/admin.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,11 @@ class CandidateURLAdmin(admin.ModelAdmin):
290290
"""Admin view for CandidateURL"""
291291

292292
form = CandidateURLForm
293-
list_display = ["url", "collection", "is_tdamm", "tdamm_tag_manual", "tdamm_tag_ml"]
294-
list_filter = ["collection", "is_tdamm"]
293+
list_display = ["url", "collection", "tdamm_tag_manual", "tdamm_tag_ml"]
294+
list_filter = ["collection"]
295295
search_fields = ("url", "collection__name")
296296

297297
def get_fieldsets(self, request, obj=None):
298-
"""Dynamically adjust fieldsets based on is_tdamm"""
299298
fieldsets = [
300299
(
301300
"Essential Information",
@@ -316,27 +315,21 @@ def get_fieldsets(self, request, obj=None):
316315
"is_pdf",
317316
"present_on_test",
318317
"present_on_prod",
319-
"is_tdamm",
320318
)
321319
},
322320
),
321+
(
322+
"TDAMM Tags",
323+
{
324+
"fields": (
325+
"tdamm_tag_ml",
326+
"tdamm_tag_manual",
327+
),
328+
"classes": ("collapse",),
329+
},
330+
),
323331
]
324332

325-
# Add TDAMM fields only if is_tdamm is True
326-
if obj and obj.is_tdamm:
327-
fieldsets.append(
328-
(
329-
"TDAMM Tags",
330-
{
331-
"fields": (
332-
"tdamm_tag_ml",
333-
"tdamm_tag_manual",
334-
),
335-
"classes": ("collapse",),
336-
},
337-
)
338-
)
339-
340333
return fieldsets
341334

342335

sde_collections/migrations/0059_candidateurl_is_tdamm_candidateurl_tdamm_tag_manual_and_more.py renamed to sde_collections/migrations/0059_candidateurl_tdamm_tag_manual_and_more.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 4.2.9 on 2024-11-13 08:01
1+
# Generated by Django 4.2.9 on 2024-11-20 06:39
22

33
import django.contrib.postgres.fields
44
from django.db import migrations, models
@@ -11,13 +11,6 @@ class Migration(migrations.Migration):
1111
]
1212

1313
operations = [
14-
migrations.AddField(
15-
model_name="candidateurl",
16-
name="is_tdamm",
17-
field=models.BooleanField(
18-
default=False, help_text="Enable TDAMM tagging for this URL", verbose_name="Is TDAMM?"
19-
),
20-
),
2114
migrations.AddField(
2215
model_name="candidateurl",
2316
name="tdamm_tag_manual",

sde_collections/models/candidate_url.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,10 @@ class CandidateURL(models.Model):
8181
default=False,
8282
help_text="Helps keep track if the Current URL is present in production or not",
8383
)
84-
is_tdamm = models.BooleanField("Is TDAMM?", default=False, help_text="Enable TDAMM tagging for this URL")
84+
# is_tdamm = models.BooleanField("Is TDAMM?", default=False, help_text="Enable TDAMM tagging for this URL")
8585
tdamm_tag = PairedFieldDescriptor(
8686
field_name="tdamm_tag",
8787
field_type=ArrayField(models.CharField(max_length=255, choices=TDAMMTags.choices), blank=True, null=True),
88-
switch="is_tdamm",
8988
verbose_name="TDAMM Tags",
9089
)
9190

sde_collections/serializers.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,7 @@ class CandidateURLAPISerializer(serializers.ModelSerializer):
116116

117117
class Meta:
118118
model = CandidateURL
119-
fields = ("url", "title", "document_type", "hash", "file_extension", "tree_root", "is_tdamm", "tdamm_tag")
120-
121-
def to_representation(self, instance):
122-
"""Remove tdamm_tag field if is_tdamm is False"""
123-
representation = super().to_representation(instance)
124-
if not instance.is_tdamm:
125-
representation.pop("tdamm_tag", None)
126-
return representation
119+
fields = ("url", "title", "document_type", "hash", "file_extension", "tree_root", "tdamm_tag")
127120

128121
def get_tdamm_tag(self, obj):
129122
tags = obj.tdamm_tag

sde_collections/utils/paired_field_descriptor.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ class PairedFieldDescriptor:
66
- Getting the main field returns manual if present, otherwise ML
77
"""
88

9-
def __init__(self, field_name, field_type, switch, verbose_name=""):
9+
def __init__(self, field_name, field_type, verbose_name=""):
1010
self.field_name = field_name
1111
self.manual_field_name = f"{field_name}_manual"
1212
self.ml_field_name = f"{field_name}_ml"
1313
self.field_type = field_type
1414
self.verbose_name = verbose_name or field_name.replace("_", " ").title()
15-
self.switch = switch
1615

1716
def contribute_to_class(self, cls, name):
1817
"""Called by Django when the descriptor is added to the model class."""
@@ -48,14 +47,10 @@ def __get__(self, instance, owner):
4847
Get the value of the main field:
4948
- Returns manual tags if they exist
5049
- Otherwise returns ML tags
51-
- Returns None if switch is False
5250
"""
5351
if instance is None:
5452
return self
5553

56-
if not getattr(instance, self.switch, False):
57-
return None
58-
5954
manual_value = getattr(instance, self.manual_field_name, None)
6055
ml_value = getattr(instance, self.ml_field_name, None)
6156

@@ -69,16 +64,10 @@ def __set__(self, instance, value):
6964
Set only the manual field when setting the field.
7065
ML field must be set explicitly.
7166
"""
72-
if getattr(instance, self.switch, False):
73-
# Only set the manual field
74-
setattr(instance, self.manual_field_name, value)
67+
68+
setattr(instance, self.manual_field_name, value)
7569

7670
def __delete__(self, instance):
7771
"""Delete both manual and ML fields"""
7872
setattr(instance, self.manual_field_name, None)
7973
setattr(instance, self.ml_field_name, None)
80-
81-
def set_ml(self, instance, value):
82-
"""Explicit method to set ML tags"""
83-
if getattr(instance, self.switch, False):
84-
setattr(instance, self.ml_field_name, value)

0 commit comments

Comments
 (0)