diff --git a/ccdb/processing/__init__.py b/ccdb/processing/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ccdb/processing/admin.py b/ccdb/processing/admin.py new file mode 100644 index 0000000..be47cee --- /dev/null +++ b/ccdb/processing/admin.py @@ -0,0 +1,32 @@ +from django.contrib import admin + +from .models import ProcessType, Reagent, Flaw + + +class ProcessTypeAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'description', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'description') + list_per_page = 25 + fields = ('name', 'code', 'description', 'sort_order') + + +class ReagentAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'reagent_class', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'reagent_class') + list_per_page = 25 + fields = ('name', 'code', 'reagent_class', 'sort_order') + + +class FlawAdmin(admin.ModelAdmin): + list_display = ('name', 'description', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'description') + list_per_page = 25 + fields = ('name', 'description') + + +admin.site.register(ProcessType, ProcessTypeAdmin) +admin.site.register(Reagent, ReagentAdmin) +admin.site.register(Flaw, FlawAdmin) diff --git a/ccdb/processing/migrations/0001_initial.py b/ccdb/processing/migrations/0001_initial.py new file mode 100644 index 0000000..d471501 --- /dev/null +++ b/ccdb/processing/migrations/0001_initial.py @@ -0,0 +1,92 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import autoslug.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('misc', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Flaw', + fields=[ + ('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)), + ('name', models.CharField(max_length=200)), + ('description', models.CharField(blank=True, max_length=255)), + ('sort_order', models.IntegerField(blank=True, null=True)), + ('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.CreateModel( + name='Processing', + fields=[ + ('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)), + ('container_label', models.CharField(max_length=50)), + ('process_date', models.DateField(blank=True, null=True)), + ('process_time', models.TimeField(blank=True, null=True)), + ('reagent_volume', models.FloatField(blank=True, null=True)), + ('minutes_in_reagent', models.IntegerField(blank=True, null=True)), + ('container', models.ForeignKey(to='misc.Container')), + ('flaw', models.ForeignKey(to='processing.Flaw', blank=True, null=True)), + ('measurement_unit', models.ForeignKey(to='misc.MeasurementUnit', blank=True, null=True)), + ], + ), + migrations.CreateModel( + name='ProcessType', + fields=[ + ('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)), + ('name', models.CharField(max_length=100)), + ('code', models.CharField(blank=True, max_length=10)), + ('description', models.CharField(blank=True, max_length=255)), + ('sort_order', models.IntegerField(blank=True, null=True)), + ('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.CreateModel( + name='Reagent', + fields=[ + ('id', models.AutoField(primary_key=True, auto_created=True, verbose_name='ID', serialize=False)), + ('name', models.CharField(max_length=100)), + ('code', models.CharField(blank=True, max_length=10)), + ('reagent_class', models.CharField(blank=True, max_length=50)), + ('sort_order', models.IntegerField(blank=True, null=True)), + ('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.AlterUniqueTogether( + name='reagent', + unique_together=set([('name', 'code')]), + ), + migrations.AlterUniqueTogether( + name='processtype', + unique_together=set([('name', 'code')]), + ), + migrations.AddField( + model_name='processing', + name='process_type', + field=models.ForeignKey(to='processing.ProcessType'), + ), + migrations.AddField( + model_name='processing', + name='reagent', + field=models.ForeignKey(to='processing.Reagent', blank=True, null=True), + ), + migrations.AlterUniqueTogether( + name='processing', + unique_together=set([('process_type', 'container', 'container_label', 'process_date', 'process_time', 'reagent')]), + ), + ] diff --git a/ccdb/processing/migrations/__init__.py b/ccdb/processing/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ccdb/processing/models.py b/ccdb/processing/models.py new file mode 100644 index 0000000..639b530 --- /dev/null +++ b/ccdb/processing/models.py @@ -0,0 +1,66 @@ +from django.db import models + +from autoslug import AutoSlugField + + +class ProcessType(models.Model): + name = models.CharField(max_length=100) + code = models.CharField(max_length=10, blank=True) + description = models.CharField(max_length=255, blank=True) + sort_order = models.IntegerField(blank=True, null=True) + slug = AutoSlugField(populate_from='name') + + def __str__(self): + return self.name + + class Meta: + unique_together = ('name', 'code') + ordering = ['sort_order'] + + +class Reagent(models.Model): + name = models.CharField(max_length=100) + code = models.CharField(max_length=10, blank=True) + reagent_class = models.CharField(max_length=50, blank=True) + sort_order = models.IntegerField(blank=True, null=True) + slug = AutoSlugField(populate_from='name') + + def __str__(self): + return self.name + + class Meta: + unique_together = ('name', 'code') + ordering = ['sort_order'] + + +class Flaw(models.Model): + name = models.CharField(max_length=200) + description = models.CharField(max_length=255, blank=True) + sort_order = models.IntegerField(blank=True, null=True) + slug = AutoSlugField(populate_from='name') + + def __str__(self): + return self.name + + class Meta: + ordering = ['sort_order'] + + +class Processing(models.Model): + process_type = models.ForeignKey(ProcessType) + container = models.ForeignKey('misc.Container') + container_label = models.CharField(max_length=50) + process_date = models.DateField(blank=True, null=True) + process_time = models.TimeField(blank=True, null=True) + reagent = models.ForeignKey(Reagent, blank=True, null=True) + reagent_volume = models.FloatField(blank=True, null=True) + measurement_unit = models.ForeignKey('misc.MeasurementUnit', blank=True, null=True) + minutes_in_reagent = models.IntegerField(blank=True, null=True) + flaw = models.ForeignKey(Flaw, blank=True, null=True) + + def __str__(self): + return "{process_date} {process_type} {container_label}".format(**self) + + class Meta: + unique_together = ('process_type', 'container', 'container_label', + 'process_date', 'process_time', 'reagent') diff --git a/ccdb/utils/management/commands/import_data.py b/ccdb/utils/management/commands/import_data.py index 91b9569..fd18865 100644 --- a/ccdb/utils/management/commands/import_data.py +++ b/ccdb/utils/management/commands/import_data.py @@ -13,6 +13,7 @@ from ccdb.misc.models import MeasurementUnit, MeasurementType, Container, \ from ccdb.locations.models import Region, Site, MunicipalLocation, \ StudyLocation, StorageLocation from ccdb.species.models import Species +from ccdb.processing.models import ProcessType, Reagent, Flaw, Processing class Command(BaseCommand): @@ -24,7 +25,7 @@ class Command(BaseCommand): def handle(self, **options): _fetch_data(options['manifest_url'], self.stdout.write) self.stdout.write('Fetched data') - _import_data() + _import_admin_data() self.stdout.write('Imported data') @@ -44,7 +45,7 @@ def _fetch_data(url, write): out_file.write(chunk) -def _import_data(): +def _import_admin_data(): c = setup_sqlite() if c: # Projects @@ -126,7 +127,7 @@ def _import_data(): # Municipal Locations for r in c.execute('SELECT * FROM tbl_lu_municipal_locations;'): - ml = MunicipalLocation(site_id=r[0], id=r[1], name=r[2], code=r[3], + ml = MunicipalLocation(id=r[1], name=r[2], code=r[3], municipal_location_type=r[4], description=r[5], sort_order=r[6]) ml.save() @@ -158,3 +159,15 @@ def _import_data(): s = Species(id=r[0], common_name=r[1], genus=r[2], species=r[3], parasite=r[4], sort_order=r[5]) s.save() + + # Processing Type + for r in c.execute('SELECT * FROM tbl_lu_process_types;'): + pt = ProcessType(id=r[0], name=r[1], code=r[2], description=r[3], + sort_order=r[4]) + pt.save() + + # Reagent + for r in c.execute('SELECT * FROM tbl_lu_reagents;'): + r = Reagent(id=r[0], name=r[1], code=r[2], reagent_class=r[3], + sort_order=r[4]) + r.save() diff --git a/config/settings/base.py b/config/settings/base.py index d1ee8c5..bff0974 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -44,6 +44,7 @@ LOCAL_APPS = ( 'ccdb.locations', 'ccdb.species', 'ccdb.collections_ccdb', + 'ccdb.processing', ) # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps diff --git a/misc/existing.py b/misc/existing.py index 1d9d53b..0ff04df 100644 --- a/misc/existing.py +++ b/misc/existing.py @@ -74,31 +74,6 @@ class TblBioReplicates(models.Model): db_table = 'tbl_Bio_Replicates' -class TblCollections(models.Model): - projectid = models.ForeignKey('TblLuProjects', db_column='ProjectID') # Field name made lowercase. - collectionid = models.AutoField(db_column='CollectionID', primary_key=True) # Field name made lowercase. - study_locationid = models.ForeignKey('TblLuStudyLocations', db_column='Study_LocationID') # Field name made lowercase. - collection_typeid = models.ForeignKey('TblLuCollectionTypes', db_column='Collection_TypeID') # Field name made lowercase. - collection_methodid = models.ForeignKey('TblLuCollectionMethods', db_column='Collection_MethodID') # Field name made lowercase. - number_of_traps = models.IntegerField(db_column='Number_Of_Traps', blank=True, null=True) # Field name made lowercase. - collection_start_date = models.DateField(db_column='Collection_Start_Date', blank=True, null=True) # Field name made lowercase. - collection_start_time = models.TimeField(db_column='Collection_Start_Time', blank=True, null=True) # Field name made lowercase. - collection_end_date = models.DateField(db_column='Collection_End_Date', blank=True, null=True) # Field name made lowercase. - collection_end_time = models.TimeField(db_column='Collection_End_Time', blank=True, null=True) # Field name made lowercase. - storage_locationid = models.ForeignKey('TblLuStorageLocations', db_column='Storage_LocationID', blank=True, null=True) # Field name made lowercase. - specimen_state = models.CharField(db_column='Specimen_State', max_length=50, blank=True, null=True) # Field name made lowercase. - process_typeid = models.ForeignKey('TblLuProcessTypes', db_column='Process_TypeID', blank=True, null=True) # Field name made lowercase. - reagentid = models.ForeignKey('TblLuReagents', db_column='ReagentID', blank=True, null=True) # Field name made lowercase. - adfg_permit = models.CharField(db_column='ADFG_Permit', max_length=25, blank=True, null=True) # Field name made lowercase. - link_to_datasheets = models.CharField(db_column='Link_To_Datasheets', max_length=255, blank=True, null=True) # Field name made lowercase. - flawid = models.ForeignKey('TblLuRecordFlaws', db_column='FlawID', blank=True, null=True) # Field name made lowercase. - - class Meta: - managed = False - db_table = 'tbl_Collections' - unique_together = (('ProjectID', 'Study_LocationID', 'Collection_TypeID', 'Collection_Start_Date', 'Collection_End_Date', 'Collection_MethodID'),) - - class TblComments(models.Model): record_typeid = models.ForeignKey('TblLuRecordTypes', db_column='Record_TypeID') # Field name made lowercase. foreign_key = models.AutoField(db_column='Foreign_Key') # Field name made lowercase. @@ -399,45 +374,6 @@ class TblLuPeople(models.Model): unique_together = (('First_Name', 'Middle_Initial', 'Last_Name'),) -class TblLuProcessTypes(models.Model): - process_typeid = models.AutoField(db_column='Process_TypeID', primary_key=True) # Field name made lowercase. - process_type = models.CharField(db_column='Process_Type', max_length=100) # Field name made lowercase. - process_type_code = models.CharField(db_column='Process_Type_Code', max_length=10, blank=True, null=True) # Field name made lowercase. - ptype_short_description = models.CharField(db_column='PType_Short_Description', max_length=255, blank=True, null=True) # Field name made lowercase. - sort_order = models.IntegerField(db_column='Sort_Order', blank=True, null=True) # Field name made lowercase. - - class Meta: - managed = False - db_table = 'tbl_LU_Process_Types' - unique_together = (('Process_Type', 'Process_Type_Code'),) - - -class TblLuReagents(models.Model): - reagentid = models.AutoField(db_column='ReagentID', primary_key=True) # Field name made lowercase. - reagent = models.CharField(db_column='Reagent', max_length=100) # Field name made lowercase. - reagent_code = models.CharField(db_column='Reagent_Code', max_length=10, blank=True, null=True) # Field name made lowercase. - reagent_class = models.CharField(db_column='Reagent_Class', max_length=50, blank=True, null=True) # Field name made lowercase. - sort_order = models.IntegerField(db_column='Sort_Order', blank=True, null=True) # Field name made lowercase. - - class Meta: - managed = False - db_table = 'tbl_LU_Reagents' - unique_together = (('Reagent', 'Reagent_Code'),) - - -class TblLuRecordFlaws(models.Model): - flawid = models.AutoField(db_column='FlawID', primary_key=True) # Field name made lowercase. - record_typeid = models.ForeignKey('TblLuRecordTypes', db_column='Record_TypeID') # Field name made lowercase. - flaw = models.CharField(db_column='Flaw', max_length=200) # Field name made lowercase. - flaw_short_description = models.CharField(db_column='Flaw_Short_Description', max_length=255, blank=True, null=True) # Field name made lowercase. - sort_order = models.IntegerField(db_column='Sort_Order', blank=True, null=True) # Field name made lowercase. - - class Meta: - managed = False - db_table = 'tbl_LU_Record_Flaws' - unique_together = (('Record_TypeID', 'Flaw'),) - - class TblLuRecordTypes(models.Model): record_typeid = models.AutoField(db_column='Record_TypeID', primary_key=True) # Field name made lowercase. record_type = models.CharField(db_column='Record_Type', unique=True, max_length=50) # Field name made lowercase. @@ -492,25 +428,6 @@ class TblLuUsers(models.Model): db_table = 'tbl_LU_Users' -class TblProcessing(models.Model): - processid = models.AutoField(db_column='ProcessID', primary_key=True) # Field name made lowercase. - process_typeid = models.ForeignKey(TblLuProcessTypes, db_column='Process_TypeID') # Field name made lowercase. - containerid = models.ForeignKey(TblLuContainers, db_column='ContainerID') # Field name made lowercase. - container_label = models.CharField(db_column='Container_Label', max_length=50) # Field name made lowercase. - process_date = models.DateField(db_column='Process_Date', blank=True, null=True) # Field name made lowercase. - process_time = models.TimeField(db_column='Process_Time', blank=True, null=True) # Field name made lowercase. - reagentid = models.ForeignKey(TblLuReagents, db_column='ReagentID', blank=True, null=True) # Field name made lowercase. - reagent_volume = models.FloatField(db_column='Reagent_Volume', blank=True, null=True) # Field name made lowercase. - measurement_unitid = models.ForeignKey(TblLuMeasurementUnits, db_column='Measurement_UnitID', blank=True, null=True) # Field name made lowercase. - time_in_reagent = models.CharField(db_column='Time_in_Reagent', max_length=10, blank=True, null=True) # Field name made lowercase. - flawid = models.ForeignKey(TblLuRecordFlaws, db_column='FlawID', blank=True, null=True) # Field name made lowercase. - - class Meta: - managed = False - db_table = 'tbl_Processing' - unique_together = (('Process_TypeID', 'ContainerID', 'Container_Label', 'Process_Date', 'Process_Time', 'ReagentID'),) - - class TblSamples(models.Model): trrepid = models.ForeignKey('TblTreatmentReplicates', db_column='TrRepID') # Field name made lowercase. sampleid = models.AutoField(db_column='SampleID', primary_key=True) # Field name made lowercase.