Skip to content

Commit

Permalink
CU-8697qrm0k: add further metadata for model uploads and vocabulary '…
Browse files Browse the repository at this point in the history
…name' attr and admin model. Fix the cdb name validator for solr collection names
  • Loading branch information
tomolopolis committed Jan 30, 2025
1 parent f421ae2 commit ca60484
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
14 changes: 14 additions & 0 deletions webapp/api/api/admin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,27 @@ def save_model(self, request, obj, form, change):
super().save_model(request, obj, form, change)


class VocabularyAdmin(admin.ModelAdmin):
model = Vocabulary
list_display = ('name', 'create_time', 'last_modified', 'last_modified_by')
fields = ('name', 'vocab_file', 'create_time', 'last_modified', 'last_modified_by')

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):
model = ModelPack
list_display = ('name', 'model_pack', 'concept_db', 'vocab', 'metacats')
fields = ['name', 'model_pack']

def metacats(self, obj):
return ", ".join(str(m_c) for m_c in obj.meta_cats.all())

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


class MetaCATModelAdmin(admin.ModelAdmin):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 5.1.4 on 2025-01-30 11:07

import django.core.validators
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0086_vocabulary_name'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.AddField(
model_name='modelpack',
name='create_time',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='modelpack',
name='last_modified',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='modelpack',
name='last_modified_by',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='vocabulary',
name='create_time',
field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now),
preserve_default=False,
),
migrations.AddField(
model_name='vocabulary',
name='last_modified',
field=models.DateTimeField(auto_now=True),
),
migrations.AddField(
model_name='vocabulary',
name='last_modified_by',
field=models.ForeignKey(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AlterField(
model_name='conceptdb',
name='name',
field=models.CharField(blank=True, default='', max_length=100, unique=True, validators=[django.core.validators.RegexValidator('^[a-zA-Z][a-zA-Z0-9_]*$', 'Only alpahanumeric characters, -, _ are allowed for CDB names')]),
),
]
19 changes: 19 additions & 0 deletions webapp/api/api/migrations/0088_alter_conceptdb_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.1.4 on 2025-01-30 11:09

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0087_modelpack_create_time_modelpack_last_modified_and_more'),
]

operations = [
migrations.AlterField(
model_name='conceptdb',
name='name',
field=models.CharField(blank=True, default='', max_length=100, unique=True, validators=[django.core.validators.RegexValidator('^[a-zA-Z][a-zA-Z0-9_]*$', 'a-z for first character required. Alpahanumeric and _ thereafter are allowed for CDB names')]),
),
]
8 changes: 7 additions & 1 deletion webapp/api/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
]


cdb_name_validator = RegexValidator(r'^[0-9a-zA-Z_-]*$', 'Only alpahanumeric characters, -, _ are allowed for CDB names')
cdb_name_validator = RegexValidator(r'^[a-zA-Z][a-zA-Z0-9_]*$', 'a-z for first character required. Alpahanumeric and _ thereafter are allowed for CDB names')

logger = logging.getLogger(__name__)

Expand All @@ -41,6 +41,9 @@ class ModelPack(models.Model):
concept_db = models.ForeignKey('ConceptDB', on_delete=models.CASCADE, blank=True, null=True)
vocab = models.ForeignKey('Vocabulary', on_delete=models.CASCADE, blank=True, null=True)
meta_cats = models.ManyToManyField('MetaCATModel', blank=True, default=None)
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 save(self, *args, **kwargs):
super().save(*args, **kwargs)
Expand Down Expand Up @@ -134,6 +137,9 @@ def __str__(self):
class Vocabulary(models.Model):
name = models.CharField(max_length=100, default='', blank=True)
vocab_file = models.FileField()
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 save(self, *args, skip_load=False, **kwargs):
super().save(*args, **kwargs)
Expand Down
1 change: 1 addition & 0 deletions webapp/api/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class UserViewSet(viewsets.ModelViewSet):

class ProjectAnnotateEntitiesViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.IsAuthenticated]
http_method_names = ['get', 'post', 'put']
queryset = ProjectAnnotateEntities.objects.all()
serializer_class = ProjectAnnotateEntitiesSerializer
filterset_fields = ['members', 'dataset', 'id', 'project_status', 'annotation_classification']
Expand Down

0 comments on commit ca60484

Please sign in to comment.