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

Dev #2

Merged
merged 8 commits into from Oct 9, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# vscode
.vscode
41 changes: 40 additions & 1 deletion out_on_a_LIMS/lims/forms.py
@@ -1,6 +1,7 @@
from django import forms
from django.forms import ModelForm
from .models import Sample, Project, Location, Researcher
from .models import (
Sample, Project, Location, Researcher, Event, Subject)


class DateInput(forms.DateInput):
Expand Down Expand Up @@ -36,3 +37,41 @@ class ResearcherForm(ModelForm):
class Meta:
model = Researcher
fields = ['name', 'email', 'phone']


class EventForm(ModelForm):
class Meta:
model = Event
fields = ['name', 'location', 'date',
'researcher'
]
widgets = {
'date': DateInput()
}
def __init__(self, *args, **kwargs):
super(EventForm, self).__init__(*args, **kwargs)
self.fields['location'].label_from_instance = self.label_from_instance
self.fields['researcher'].label_from_instance = self.label_from_instance

@staticmethod
def label_from_instance(obj):
return "%s" % obj.name


class SubjectForm(ModelForm):
class Meta:
model = Subject
fields = ['subject_ui', 'location', 'first_name',
'last_name', 'birthdate', 'sex', 'vaccine_status',
'covid'
]
widgets = {
'birthdate': DateInput()
}
def __init__(self, *args, **kwargs):
super(SubjectForm, self).__init__(*args, **kwargs)
self.fields['location'].label_from_instance = self.label_from_instance

@staticmethod
def label_from_instance(obj):
return "%s" % obj.name
39 changes: 27 additions & 12 deletions out_on_a_LIMS/lims/migrations/0001_initial.py
@@ -1,4 +1,4 @@
# Generated by Django 3.1.2 on 2021-10-09 00:21
# Generated by Django 3.1.2 on 2021-10-09 21:00

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -26,12 +26,12 @@ class Migration(migrations.Migration):
name='Location',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('address', models.CharField(blank=True, max_length=100)),
('room', models.CharField(blank=True, max_length=100)),
('contact_name', models.CharField(blank=True, max_length=100)),
('contact_email', models.EmailField(blank=True, max_length=254)),
('contact_phone', phone_field.models.PhoneField(blank=True, max_length=31)),
('name', models.CharField(max_length=100, unique=True)),
('address', models.CharField(blank=True, max_length=100, null=True)),
('description', models.TextField(blank=True, null=True)),
('contact_name', models.CharField(blank=True, max_length=100, null=True)),
('contact_email', models.EmailField(blank=True, max_length=254, null=True)),
('contact_phone', phone_field.models.PhoneField(blank=True, max_length=31, null=True)),
],
),
migrations.CreateModel(
Expand All @@ -50,16 +50,23 @@ class Migration(migrations.Migration):
name='Researcher',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('email', models.EmailField(blank=True, max_length=254)),
('phone', phone_field.models.PhoneField(blank=True, max_length=31)),
('name', models.CharField(max_length=100, unique=True)),
('email', models.EmailField(blank=True, max_length=254, null=True)),
('phone', phone_field.models.PhoneField(blank=True, max_length=31, null=True)),
],
),
migrations.CreateModel(
name='Subject',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('subject_id', models.CharField(max_length=6)),
('subject_ui', models.CharField(max_length=6, unique=True)),
('first_name', models.CharField(blank=True, max_length=100, null=True)),
('last_name', models.CharField(blank=True, max_length=100, null=True)),
('birthdate', models.DateField(blank=True, null=True)),
('sex', models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female')], max_length=1, null=True)),
('vaccine_status', models.CharField(blank=True, choices=[('F', 'Fully'), ('P', 'Partially'), ('N', 'No')], max_length=1, null=True)),
('covid', models.BooleanField(blank=True, help_text='Has subject been infected with COVID-19 prior to study', null=True)),
('location', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lims.location')),
],
),
migrations.CreateModel(
Expand All @@ -74,13 +81,21 @@ class Migration(migrations.Migration):
('subject_id', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lims.subject')),
],
),
migrations.AddField(
model_name='location',
name='project',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lims.project'),
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True)),
('date', models.DateField()),
('description', models.TextField(blank=True, null=True)),
('notes', models.TextField(blank=True, null=True)),
('location', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='lims.location')),
('researcher', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.PROTECT, to='lims.researcher')),
('researcher', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='lims.researcher')),
],
),
]
55 changes: 0 additions & 55 deletions out_on_a_LIMS/lims/migrations/0002_auto_20211009_0147.py

This file was deleted.

