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

add ! name and description to DeduplicationSet #81

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 0 additions & 13 deletions src/hope_dedup_engine/apps/api/admin.py

This file was deleted.

4 changes: 4 additions & 0 deletions src/hope_dedup_engine/apps/api/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .deduplicationset import DeduplicationSetAdmin # noqa
from .duplicate import DuplicateAdmin # noqa
from .hdetoken import HDETokenAdmin # noqa
from .image import ImageAdmin # noqa
40 changes: 40 additions & 0 deletions src/hope_dedup_engine/apps/api/admin/deduplicationset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.contrib.admin import ModelAdmin, register

from adminfilters.dates import DateRangeFilter
from adminfilters.filters import ChoicesFieldComboFilter, DjangoLookupFilter
from adminfilters.mixin import AdminFiltersMixin

from hope_dedup_engine.apps.api.models import DeduplicationSet


@register(DeduplicationSet)
class DeduplicationSetAdmin(AdminFiltersMixin, ModelAdmin):
list_display = (
"id",
"name",
"reference_pk",
"state",
"created_at",
"updated_at",
"deleted",
)
readonly_fields = (
"id",
"state",
"external_system",
"created_at",
"created_by",
"updated_at",
"updated_by",
"deleted",
)
search_fields = ("name",)
list_filter = (
("state", ChoicesFieldComboFilter),
("created_at", DateRangeFilter),
("updated_at", DateRangeFilter),
DjangoLookupFilter,
)

def has_add_permission(self, request):
return False
35 changes: 35 additions & 0 deletions src/hope_dedup_engine/apps/api/admin/duplicate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.contrib.admin import ModelAdmin, register

from adminfilters.filters import (
DjangoLookupFilter,
NumberFilter,
RelatedFieldComboFilter,
)
from adminfilters.mixin import AdminFiltersMixin

from hope_dedup_engine.apps.api.models import Duplicate


@register(Duplicate)
class DuplicateAdmin(AdminFiltersMixin, ModelAdmin):
list_display = (
"id",
"deduplication_set",
"score",
"first_reference_pk",
"second_reference_pk",
)
list_filter = (
("deduplication_set", RelatedFieldComboFilter),
("score", NumberFilter),
DjangoLookupFilter,
)

def has_add_permission(self, request):
return False

def has_delete_permission(self, request, obj=None):
return False

def has_change_permission(self, request, obj=None):
return False
8 changes: 8 additions & 0 deletions src/hope_dedup_engine/apps/api/admin/hdetoken.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib.admin import ModelAdmin, register

from hope_dedup_engine.apps.api.models import HDEToken


@register(HDEToken)
class HDETokenAdmin(ModelAdmin):
pass
32 changes: 32 additions & 0 deletions src/hope_dedup_engine/apps/api/admin/image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from django.contrib.admin import ModelAdmin, register

from adminfilters.dates import DateRangeFilter
from adminfilters.filters import DjangoLookupFilter, RelatedFieldComboFilter
from adminfilters.mixin import AdminFiltersMixin

from hope_dedup_engine.apps.api.models import Image


@register(Image)
class ImageAdmin(AdminFiltersMixin, ModelAdmin):
list_display = (
"id",
"filename",
"deduplication_set",
"created_at",
)

list_filter = (
("deduplication_set", RelatedFieldComboFilter),
("created_at", DateRangeFilter),
DjangoLookupFilter,
)

def has_add_permission(self, request):
return False

def has_delete_permission(self, request, obj=None):
return False

def has_change_permission(self, request, obj=None):
return False
3 changes: 1 addition & 2 deletions src/hope_dedup_engine/apps/api/deduplication/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ def find_duplicates(deduplication_set_id: str, serialized_lock: str) -> None:
if lock_enabled:
lock.release()

except Exception as e:
except Exception:
deduplication_set.state = DeduplicationSet.State.ERROR
deduplication_set.error = str(e)
deduplication_set.save()
raise
finally:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 5.0.7 on 2024-09-20 08:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("api", "0002_remove_duplicate_first_filename_and_more"),
]

operations = [
migrations.RemoveField(
model_name="deduplicationset",
name="error",
),
migrations.AddField(
model_name="deduplicationset",
name="description",
field=models.TextField(blank=True, null=True),
),
migrations.AlterField(
model_name="deduplicationset",
name="name",
field=models.CharField(
blank=True, db_index=True, max_length=128, null=True, unique=True
),
),
]

This file was deleted.

12 changes: 9 additions & 3 deletions src/hope_dedup_engine/apps/api/models/deduplication.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any, override
from typing import Any, Final, override
from uuid import uuid4

from django.conf import settings
from django.db import models

from hope_dedup_engine.apps.security.models import ExternalSystem

REFERENCE_PK_LENGTH = 100
REFERENCE_PK_LENGTH: Final[int] = 100

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still used? @vitali-yanushchyk-valor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still used? @vitali-yanushchyk-valor

Yes - it's other part of code. @domdinicola


class DeduplicationSet(models.Model):
Expand All @@ -24,14 +24,17 @@ class State(models.IntegerChoices):
ERROR = 3, "Error" # Error occurred

id = models.UUIDField(primary_key=True, default=uuid4)
name = models.CharField(
max_length=128, unique=True, null=True, blank=True, db_index=True
)
description = models.TextField(null=True, blank=True)
reference_pk = models.CharField(max_length=REFERENCE_PK_LENGTH) # source_id
state = models.IntegerField(
choices=State.choices,
default=State.CLEAN,
)
deleted = models.BooleanField(null=False, blank=False, default=False)
external_system = models.ForeignKey(ExternalSystem, on_delete=models.CASCADE)
error = models.CharField(max_length=255, null=True, blank=True)
created_by = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
Expand All @@ -50,6 +53,9 @@ class State(models.IntegerChoices):
updated_at = models.DateTimeField(auto_now=True)
notification_url = models.CharField(max_length=255, null=True, blank=True)

def __str__(self) -> str:
return f"ID: {self.pk}" if not self.name else f"{self.name}"


class Image(models.Model):
"""
Expand Down
Loading