Skip to content

Commit

Permalink
Merge pull request #168 from stanfordnmbl/dev
Browse files Browse the repository at this point in the history
Subject tags and subject refactoring
  • Loading branch information
antoinefalisse committed Apr 12, 2024
2 parents 513b2dc + 36fda04 commit 7287eb9
Show file tree
Hide file tree
Showing 10 changed files with 414 additions and 12 deletions.
28 changes: 19 additions & 9 deletions mcserver/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
AnalysisResult,
AnalysisDashboardTemplate,
AnalysisDashboard,
SubjectTags
)
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin, GroupAdmin
Expand Down Expand Up @@ -54,10 +55,11 @@ class SessionAdmin(admin.ModelAdmin):
'id', 'user', 'subject',
'public',
'created_at', 'updated_at', 'server',
'status', 'status_changed',
'trashed', 'trashed_at',
)
raw_id_fields = ('user', 'subject')
search_fields = ['id']
search_fields = ['id', 'user__username', "subject__name"]
inlines = [TrialInline]
actions = ['set_subject']

Expand Down Expand Up @@ -92,7 +94,7 @@ class ResultInline(admin.TabularInline):

@admin.register(Trial)
class TrialAdmin(admin.ModelAdmin):
search_fields = ['id', 'session_id']
search_fields = ['id', 'name', 'session__id']
list_display = (
'id',
'name',
Expand All @@ -111,20 +113,20 @@ class ResultAdmin(admin.ModelAdmin):
'id', 'trial', 'tag', 'media',
'device_id',
'created_at', 'updated_at')
search_fields = ['trial']
search_fields = ['id', 'trial__id']
raw_id_fields = ('trial',)


@admin.register(Video)
class VideoAdmin(admin.ModelAdmin):
search_fields = ['trial']
list_display = ('trial', 'video', 'created_at', 'updated_at')
search_fields = ['id', 'trial__id']
list_display = ('id', 'trial', 'video', 'created_at', 'updated_at')
raw_id_fields = ('trial',)


@admin.register(Subject)
class SubjectAdmin(admin.ModelAdmin):
search_fields = ['name']
search_fields = ['name', 'user__username']
list_display = (
'id',
'name',
Expand All @@ -141,11 +143,19 @@ class SubjectAdmin(admin.ModelAdmin):
)
raw_id_fields = ('user',)

@admin.register(SubjectTags)
class SubjectTagsAdmin(admin.ModelAdmin):
search_fields = ['tag', 'subject__name']
list_display = (
'id',
'tag',
'subject',
)

@admin.register(ResetPassword)
class ResetPasswordAdmin(admin.ModelAdmin):
search_field = ['email']
list_display = ('email', 'id', 'datetime')
list_display = ['email', 'id', 'datetime']


@admin.register(LogEntry)
Expand Down Expand Up @@ -184,10 +194,10 @@ class DownloadLogAdmin(admin.ModelAdmin):
@admin.register(AnalysisFunction)
class AnalysisFunctionAdmin(admin.ModelAdmin):
list_display = [
'id', 'title', 'is_active',
'id', 'title', 'description', 'is_active',
'only_for_users_display',
'local_run', 'created_at']
search_fields = ['title', 'description']
search_fields = ['title']
raw_id_fields = ['only_for_users']

def only_for_users_display(self, obj):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Generated by Django 4.2 on 2024-02-08 19:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("mcserver", "0028_user_institutional_use"),
]

operations = [
migrations.AddField(
model_name="subject",
name="tags",
field=models.CharField(
blank=True,
choices=[("unimpaired", "Unimpaired")],
max_length=20,
null=True,
),
),
migrations.AlterField(
model_name="analysisresult",
name="status",
field=models.IntegerField(
choices=[
(100, "Continue"),
(101, "Switching Protocols"),
(102, "Processing"),
(103, "Early Hints"),
(200, "OK"),
(201, "Created"),
(202, "Accepted"),
(203, "Non-Authoritative Information"),
(204, "No Content"),
(205, "Reset Content"),
(206, "Partial Content"),
(207, "Multi-Status"),
(208, "Already Reported"),
(226, "IM Used"),
(300, "Multiple Choices"),
(301, "Moved Permanently"),
(302, "Found"),
(303, "See Other"),
(304, "Not Modified"),
(305, "Use Proxy"),
(307, "Temporary Redirect"),
(308, "Permanent Redirect"),
(400, "Bad Request"),
(401, "Unauthorized"),
(402, "Payment Required"),
(403, "Forbidden"),
(404, "Not Found"),
(405, "Method Not Allowed"),
(406, "Not Acceptable"),
(407, "Proxy Authentication Required"),
(408, "Request Timeout"),
(409, "Conflict"),
(410, "Gone"),
(411, "Length Required"),
(412, "Precondition Failed"),
(413, "Request Entity Too Large"),
(414, "Request-URI Too Long"),
(415, "Unsupported Media Type"),
(416, "Requested Range Not Satisfiable"),
(417, "Expectation Failed"),
(418, "I'm a Teapot"),
(421, "Misdirected Request"),
(422, "Unprocessable Entity"),
(423, "Locked"),
(424, "Failed Dependency"),
(425, "Too Early"),
(426, "Upgrade Required"),
(428, "Precondition Required"),
(429, "Too Many Requests"),
(431, "Request Header Fields Too Large"),
(451, "Unavailable For Legal Reasons"),
(500, "Internal Server Error"),
(501, "Not Implemented"),
(502, "Bad Gateway"),
(503, "Service Unavailable"),
(504, "Gateway Timeout"),
(505, "HTTP Version Not Supported"),
(506, "Variant Also Negotiates"),
(507, "Insufficient Storage"),
(508, "Loop Detected"),
(510, "Not Extended"),
(511, "Network Authentication Required"),
],
default=200,
help_text="Status code function responsed with.",
verbose_name="Status",
),
),
]
18 changes: 18 additions & 0 deletions mcserver/migrations/0030_rename_tags_subject_subject_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2 on 2024-02-08 19:21

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("mcserver", "0029_subject_tags_alter_analysisresult_status"),
]