28 changes: 28 additions & 0 deletions out_on_a_LIMS/lims/migrations/0002_auto_20211009_1429.py
@@ -0,0 +1,28 @@
# Generated by Django 3.1.2 on 2021-10-09 21:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('lims', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='subject',
name='covid',
field=models.CharField(blank=True, choices=[('Yes', 'Yes'), ('No', 'No')], help_text='Has subject been infected with COVID-19 prior to study', max_length=10, null=True),
),
migrations.AlterField(
model_name='subject',
name='sex',
field=models.CharField(blank=True, choices=[('MALE', 'Male'), ('FEMALE', 'Female')], max_length=10, null=True),
),
migrations.AlterField(
model_name='subject',
name='vaccine_status',
field=models.CharField(blank=True, choices=[('FULL', 'Full'), ('PARTIAL', 'Partial'), ('NO', 'None')], max_length=10, null=True),
),
]
34 changes: 0 additions & 34 deletions out_on_a_LIMS/lims/migrations/0003_auto_20211009_0323.py

This file was deleted.

77 changes: 55 additions & 22 deletions out_on_a_LIMS/lims/models.py
Expand Up @@ -5,26 +5,66 @@

# Create your models here.

class Project(models.Model):
name = models.CharField(max_length=100, unique=True)
investigator = models.CharField(max_length=100, blank=True, null=True)
start_date = models.DateField(blank=True, null=True)
end_date = models.DateField(blank=True, null=True)
description = models.TextField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)

def __str__(self):
return str(self.name)

class Location(models.Model):
name = models.CharField(max_length=100, unique=True)
address = models.CharField(max_length=100, blank=True, null=True)
description = models.TextField(blank=True, null=True)
contact_name = models.CharField(max_length=100, blank=True, null=True)
contact_email = models.EmailField(blank=True, null=True)
contact_phone = PhoneField(blank=True, null=True)
project = models.ForeignKey(Project, on_delete=models.PROTECT)

def __str__(self):
return self.name


class Subject(models.Model):
subject_id = models.CharField(max_length=6)

SEX_CHOICES = [
('MALE', 'Male'),
('FEMALE', 'Female'),
]
VACCINE_CHOICES = [
('FULL', 'Full'),
('PARTIAL', 'Partial'),
('NO', 'None')
]
COVID_CHOICES = [
('Yes', 'Yes'),
('No', 'No')
]
subject_ui = models.CharField(max_length=6, unique=True)
first_name = models.CharField(max_length=100, null=True, blank=True)
last_name = models.CharField(max_length=100, null=True, blank=True)
birthdate = models.DateField(null=True, blank=True)
sex = models.CharField(max_length=10, choices=SEX_CHOICES, blank=True, null=True)
vaccine_status = models.CharField(max_length=10, choices=VACCINE_CHOICES, blank=True, null=True)
covid = models.CharField(max_length=10, choices=COVID_CHOICES, null=True, blank=True, help_text="Has subject been infected with COVID-19 prior to study")
location = models.ForeignKey(Location, on_delete=models.PROTECT)

def __str__(self):
return self.subject_id
return self.subject_ui

class Box(models.Model):
box_id = models.IntegerField()
storage_location = models.CharField(max_length=100)
storage_shelf = models.CharField(max_length=100)

def __str__(self):
return str(self.box_id)


class Project(models.Model):
name = models.CharField(max_length=100, unique=True)
investigator = models.CharField(max_length=100, blank=True, null=True)
start_date = models.DateField(blank=True, null=True)
end_date = models.DateField(blank=True, null=True)
description = models.TextField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)



Expand All @@ -36,21 +76,12 @@ class Sample(models.Model):
project = models.CharField(max_length=100)
collection_event = models.CharField(max_length=100)
collected = models.BooleanField()

def __str__(self):
return self.sample_id


class Location(models.Model):
name = models.CharField(max_length=100, unique=True)
address = models.CharField(max_length=100, blank=True, null=True)
description = models.TextField(blank=True, null=True)
contact_name = models.CharField(max_length=100, blank=True, null=True)
contact_email = models.EmailField(blank=True, null=True)
contact_phone = PhoneField(blank=True, null=True)
project = models.ForeignKey(Project, on_delete=models.PROTECT)

def __str__(self):
return self.name

class Researcher(models.Model):
name = models.CharField(max_length=100, unique=True)
Expand All @@ -61,14 +92,16 @@ def __str__(self):
return self.name

class Event(models.Model):
name = models.CharField(max_length=100, unique=True)
location = models.ForeignKey(Location, on_delete=models.PROTECT)
researcher = models.ForeignKey(Researcher, on_delete=models.PROTECT, blank=True)
researcher = models.ForeignKey(Researcher, on_delete=models.PROTECT, blank=True, null=True)
date = models.DateField()
description = models.TextField(blank=True, null=True)
notes = models.TextField(blank=True, null=True)
def __str__(self):
return self.location, self.date




def __str__(self):
return str(self.name)

4 changes: 2 additions & 2 deletions out_on_a_LIMS/lims/templates/lims/base.html
Expand Up @@ -66,7 +66,7 @@
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<a class="nav-link" href="{% url 'lims:subject_list' %}">
<span data-feather="users"></span>
Subjects
</a>
Expand All @@ -78,7 +78,7 @@
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<a class="nav-link" href="{% url 'lims:event_list' %}">
<span data-feather="calendar"></span>
Events
</a>
Expand Down