Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Two Column to work with Delta Urls #1103

Merged
merged 23 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f4849e8
add PairedFieldDescriptor two-column tag model
Kirandawadi Oct 30, 2024
a469ef1
add fields to admin panel
Kirandawadi Oct 30, 2024
8e8e0ac
moved tdamm_tags feature from collection to candidate_url
Kirandawadi Nov 4, 2024
f5c69bd
refactor code
Kirandawadi Nov 4, 2024
7e888e8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 4, 2024
1b9d800
modify architecture to define one single field to generate two
Kirandawadi Nov 13, 2024
74b5b76
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 13, 2024
3ee8845
fix flake8 issues
Kirandawadi Nov 13, 2024
13649ae
refactor code for admin panel handling TDAMM
Kirandawadi Nov 13, 2024
a5a408c
add TDAMM_TAG_CHOICES to collection_choice_fields
Kirandawadi Nov 20, 2024
e8b0cf0
delete is_tdamm switch functionality
Kirandawadi Nov 20, 2024
b65c693
add test cases for two column tags functionality
Kirandawadi Nov 15, 2024
0707500
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2024
1a2e792
merge 1051-backend-model-changes-on-cosmos-to-hold-new-incoming-urls-…
Kirandawadi Nov 20, 2024
e45eeeb
refactor code for DeltaUrl model
Kirandawadi Nov 21, 2024
ff1484b
add tdamm_tag field to new serializers
Kirandawadi Nov 21, 2024
70ccb2c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
f35a7de
Merge branch 'dev' into 1093-write-tests-for-two-column-tags-function…
Kirandawadi Dec 5, 2024
1b70b52
Fix incorrect import
Kirandawadi Dec 5, 2024
e0ac9e4
merge migrations conflict
Kirandawadi Dec 5, 2024
8f87aef
Update sde_collections/models/candidate_url.py
CarsonDavis Dec 5, 2024
de20d47
add a TDAMM field Not TDAMM
CarsonDavis Dec 5, 2024
547401c
add tdamm tags to the api serializer tests
CarsonDavis Dec 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading