diff --git a/ccdb/misc/__init__.py b/ccdb/misc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ccdb/misc/admin.py b/ccdb/misc/admin.py new file mode 100644 index 0000000..b0d8c53 --- /dev/null +++ b/ccdb/misc/admin.py @@ -0,0 +1,9 @@ +from django.contrib import admin + +from .models import MeasurementUnit, MeasurementType, Container, Material, Color + +admin.site.register(MeasurementUnit) +admin.site.register(MeasurementType) +admin.site.register(Container) +admin.site.register(Material) +admin.site.register(Color) diff --git a/ccdb/misc/migrations/0001_initial.py b/ccdb/misc/migrations/0001_initial.py new file mode 100644 index 0000000..0c78d8d --- /dev/null +++ b/ccdb/misc/migrations/0001_initial.py @@ -0,0 +1,116 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import autoslug.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Color', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')), + ('name', models.CharField(max_length=50)), + ('code', models.CharField(blank=True, max_length=10)), + ('color_number', models.FloatField(null=True, blank=True)), + ('sort_order', models.IntegerField(null=True, blank=True)), + ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name')), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.CreateModel( + name='Container', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('code', models.CharField(blank=True, max_length=10)), + ('application', models.CharField(blank=True, max_length=50)), + ('volume', models.FloatField(null=True, blank=True)), + ('sort_order', models.IntegerField(null=True, blank=True)), + ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name')), + ('color', models.ForeignKey(null=True, to='misc.Color', blank=True)), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.CreateModel( + name='Material', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('code', models.CharField(blank=True, max_length=10)), + ('material_class', models.CharField(blank=True, max_length=50)), + ('description', models.CharField(blank=True, max_length=255)), + ('sort_order', models.IntegerField(null=True, blank=True)), + ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name')), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.CreateModel( + name='MeasurementType', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('code', models.CharField(blank=True, max_length=10)), + ('measurement_type_class', models.CharField(blank=True, max_length=50)), + ('description', models.CharField(blank=True, max_length=255)), + ('sort_order', models.IntegerField(null=True, blank=True)), + ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name')), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.CreateModel( + name='MeasurementUnit', + fields=[ + ('id', models.AutoField(primary_key=True, serialize=False, auto_created=True, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('code', models.CharField(max_length=25)), + ('unit_class', models.CharField(blank=True, max_length=50)), + ('description', models.CharField(blank=True, max_length=255)), + ('sort_order', models.IntegerField(null=True, blank=True)), + ('slug', autoslug.fields.AutoSlugField(editable=False, populate_from='name')), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.AlterUniqueTogether( + name='measurementunit', + unique_together=set([('name', 'code')]), + ), + migrations.AddField( + model_name='measurementtype', + name='default_measurement_unit', + field=models.ForeignKey(null=True, to='misc.MeasurementUnit', blank=True), + ), + migrations.AlterUniqueTogether( + name='material', + unique_together=set([('name', 'code')]), + ), + migrations.AddField( + model_name='container', + name='material', + field=models.ForeignKey(null=True, to='misc.Material', blank=True), + ), + migrations.AddField( + model_name='container', + name='measurement_unit', + field=models.ForeignKey(null=True, to='misc.MeasurementUnit', blank=True), + ), + migrations.AlterUniqueTogether( + name='color', + unique_together=set([('name', 'code', 'color_number')]), + ), + ] diff --git a/ccdb/misc/migrations/__init__.py b/ccdb/misc/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ccdb/misc/models.py b/ccdb/misc/models.py new file mode 100644 index 0000000..2213eef --- /dev/null +++ b/ccdb/misc/models.py @@ -0,0 +1,84 @@ +from django.db import models + +from autoslug import AutoSlugField + + +class MeasurementUnit(models.Model): + name = models.CharField(max_length=100) + code = models.CharField(max_length=25) + unit_class = models.CharField(max_length=50, 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 MeasurementType(models.Model): + name = models.CharField(max_length=100) + code = models.CharField(max_length=10, blank=True) + measurement_type_class = models.CharField(max_length=50, blank=True) + description = models.CharField(max_length=255, blank=True) + default_measurement_unit = models.ForeignKey('MeasurementUnit', blank=True, null=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 Material(models.Model): + name = models.CharField(max_length=100) + code = models.CharField(max_length=10, blank=True) + material_class = models.CharField(max_length=50, 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 Color(models.Model): + name = models.CharField(max_length=50) + code = models.CharField(max_length=10, blank=True) + color_number = models.FloatField(blank=True, null=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', 'color_number') + ordering = ['sort_order'] + + +class Container(models.Model): + name = models.CharField(max_length=100) + code = models.CharField(max_length=10, blank=True) + application = models.CharField(max_length=50, blank=True) + color = models.ForeignKey(Color, blank=True, null=True) + material = models.ForeignKey(Material, blank=True, null=True) + volume = models.FloatField(blank=True, null=True) + measurement_unit = models.ForeignKey(MeasurementUnit, blank=True, null=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'] diff --git a/ccdb/projects/models.py b/ccdb/projects/models.py index 6ff3bb1..6c61325 100644 --- a/ccdb/projects/models.py +++ b/ccdb/projects/models.py @@ -1,6 +1,4 @@ from django.db import models -from django.utils.translation import ugettext_lazy as _ -from django.core.urlresolvers import reverse from autoslug import AutoSlugField diff --git a/ccdb/utils/management/commands/import_data.py b/ccdb/utils/management/commands/import_data.py index 047c883..e06c905 100644 --- a/ccdb/utils/management/commands/import_data.py +++ b/ccdb/utils/management/commands/import_data.py @@ -7,6 +7,8 @@ import requests from ccdb.utils.data_import import setup_sqlite from ccdb.projects.models import Project, Grant, GrantReport +from ccdb.misc.models import MeasurementUnit, MeasurementType, Container, \ + Material, Color class Command(BaseCommand): @@ -66,8 +68,39 @@ def _import_data(): FROM tbl_lu_grant_reports; ''' for r in c.execute(q): - g = Grant.objects.get(id=r[0]) - gr = GrantReport(grant=g, title=r[1], report_type=r[2], + gr = GrantReport(grant_id=r[0], title=r[1], report_type=r[2], description=r[3], due_date=r[8], submitted_date=r[5], attachment=r[6], sort_order=r[7]) gr.save() + + # Measurement Units + for r in c.execute('SELECT * FROM tbl_lu_measurement_units;'): + mu = MeasurementUnit(id=r[0], name=r[1], code=r[2], + unit_class=r[3], description=r[4], sort_order=r[5]) + mu.save() + + # Measurement Types + for r in c.execute('SELECT * FROM tbl_lu_measurement_types;'): + mt = MeasurementType(id=r[0], name=r[1], code=r[2], + measurement_type_class=r[3], description=r[4], + default_measurement_unit_id=r[5], sort_order=r[6]) + mt.save() + + # Materials + for r in c.execute('SELECT * FROM tbl_lu_materials;'): + m = Material(id=r[0], name=r[1], code=r[2], material_class=r[3], + description=r[4], sort_order=r[5]) + m.save() + + # Colors + for r in c.execute('SELECT * FROM tbl_lu_colors;'): + cl = Color(id=r[0], name=r[1], code=r[2], + color_number=r[3], sort_order=r[4]) + cl.save() + + # Containers + for r in c.execute('SELECT * FROM tbl_lu_containers;'): + cl = Container(id=r[0], name=r[1], code=r[2], application=r[3], + color_id=r[4], material_id=r[5], volume=r[6], + measurement_unit_id=r[7], sort_order=r[8]) + cl.save() diff --git a/config/settings/base.py b/config/settings/base.py index 4572943..4d45f68 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -40,6 +40,7 @@ LOCAL_APPS = ( 'ccdb.utils', 'ccdb.users', # custom users app 'ccdb.projects', + 'ccdb.misc', ) # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps diff --git a/misc/existing.py b/misc/existing.py index 716039b..35da399 100644 --- a/misc/existing.py +++ b/misc/existing.py @@ -267,16 +267,6 @@ class TblHashPeopleSets(models.Model): db_table = 'tbl_HASH_People_Sets' -# class TblHashProjectGrants(models.Model): -# projectid = models.ForeignKey('TblLuProjects', db_column='ProjectID') # Field name made lowercase. -# grantid = models.ForeignKey('TblLuGrants', db_column='GrantID') # Field name made lowercase. -# -# class Meta: -# managed = False -# db_table = 'tbl_HASH_Project_Grants' -# unique_together = (('ProjectID', 'GrantID'),) - - class TblHashTrapSpecies(models.Model): trapspeciesid = models.AutoField(db_column='TrapSpeciesID', primary_key=True) # Field name made lowercase. colltrapid = models.ForeignKey(TblHashCollectionTraps, db_column='CollTrapID') # Field name made lowercase. @@ -353,19 +343,6 @@ class TblLuCollectionTypes(models.Model): unique_together = (('Collection_Type', 'Collection_Type_Code'),) -class TblLuColors(models.Model): - colorid = models.AutoField(db_column='ColorID', primary_key=True) # Field name made lowercase. - color = models.CharField(db_column='Color', max_length=50) # Field name made lowercase. - color_code = models.CharField(db_column='Color_Code', max_length=10, blank=True, null=True) # Field name made lowercase. - msaccess_clr_nbr = models.FloatField(db_column='MSAccess_Clr_Nbr', 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_Colors' - unique_together = (('Color', 'Color_Code', 'MSAccess_Clr_Nbr'),) - - class TblLuCommentTypes(models.Model): comment_typeid = models.AutoField(db_column='Comment_TypeID', primary_key=True) # Field name made lowercase. comment_type = models.CharField(db_column='Comment_Type', max_length=100) # Field name made lowercase. @@ -378,22 +355,6 @@ class TblLuCommentTypes(models.Model): unique_together = (('Comment_Type', 'Comment_Type_Code'),) -class TblLuContainers(models.Model): - containerid = models.AutoField(db_column='ContainerID', primary_key=True) # Field name made lowercase. - container_type = models.CharField(db_column='Container_Type', max_length=100) # Field name made lowercase. - container_type_code = models.CharField(db_column='Container_Type_Code', max_length=10, blank=True, null=True) # Field name made lowercase. - container_type_application = models.CharField(db_column='Container_Type_Application', max_length=50, blank=True, null=True) # Field name made lowercase. - colorid = models.ForeignKey(TblLuColors, db_column='ColorID', blank=True, null=True) # Field name made lowercase. - materialid = models.ForeignKey('TblLuMaterials', db_column='MaterialID', blank=True, null=True) # Field name made lowercase. - volume = models.FloatField(db_column='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. - sort_order = models.IntegerField(db_column='Sort_Order', blank=True, null=True) # Field name made lowercase. - - class Meta: - managed = False - db_table = 'tbl_LU_Containers' - - class TblLuExperiments(models.Model): experimentid = models.AutoField(db_column='ExperimentID', primary_key=True) # Field name made lowercase. experiment_name = models.CharField(db_column='Experiment_Name', max_length=150) # Field name made lowercase. @@ -409,77 +370,6 @@ class TblLuExperiments(models.Model): unique_together = (('Experiment_Name', 'Experiment_Code'),) -# class TblLuGrantReports(models.Model): -# grantreportid = models.AutoField(db_column='GrantReportID', primary_key=True) # Field name made lowercase. -# grantid = models.ForeignKey('TblLuGrants', db_column='GrantID') # Field name made lowercase. -# report_title = models.CharField(db_column='Report_Title', max_length=200) # Field name made lowercase. -# report_type = models.CharField(db_column='Report_Type', max_length=50, blank=True, null=True) # Field name made lowercase. -# report_short_description = models.CharField(db_column='Report_Short_Description', max_length=255, blank=True, null=True) # Field name made lowercase. -# report_due_date = models.DateField(db_column='Report_Due_Date', blank=True, null=True) # Field name made lowercase. -# report_submitted_date = models.DateField(db_column='Report_Submitted_Date', blank=True, null=True) # Field name made lowercase. -# link_to_report = models.CharField(db_column='Link_To_Report', 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_Grant_Reports' - - -# class TblLuGrants(models.Model): -# grantid = models.AutoField(db_column='GrantID', primary_key=True) # Field name made lowercase. -# grant_title = models.CharField(db_column='Grant_Title', max_length=200) # Field name made lowercase. -# grant_code = models.CharField(db_column='Grant_Code', max_length=10, blank=True, null=True) # Field name made lowercase. -# grant_short_description = models.CharField(db_column='Grant_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_Grants' -# unique_together = (('Grant_Title', 'Grant_Code'),) - - -class TblLuMaterials(models.Model): - materialid = models.AutoField(db_column='MaterialID', primary_key=True) # Field name made lowercase. - material = models.CharField(db_column='Material', max_length=100) # Field name made lowercase. - material_code = models.CharField(db_column='Material_Code', max_length=10, blank=True, null=True) # Field name made lowercase. - material_class = models.CharField(db_column='Material_Class', max_length=50, blank=True, null=True) # Field name made lowercase. - material_short_description = models.CharField(db_column='Material_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_Materials' - unique_together = (('Material', 'Material_Code'),) - - -class TblLuMeasurementTypes(models.Model): - measurement_typeid = models.AutoField(db_column='Measurement_TypeID', primary_key=True) # Field name made lowercase. - measurement_type = models.CharField(db_column='Measurement_Type', max_length=100) # Field name made lowercase. - measurement_type_code = models.CharField(db_column='Measurement_Type_Code', max_length=10, blank=True, null=True) # Field name made lowercase. - measurement_type_class = models.CharField(db_column='Measurement_Type_Class', max_length=50, blank=True, null=True) # Field name made lowercase. - mtype_short_description = models.CharField(db_column='MType_Short_Description', max_length=255, blank=True, null=True) # Field name made lowercase. - default_measurement_unitid = models.ForeignKey('TblLuMeasurementUnits', db_column='Default_Measurement_UnitID', 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_Measurement_Types' - - -class TblLuMeasurementUnits(models.Model): - measurement_unitid = models.AutoField(db_column='Measurement_UnitID', primary_key=True) # Field name made lowercase. - measurement_unit = models.CharField(db_column='Measurement_Unit', max_length=100) # Field name made lowercase. - measurement_unit_code = models.CharField(db_column='Measurement_Unit_Code', max_length=25) # Field name made lowercase. - measurement_unit_class = models.CharField(db_column='Measurement_Unit_Class', max_length=50, blank=True, null=True) # Field name made lowercase. - munit_short_description = models.CharField(db_column='MUnit_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_Measurement_Units' - unique_together = (('Measurement_Unit', 'Measurement_Unit_Code'),) - - class TblLuMunicipalLocations(models.Model): municipal_locationid = models.AutoField(db_column='Municipal_LocationID', primary_key=True) # Field name made lowercase. siteid = models.ForeignKey('TblLuSites', db_column='SiteID') # Field name made lowercase. @@ -536,20 +426,6 @@ class TblLuProcessTypes(models.Model): unique_together = (('Process_Type', 'Process_Type_Code'),) -# class TblLuProjects(models.Model): -# projectid = models.AutoField(db_column='ProjectID', primary_key=True) # Field name made lowercase. -# project = models.CharField(db_column='Project', max_length=100) # Field name made lowercase. -# project_code = models.CharField(db_column='Project_Code', max_length=10, blank=True, null=True) # Field name made lowercase. -# iacuc_number = models.CharField(db_column='IACUC_Number', max_length=25, blank=True, null=True) # Field name made lowercase. -# project_short_description = models.CharField(db_column='Project_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_Projects' -# unique_together = (('Project', 'Project_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.