From b78d7882d510b3ac760982aec81a81958cd30a39 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 28 Jan 2016 15:15:06 -0700 Subject: [PATCH] Beef up admin representation --- ccdb/locations/admin.py | 63 +++++++++++++++++-- ccdb/misc/admin.py | 56 +++++++++++++++-- ccdb/misc/models.py | 2 +- ccdb/projects/admin.py | 27 ++++++-- .../migrations/0004_initial_grantreport.py | 4 ++ ccdb/projects/models.py | 1 + ccdb/utils/management/commands/import_data.py | 7 ++- 7 files changed, 144 insertions(+), 16 deletions(-) diff --git a/ccdb/locations/admin.py b/ccdb/locations/admin.py index 3a43cc8..bed516b 100644 --- a/ccdb/locations/admin.py +++ b/ccdb/locations/admin.py @@ -4,8 +4,61 @@ from .models import Region, Site, MunicipalLocation, \ StudyLocation, StorageLocation -admin.site.register(Region) -admin.site.register(Site) -admin.site.register(MunicipalLocation) -admin.site.register(StudyLocation) -admin.site.register(StorageLocation) +class RegionAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code') + list_per_page = 25 + fields = ('name', 'code', 'sort_order') + + +class SiteAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'region', 'description', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'region', 'description') + list_per_page = 25 + fields = ('name', 'code', 'region', 'description', 'sort_order') + + +class MunicipalLocationAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'site', 'municipal_location_type', + 'description', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'site', 'municipal_location_type', + 'description') + list_per_page = 25 + fields = ('name', 'code', 'site', 'municipal_location_type', + 'description', 'sort_order') + + +class StudyLocationAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'site', 'study_location_type', + 'treatment_type', 'municipal_location', 'collecting_location', + 'description', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'site', 'study_location_type', + 'treatment_type', 'municipal_location', 'collecting_location', + 'description') + list_per_page = 25 + fields = ('name', 'code', 'site', 'study_location_type', + 'treatment_type', 'municipal_location', 'collecting_location', + 'description', 'sort_order') + + +class StorageLocationAdmin(admin.ModelAdmin): + list_display = ('__str__', 'facility', 'building', 'room', 'freezer', 'temp_c', + 'description', 'sort_order') + list_display_links = ('__str__',) + search_fields = ('__str__', 'facility', 'building', 'room', 'freezer', 'temp_c', + 'description') + list_per_page = 25 + fields = ('facility', 'building', 'room', 'freezer', 'temp_c', + 'description', 'sort_order') + + + +admin.site.register(Region, RegionAdmin) +admin.site.register(Site, SiteAdmin) +admin.site.register(MunicipalLocation, MunicipalLocationAdmin) +admin.site.register(StudyLocation, StudyLocationAdmin) +admin.site.register(StorageLocation, StorageLocationAdmin) diff --git a/ccdb/misc/admin.py b/ccdb/misc/admin.py index b0d8c53..586bf54 100644 --- a/ccdb/misc/admin.py +++ b/ccdb/misc/admin.py @@ -2,8 +2,54 @@ 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) + +class MeasurementUnitAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'unit_class', 'description', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'unit_class', 'description') + list_per_page = 25 + fields = ('name', 'code', 'unit_class', 'description', 'sort_order') + + +class MeasurementTypeAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'measurement_type_class', 'description', + 'default_measurement_unit', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'measurement_type_class', 'description') + list_per_page = 25 + fields = ('name', 'code', 'measurement_type_class', 'description', + 'default_measurement_unit', 'sort_order') + + +class ContainerAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'application', 'color', 'material', + 'volume', 'measurement_unit', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'application', 'color', 'material', + 'volume', 'measurement_unit') + list_per_page = 25 + fields = ('name', 'code', 'application', 'color', 'material', + 'volume', 'measurement_unit', 'sort_order') + + +class MaterialAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'material_class', 'description', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'material_class', 'description') + list_per_page = 25 + fields = ('name', 'code', 'material_class', 'description', 'sort_order') + + +class ColorAdmin(admin.ModelAdmin): + list_display = ('name', 'code', 'color_number', 'sort_order') + list_display_links = ('name',) + search_fields = ('name', 'code', 'color_number') + list_per_page = 25 + fields = ('name', 'code', 'color_number', 'sort_order') + + +admin.site.register(MeasurementUnit, MeasurementUnitAdmin) +admin.site.register(MeasurementType, MeasurementTypeAdmin) +admin.site.register(Container, ContainerAdmin) +admin.site.register(Material, MaterialAdmin) +admin.site.register(Color, ColorAdmin) diff --git a/ccdb/misc/models.py b/ccdb/misc/models.py index 2213eef..90bc941 100644 --- a/ccdb/misc/models.py +++ b/ccdb/misc/models.py @@ -12,7 +12,7 @@ class MeasurementUnit(models.Model): slug = AutoSlugField(populate_from='name') def __str__(self): - return self.name + return self.code class Meta: unique_together = ('name', 'code') diff --git a/ccdb/projects/admin.py b/ccdb/projects/admin.py index c9f8232..dca2c37 100644 --- a/ccdb/projects/admin.py +++ b/ccdb/projects/admin.py @@ -9,8 +9,8 @@ class ProjectGrantInline(admin.TabularInline): class ProjectAdmin(admin.ModelAdmin): - list_display = ('id', 'name', 'code', 'iacuc_number', 'description', 'sort_order') - list_display_links = ('id', 'name') + list_display = ('name', 'code', 'iacuc_number', 'description', 'sort_order') + list_display_links = ('name',) search_fields = ('name', 'code', 'iacuc_number', 'description') list_per_page = 25 fields = ('name', 'code', 'iacuc_number', 'description', 'sort_order') @@ -18,6 +18,25 @@ class ProjectAdmin(admin.ModelAdmin): inlines = [ProjectGrantInline] +class GrantAdmin(admin.ModelAdmin): + list_display = ('title', 'code', 'description', 'sort_order') + list_display_links = ('title',) + search_fields = ('title', 'code', 'description', 'description') + list_per_page = 25 + fields = ('title', 'code', 'description', 'projects', 'sort_order') + + +class GrantReportAdmin(admin.ModelAdmin): + list_display = ('title', 'report_type', 'description', 'due_date', + 'submitted_date', 'attachment', 'sort_order') + list_display_links = ('title',) + search_fields = ('title', 'report_type', 'description', 'due_date', + 'submitted_date', 'attachment') + list_per_page = 25 + fields = ('title', 'report_type', 'description', 'due_date', + 'submitted_date', 'attachment', 'sort_order') + + admin.site.register(Project, ProjectAdmin) -admin.site.register(Grant) -admin.site.register(GrantReport) +admin.site.register(Grant, GrantAdmin) +admin.site.register(GrantReport, GrantReportAdmin) diff --git a/ccdb/projects/migrations/0004_initial_grantreport.py b/ccdb/projects/migrations/0004_initial_grantreport.py index d7c7a39..3d81a33 100644 --- a/ccdb/projects/migrations/0004_initial_grantreport.py +++ b/ccdb/projects/migrations/0004_initial_grantreport.py @@ -28,4 +28,8 @@ class Migration(migrations.Migration): 'ordering': ['sort_order'], }, ), + migrations.AlterUniqueTogether( + name='grantreport', + unique_together=set([('grant', 'title', 'due_date')]), + ), ] diff --git a/ccdb/projects/models.py b/ccdb/projects/models.py index 6c61325..08290a8 100644 --- a/ccdb/projects/models.py +++ b/ccdb/projects/models.py @@ -50,4 +50,5 @@ class GrantReport(models.Model): return self.title class Meta: + unique_together = ('grant', 'title', 'due_date',) ordering = ['sort_order'] diff --git a/ccdb/utils/management/commands/import_data.py b/ccdb/utils/management/commands/import_data.py index 32fd870..99d4f51 100644 --- a/ccdb/utils/management/commands/import_data.py +++ b/ccdb/utils/management/commands/import_data.py @@ -2,6 +2,7 @@ import os import shutil from django.core.management.base import BaseCommand +from django.db import IntegrityError import requests @@ -70,10 +71,14 @@ def _import_data(): FROM tbl_lu_grant_reports; ''' for r in c.execute(q): + # No PK field in Andre's file 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() + try: + gr.save() + except IntegrityError: + pass # Measurement Units for r in c.execute('SELECT * FROM tbl_lu_measurement_units;'):