Skip to content

Commit 03bee6c

Browse files
committed
WIP
1 parent 95ef02b commit 03bee6c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

dandiapi/api/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .asset_paths import AssetPath, AssetPathRelation
55
from .audit import AuditRecord
66
from .dandiset import Dandiset, DandisetStar
7+
from .datacite import DataciteEvent
78
from .garbage_collection import GarbageCollectionEvent, GarbageCollectionEventRecord
89
from .oauth import StagingApplication
910
from .stats import ApplicationStats
@@ -21,6 +22,7 @@
2122
'AuditRecord',
2223
'Dandiset',
2324
'DandisetStar',
25+
'DataciteEvent',
2426
'GarbageCollectionEvent',
2527
'GarbageCollectionEventRecord',
2628
'StagingApplication',

dandiapi/api/models/datacite.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from __future__ import annotations
2+
3+
from django.db import models
4+
5+
from dandiapi.api.models.dandiset import Dandiset
6+
7+
8+
class DataciteEventType(models.TextChoices):
9+
CREATE_DOI = 'CREATE_DOI', 'Create DOI'
10+
UPDATE_DOI = 'UPDATE_DOI', 'Update DOI'
11+
HIDE_DOI = 'HIDE_DOI', 'Hide DOI'
12+
DELETE_DOI = 'DELETE_DOI', 'Delete DOI'
13+
14+
15+
class DataciteEvent(models.Model):
16+
timestamp = models.DateTimeField()
17+
event_type = models.CharField(
18+
max_length=max(len(choice[0]) for choice in DataciteEventType.choices),
19+
choices=DataciteEventType.choices,
20+
)
21+
22+
# Since the deletion of a dandiset will set the foreign key relation to null,
23+
# also store the dandiset ID in a separate field
24+
dandiset_identifier = models.PositiveIntegerField()
25+
dandiset = models.ForeignKey(
26+
Dandiset,
27+
related_name='datacite_events',
28+
on_delete=models.SET_NULL,
29+
null=True,
30+
)
31+
32+
class Meta:
33+
ordering = ['timestamp']
34+
constraints = [
35+
models.CheckConstraint(
36+
condition=models.Q(dandiset_id=models.F('dandiset_identifier')),
37+
name='dandiset_fields_equal',
38+
)
39+
]
40+
41+
def __str__(self) -> str:
42+
return f'Datacite Event: {self.event_type} @ {self.timestamp}'

0 commit comments

Comments
 (0)