operations = [
migrations.RenameField(
model_name="subject",
old_name="tags",
new_name="subject_tags",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.2 on 2024-02-08 19:28

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("mcserver", "0030_rename_tags_subject_subject_tags"),
]

operations = [
migrations.RemoveField(
model_name="subject",
name="subject_tags",
),
migrations.CreateModel(
name="SubjectTags",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("tag", models.TextField()),
(
"subject",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="mcserver.subject",
),
),
],
options={
"ordering": ["subject", "tag"],
},
),
]
14 changes: 14 additions & 0 deletions mcserver/migrations/0032_merge_20240319_1339.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.1.14 on 2024-03-19 20:39

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('mcserver', '0029_analysisfunction_info'),
('mcserver', '0031_remove_subject_subject_tags_subjecttags'),
]

operations = [
]
18 changes: 18 additions & 0 deletions mcserver/migrations/0033_auto_20240319_1339.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.14 on 2024-03-19 20:39

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mcserver', '0032_merge_20240319_1339'),
]

operations = [
migrations.AlterField(
model_name='analysisresult',
name='status',
field=models.IntegerField(choices=[(100, 'Continue'), (101, 'Switching Protocols'), (102, 'Processing'), (200, 'OK'), (201, 'Created'), (202, 'Accepted'), (203, 'Non-Authoritative Information'), (204, 'No Content'), (205, 'Reset Content'), (206, 'Partial Content'), (207, 'Multi-Status'), (208, 'Already Reported'), (226, 'IM Used'), (300, 'Multiple Choices'), (301, 'Moved Permanently'), (302, 'Found'), (303, 'See Other'), (304, 'Not Modified'), (305, 'Use Proxy'), (307, 'Temporary Redirect'), (308, 'Permanent Redirect'), (400, 'Bad Request'), (401, 'Unauthorized'), (402, 'Payment Required'), (403, 'Forbidden'), (404, 'Not Found'), (405, 'Method Not Allowed'), (406, 'Not Acceptable'), (407, 'Proxy Authentication Required'), (408, 'Request Timeout'), (409, 'Conflict'), (410, 'Gone'), (411, 'Length Required'), (412, 'Precondition Failed'), (413, 'Request Entity Too Large'), (414, 'Request-URI Too Long'), (415, 'Unsupported Media Type'), (416, 'Requested Range Not Satisfiable'), (417, 'Expectation Failed'), (421, 'Misdirected Request'), (422, 'Unprocessable Entity'), (423, 'Locked'), (424, 'Failed Dependency'), (426, 'Upgrade Required'), (428, 'Precondition Required'), (429, 'Too Many Requests'), (431, 'Request Header Fields Too Large'), (500, 'Internal Server Error'), (501, 'Not Implemented'), (502, 'Bad Gateway'), (503, 'Service Unavailable'), (504, 'Gateway Timeout'), (505, 'HTTP Version Not Supported'), (506, 'Variant Also Negotiates'), (507, 'Insufficient Storage'), (508, 'Loop Detected'), (510, 'Not Extended'), (511, 'Network Authentication Required')], default=200, help_text='Status code function responsed with.', verbose_name='Status'),
),
]
18 changes: 18 additions & 0 deletions mcserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class Session(models.Model):
public = models.BooleanField(blank=False, null=False, default=False)
server = models.GenericIPAddressField(null=True, blank=True)

status = models.CharField(max_length=64, default="init", blank=True, db_index=True)
status_changed = models.DateTimeField(null=True, blank=True, default=timezone.now, db_index=True)

subject = models.ForeignKey(
'Subject', blank=True, null=True,
related_name='sessions',
Expand Down Expand Up @@ -335,6 +338,21 @@ def save(self, *args, **kwargs):
self.birth_year = timezone.now().year - self.age
return super().save(*args, **kwargs)


class SubjectTags(models.Model):
tag = models.TextField(blank=False, null=False)
subject = models.ForeignKey(to=Subject, on_delete=models.CASCADE, blank=False, null=False)

class Meta:
ordering = ['subject', 'tag']

def __str__(self):
return self.subject.name + " - " + self.tag

verbose_name = 'Subject Tag'
verbose_name_plural = 'Subject Tags'


class AnalysisFunction(models.Model):
""" This model describes AWS Lambda function object.
"""
Expand Down
Loading

0 comments on commit 7287eb9

Please sign in to comment.