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

CU-8695e8hu5: Save extra metadata for cdb edits #209

Merged
merged 2 commits into from
Sep 25, 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
6 changes: 6 additions & 0 deletions webapp/api/api/admin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ class AnnotatedEntityAdmin(admin.ModelAdmin):
class ConceptDBAdmin(admin.ModelAdmin):
model = ConceptDB
actions = [import_concepts, delete_indexed_concepts, reset_cdb_filters]
list_display = ('name', 'use_for_training', 'create_time', 'last_modified', 'last_modified_by')
fields = ('name', 'cdb_file', 'use_for_training')

def save_model(self, request, obj, form, change):
obj.last_modified_by = request.user
super().save_model(request, obj, form, change)


class ModelPackAdmin(admin.ModelAdmin):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 5.0.6 on 2024-09-20 15:21

import datetime
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0083_project_prepared_documents_and_more'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AddField(
model_name='conceptdb',
name='create_time',
field=models.DateTimeField(auto_now_add=True, default=datetime.datetime(2023, 1, 1, 0, 0)),
preserve_default=False,
),
migrations.AddField(
model_name='conceptdb',
name='last_modified',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='conceptdb',
name='last_modified_by',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]
5 changes: 4 additions & 1 deletion webapp/api/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class ConceptDB(models.Model):
name = models.CharField(max_length=100, default='', blank=True, validators=[cdb_name_validator])
cdb_file = models.FileField()
use_for_training = models.BooleanField(default=True)
create_time = models.DateTimeField(auto_now_add=True)
last_modified = models.DateTimeField(auto_now=True)
last_modified_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, default=None, null=True)

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -110,7 +113,7 @@ def from_db(cls, db, field_names, values):
inst.__cdb_field_name = [v for f, v in zip(field_names, values) if f == 'cdb_file'][0]
return inst

def save(self, *args, skip_load=False, **kwargs, ):
def save(self, *args, skip_load=False, **kwargs):
# load the CDB, and raise if this fails.
if not skip_load:
try:
Expand Down
7 changes: 5 additions & 2 deletions webapp/api/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,17 @@ class EntityRelationViewSet(viewsets.ModelViewSet):

class ConceptDBViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated]
http_method_names = ['get', 'post', 'head']
http_method_names = ['get', 'post', 'head', 'delete']
queryset = ConceptDB.objects.all()
serializer_class = ConceptDBSerializer

def perform_create(self, serializer):
serializer.save(last_modified_by=self.request.user)


class VocabularyViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated]
http_method_names = ['get', 'post', 'head']
http_method_names = ['get', 'post', 'head', 'delete']
queryset = Vocabulary.objects.all()
serializer_class = VocabularySerializer

Expand Down