Skip to content

Commit

Permalink
Merge pull request #1103 from NASA-IMPACT/1093-write-tests-for-two-co…
Browse files Browse the repository at this point in the history
…lumn-tags-functionality

Refactor Two Column to work with Delta Urls
  • Loading branch information
CarsonDavis authored Dec 6, 2024
2 parents 1308ebc + 547401c commit b001d04
Show file tree
Hide file tree
Showing 15 changed files with 1,575 additions and 18 deletions.
110 changes: 97 additions & 13 deletions sde_collections/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import csv

from django import forms
from django.contrib import admin, messages
from django.http import HttpResponse

Expand All @@ -11,6 +12,7 @@

from .models.candidate_url import CandidateURL, ResolvedTitle
from .models.collection import Collection, WorkflowHistory
from .models.collection_choice_fields import TDAMMTags
from .models.delta_url import CuratedUrl, DeltaUrl, DumpUrl
from .models.pattern import DivisionPattern, IncludePattern, TitlePattern
from .tasks import fetch_and_replace_full_text, import_candidate_urls_from_api
Expand Down Expand Up @@ -249,6 +251,7 @@ class CollectionAdmin(admin.ModelAdmin, ExportCsvMixin, UpdateConfigMixin):
"new_collection",
"is_multi_division",
)

readonly_fields = ("config_folder",)
list_filter = ("division", "curation_status", "workflow_status", "turned_on", "is_multi_division")
search_fields = ("name", "url", "config_folder")
Expand Down Expand Up @@ -282,11 +285,90 @@ def exclude_and_delete_children(modeladmin, request, queryset):
candidate_url.get_children().delete()


class CandidateURLAdmin(admin.ModelAdmin):
"""Admin View for CandidateURL"""
class TDAMMFormMixin(forms.ModelForm):
"""Mixin for forms that need TDAMM tag fields"""

tdamm_tag_manual = forms.MultipleChoiceField(
choices=TDAMMTags.choices,
required=False,
label="TDAMM Manual Tags",
widget=forms.CheckboxSelectMultiple,
)

tdamm_tag_ml = forms.MultipleChoiceField(
choices=TDAMMTags.choices,
required=False,
label="TDAMM ML Tags",
widget=forms.CheckboxSelectMultiple,
)

list_display = ("url", "scraped_title", "collection")
list_filter = ("collection",)

class TDAMMAdminMixin:
"""Mixin for admin classes that handle TDAMM tags"""

list_display = ("url", "scraped_title", "generated_title", "collection")
list_filter = ["collection"]
search_fields = ("url", "collection__name")

def get_fieldsets(self, request, obj=None):
fieldsets = [
(
"Overall Information",
{
"fields": (
"collection",
"url",
"scraped_title",
"scraped_text",
"generated_title",
"visited",
"document_type",
"division",
)
},
),
(
"TDAMM Tags",
{
"fields": (
"tdamm_tag_ml",
"tdamm_tag_manual",
),
"classes": ("collapse",),
},
),
]
return fieldsets


class CandidateURLForm(TDAMMFormMixin):
class Meta:
model = CandidateURL
fields = "__all__"


class DumpURLForm(TDAMMFormMixin, forms.ModelForm):
class Meta:
model = DumpUrl
fields = "__all__"


class DeltaURLForm(TDAMMFormMixin, forms.ModelForm):
class Meta:
model = DeltaUrl
fields = "__all__"


class CuratedURLForm(TDAMMFormMixin, forms.ModelForm):
class Meta:
model = CuratedUrl
fields = "__all__"


class CandidateURLAdmin(TDAMMAdminMixin, admin.ModelAdmin):
"""Admin view for CandidateURL"""

form = CandidateURLForm


class TitlePatternAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -344,25 +426,27 @@ class DeltaDivisionPatternAdmin(admin.ModelAdmin):
search_fields = ("match_pattern", "division")


class DumpUrlAdmin(admin.ModelAdmin):
class DumpUrlAdmin(TDAMMAdminMixin, admin.ModelAdmin):
"""Admin View for DumpUrl"""

list_display = ("url", "scraped_title", "collection")
list_filter = ("collection",)
form = DumpURLForm


