From 8552e5f12c6d4362b48b571adfa990f21bf229d6 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 20 Jan 2016 11:35:48 -0700 Subject: [PATCH] Initial projects --- .gitignore | 1 + ccdb/projects/__init__.py | 0 ccdb/projects/admin.py | 6 +++ .../migrations/0001_initial_project.py | 33 ++++++++++++++++ ccdb/projects/migrations/0002_project_data.py | 38 +++++++++++++++++++ ccdb/projects/migrations/__init__.py | 0 ccdb/projects/models.py | 21 ++++++++++ config/settings/base.py | 1 + misc/existing.py | 24 ++++++------ 9 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 ccdb/projects/__init__.py create mode 100644 ccdb/projects/admin.py create mode 100644 ccdb/projects/migrations/0001_initial_project.py create mode 100644 ccdb/projects/migrations/0002_project_data.py create mode 100644 ccdb/projects/migrations/__init__.py create mode 100644 ccdb/projects/models.py diff --git a/.gitignore b/.gitignore index 0a49a9f..c43b556 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ venv staticfiles +data *.py[cod] *.pyc __pycache__ diff --git a/ccdb/projects/__init__.py b/ccdb/projects/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ccdb/projects/admin.py b/ccdb/projects/admin.py new file mode 100644 index 0000000..1da31ce --- /dev/null +++ b/ccdb/projects/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin + +from .models import Project + + +admin.site.register(Project) diff --git a/ccdb/projects/migrations/0001_initial_project.py b/ccdb/projects/migrations/0001_initial_project.py new file mode 100644 index 0000000..d2d460f --- /dev/null +++ b/ccdb/projects/migrations/0001_initial_project.py @@ -0,0 +1,33 @@ +# -*- 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='Project', + fields=[ + ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ('code', models.CharField(max_length=10, blank=True)), + ('iacuc_number', models.CharField(max_length=25, blank=True)), + ('description', models.CharField(max_length=255, blank=True)), + ('sort_order', models.IntegerField(null=True, blank=True)), + ('slug', autoslug.fields.AutoSlugField(populate_from='name', editable=False)), + ], + options={ + 'ordering': ['sort_order'], + }, + ), + migrations.AlterUniqueTogether( + name='project', + unique_together=set([('name', 'code')]), + ), + ] diff --git a/ccdb/projects/migrations/0002_project_data.py b/ccdb/projects/migrations/0002_project_data.py new file mode 100644 index 0000000..a0ba64e --- /dev/null +++ b/ccdb/projects/migrations/0002_project_data.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +import csv +import os + +from django.db import migrations, models + + +def import_projects(apps, schema_editor): + Project = apps.get_model('projects', 'Project') + filename = 'data/tbl_LU_Projects.csv' + if os.path.exists(filename): + with open(filename) as f: + fieldnames = ['id', 'name', 'code', 'iacuc_number', + 'description', 'sort_order'] + reader = csv.DictReader(f, fieldnames=fieldnames) + for r in reader: + r['sort_order'] = int(float(r['sort_order'])) + p = Project(**r) + p.save() + + +def remove_projects(apps, schema_editor): + print("removing projects...") + Project = apps.get_model("projects", "Project") + Project.objects.all().delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('projects', '0001_initial_project'), + ] + + operations = [ + migrations.RunPython(import_projects, remove_projects), + ] diff --git a/ccdb/projects/migrations/__init__.py b/ccdb/projects/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ccdb/projects/models.py b/ccdb/projects/models.py new file mode 100644 index 0000000..c73a599 --- /dev/null +++ b/ccdb/projects/models.py @@ -0,0 +1,21 @@ +from django.db import models +from django.utils.translation import ugettext_lazy as _ +from django.core.urlresolvers import reverse + +from autoslug import AutoSlugField + + +class Project(models.Model): + name = models.CharField(max_length=100) + code = models.CharField(max_length=10, blank=True) + iacuc_number = models.CharField(max_length=25, 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'] diff --git a/config/settings/base.py b/config/settings/base.py index c99b2a8..2cb1444 100644 --- a/config/settings/base.py +++ b/config/settings/base.py @@ -38,6 +38,7 @@ THIRD_PARTY_APPS = ( # Apps specific for this project go here. LOCAL_APPS = ( 'ccdb.users', # custom users app + 'ccdb.projects', ) # See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps diff --git a/misc/existing.py b/misc/existing.py index 95e4fe8..06f7d18 100644 --- a/misc/existing.py +++ b/misc/existing.py @@ -536,18 +536,18 @@ 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 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):