fix snapshot uuid

This commit is contained in:
Nick Sweeting 2024-08-18 01:07:21 -07:00
parent 8c50257fe9
commit 57d31b2b14
No known key found for this signature in database
4 changed files with 12 additions and 6 deletions

View file

@ -77,7 +77,7 @@ class ArchiveResultFilterSchema(FilterSchema):
id: Optional[UUID] = Field(None, q='id')
search: Optional[str] = Field(None, q=['snapshot__url__icontains', 'snapshot__title__icontains', 'snapshot__tags__name__icontains', 'extractor', 'output__icontains'])
snapshot_uuid: Optional[UUID] = Field(None, q='snapshot_uuid__icontains')
snapshot_id: Optional[UUID] = Field(None, q='snapshot_id__icontains')
snapshot_url: Optional[str] = Field(None, q='snapshot__url__icontains')
snapshot_tag: Optional[str] = Field(None, q='snapshot__tags__name__icontains')
@ -227,7 +227,7 @@ def get_snapshot(request, snapshot_id: str, with_archiveresults: bool=True):
request.with_archiveresults = with_archiveresults
snapshot = None
try:
snapshot = Snapshot.objects.get(Q(uuid__startswith=snapshot_id) | Q(abid__startswith=snapshot_id)| Q(pk__startswith=snapshot_id))
snapshot = Snapshot.objects.get(Q(abid__startswith=snapshot_id)| Q(pk__startswith=snapshot_id))
except Snapshot.DoesNotExist:
pass
@ -237,7 +237,7 @@ def get_snapshot(request, snapshot_id: str, with_archiveresults: bool=True):
pass
try:
snapshot = snapshot or Snapshot.objects.get(Q(uuid__icontains=snapshot_id) | Q(abid__icontains=snapshot_id))
snapshot = snapshot or Snapshot.objects.get(Q(pk__icontains=snapshot_id) | Q(abid__icontains=snapshot_id))
except Snapshot.DoesNotExist:
pass

View file

@ -294,7 +294,10 @@ class SnapshotAdmin(SearchResultsAdminMixin, admin.ModelAdmin):
)
def identifiers(self, obj):
return get_abid_info(self, obj)
try:
return get_abid_info(self, obj)
except Exception as e:
return str(e)
@admin.display(
description='Title',

View file

@ -140,6 +140,9 @@ class Snapshot(ABIDModel):
keys = ('url', 'timestamp', 'title', 'tags', 'updated')
@property
def uuid(self):
return self.id
def __repr__(self) -> str:
title = self.title or '-'
@ -354,7 +357,7 @@ class ArchiveResult(ABIDModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True, unique=True, verbose_name='ID')
abid = ABIDField(prefix=abid_prefix)
snapshot = models.ForeignKey(Snapshot, on_delete=models.CASCADE, to_field='id')
snapshot = models.ForeignKey(Snapshot, on_delete=models.CASCADE, to_field='id', db_column='snapshot_id')
extractor = models.CharField(choices=EXTRACTOR_CHOICES, max_length=32)
cmd = models.JSONField()

View file

@ -274,7 +274,7 @@ class Link:
@cached_property
def snapshot_uuid(self):
return str(self.snapshot.uuid)
return str(self.snapshot.id)
@cached_property
def snapshot_abid(self):