class DeltaUrlAdmin(admin.ModelAdmin):
class DeltaUrlAdmin(TDAMMAdminMixin, admin.ModelAdmin):
"""Admin View for DeltaUrl"""

list_display = ("url", "scraped_title", "generated_title", "collection")
list_filter = ("collection",)
form = DeltaURLForm

def get_fieldsets(self, request, obj=None):
fieldsets = super().get_fieldsets(request, obj)
fieldsets[0][1]["fields"] += ("to_delete",)
return fieldsets

class CuratedUrlAdmin(admin.ModelAdmin):

class CuratedUrlAdmin(TDAMMAdminMixin, admin.ModelAdmin):
"""Admin View for CuratedUrl"""

list_display = ("url", "scraped_title", "generated_title", "collection")
list_filter = ("collection",)
form = CuratedURLForm


admin.site.register(WorkflowHistory, WorkflowHistoryAdmin)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Generated by Django 4.2.9 on 2024-11-20 06:39

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("sde_collections", "0058_candidateurl_division_collection_is_multi_division_and_more"),
]

operations = [
migrations.AddField(
model_name="candidateurl",
name="tdamm_tag_manual",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.CharField(
choices=[
("MMA_M_EM", "Messenger - EM Radiation"),
("MMA_M_EM_G", "Messenger - EM Radiation - Gamma rays"),
("MMA_M_EM_X", "Messenger - EM Radiation - X-rays"),
("MMA_M_EM_U", "Messenger - EM Radiation - Ultraviolet"),
("MMA_M_EM_O", "Messenger - EM Radiation - Optical"),
("MMA_M_EM_I", "Messenger - EM Radiation - Infrared"),
("MMA_M_EM_M", "Messenger - EM Radiation - Microwave"),
("MMA_M_EM_R", "Messenger - EM Radiation - Radio"),
("MMA_M_G", "Messenger - Gravitational Waves"),
("MMA_M_G_CBI", "Messenger - Gravitational Waves - Compact Binary Inspiral"),
("MMA_M_G_S", "Messenger - Gravitational Waves - Stochastic"),
("MMA_M_G_CON", "Messenger - Gravitational Waves - Continuous"),
("MMA_M_G_B", "Messenger - Gravitational Waves - Burst"),
("MMA_M_C", "Messenger - Cosmic Rays"),
("MMA_M_N", "Messenger - Neutrinos"),
("MMA_O_BI", "Objects - Binaries"),
("MMA_O_BI_BBH", "Objects - Binaries - Binary Black Holes"),
("MMA_O_BI_BNS", "Objects - Binaries - Binary Neutron Stars"),
("MMA_O_BI_C", "Objects - Binaries - Cataclysmic Variables"),
("MMA_O_BI_N", "Objects - Binaries - Neutron Star-Black Hole"),
("MMA_O_BI_B", "Objects - Binaries - Binary Pulsars"),
("MMA_O_BI_W", "Objects - Binaries - White Dwarf Binaries"),
("MMA_O_BH", "Objects - Black Holes"),
("MMA_O_BH_AGN", "Objects - Black Holes - Active Galactic Nuclei"),
("MMA_O_BH_IM", "Objects - Black Holes - Intermediate mass"),
("MMA_O_BH_STM", "Objects - Black Holes - Stellar mass"),
("MMA_O_BH_SUM", "Objects - Black Holes - Supermassive"),
("MMA_O_E", "Objects - Exoplanets"),
("MMA_O_N", "Objects - Neutron Stars"),
("MMA_O_N_M", "Objects - Neutron Stars - Magnetars"),
("MMA_O_N_P", "Objects - Neutron Stars - Pulsars"),
("MMA_O_N_PWN", "Objects - Neutron Stars - Pulsar Wind Nebula"),
("MMA_O_S", "Objects - Supernova Remnants"),
("MMA_S_F", "Signals - Fast Radio Bursts"),
("MMA_S_G", "Signals - Gamma-ray Bursts"),
("MMA_S_K", "Signals - Kilonovae"),
("MMA_S_N", "Signals - Novae"),
("MMA_S_P", "Signals - Pevatrons"),
("MMA_S_ST", "Signals - Stellar flares"),
("MMA_S_SU", "Signals - Supernovae"),
],
max_length=255,
),
blank=True,
db_column="tdamm_tag_manual",
null=True,
size=None,
),
),
migrations.AddField(
model_name="candidateurl",
name="tdamm_tag_ml",
field=django.contrib.postgres.fields.ArrayField(
base_field=models.CharField(
choices=[
("MMA_M_EM", "Messenger - EM Radiation"),
("MMA_M_EM_G", "Messenger - EM Radiation - Gamma rays"),
("MMA_M_EM_X", "Messenger - EM Radiation - X-rays"),
("MMA_M_EM_U", "Messenger - EM Radiation - Ultraviolet"),
("MMA_M_EM_O", "Messenger - EM Radiation - Optical"),
("MMA_M_EM_I", "Messenger - EM Radiation - Infrared"),
("MMA_M_EM_M", "Messenger - EM Radiation - Microwave"),
("MMA_M_EM_R", "Messenger - EM Radiation - Radio"),
("MMA_M_G", "Messenger - Gravitational Waves"),
("MMA_M_G_CBI", "Messenger - Gravitational Waves - Compact Binary Inspiral"),
("MMA_M_G_S", "Messenger - Gravitational Waves - Stochastic"),
("MMA_M_G_CON", "Messenger - Gravitational Waves - Continuous"),
("MMA_M_G_B", "Messenger - Gravitational Waves - Burst"),
("MMA_M_C", "Messenger - Cosmic Rays"),
("MMA_M_N", "Messenger - Neutrinos"),
("MMA_O_BI", "Objects - Binaries"),
("MMA_O_BI_BBH", "Objects - Binaries - Binary Black Holes"),
("MMA_O_BI_BNS", "Objects - Binaries - Binary Neutron Stars"),
("MMA_O_BI_C", "Objects - Binaries - Cataclysmic Variables"),
("MMA_O_BI_N", "Objects - Binaries - Neutron Star-Black Hole"),
("MMA_O_BI_B", "Objects - Binaries - Binary Pulsars"),
("MMA_O_BI_W", "Objects - Binaries - White Dwarf Binaries"),
("MMA_O_BH", "Objects - Black Holes"),
("MMA_O_BH_AGN", "Objects - Black Holes - Active Galactic Nuclei"),
("MMA_O_BH_IM", "Objects - Black Holes - Intermediate mass"),
("MMA_O_BH_STM", "Objects - Black Holes - Stellar mass"),
("MMA_O_BH_SUM", "Objects - Black Holes - Supermassive"),
("MMA_O_E", "Objects - Exoplanets"),
("MMA_O_N", "Objects - Neutron Stars"),
("MMA_O_N_M", "Objects - Neutron Stars - Magnetars"),
("MMA_O_N_P", "Objects - Neutron Stars - Pulsars"),
("MMA_O_N_PWN", "Objects - Neutron Stars - Pulsar Wind Nebula"),
("MMA_O_S", "Objects - Supernova Remnants"),
("MMA_S_F", "Signals - Fast Radio Bursts"),
("MMA_S_G", "Signals - Gamma-ray Bursts"),
("MMA_S_K", "Signals - Kilonovae"),
("MMA_S_N", "Signals - Novae"),
("MMA_S_P", "Signals - Pevatrons"),
("MMA_S_ST", "Signals - Stellar flares"),
("MMA_S_SU", "Signals - Supernovae"),
],
max_length=255,
),
blank=True,
db_column="tdamm_tag_ml",
null=True,
size=None,
),
),
migrations.AlterModelTable(
name="candidateurl",
table="sde_collections_candidateurl",
),
]
13 changes: 13 additions & 0 deletions sde_collections/migrations/0066_merge_20241120_0158.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 4.2.9 on 2024-11-20 07:58

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("sde_collections", "0059_candidateurl_tdamm_tag_manual_and_more"),
("sde_collections", "0065_rename_delete_deltaurl_to_delete_and_more"),
]

operations = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.9 on 2024-11-20 16:12

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("sde_collections", "0066_merge_20241120_0158"),
]

operations = [
migrations.RemoveField(
model_name="candidateurl",
name="tdamm_tag_manual",
),
migrations.RemoveField(
model_name="candidateurl",
name="tdamm_tag_ml",
),
]
Loading

0 comments on commit b001d04

Please sign in to comment.