Grant Reports

This commit is contained in:
Matthew Dillon 2016-01-20 13:26:40 -07:00
parent 52a38951a3
commit 9161fa34ea
6 changed files with 110 additions and 15 deletions

1
.gitignore vendored
View file

@ -1,6 +1,7 @@
venv venv
staticfiles staticfiles
data data
media
*.py[cod] *.py[cod]
*.pyc *.pyc
__pycache__ __pycache__

View file

@ -1,7 +1,8 @@
from django.contrib import admin from django.contrib import admin
from .models import Project, Grant from .models import Project, Grant, GrantReport
admin.site.register(Project) admin.site.register(Project)
admin.site.register(Grant) admin.site.register(Grant)
admin.site.register(GrantReport)

View file

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('projects', '0006_project_grant_data'),
]
operations = [
migrations.CreateModel(
name='GrantReport',
fields=[
('id', models.AutoField(auto_created=True, verbose_name='ID', primary_key=True, serialize=False)),
('title', models.CharField(max_length=200)),
('report_type', models.CharField(max_length=50, blank=True)),
('description', models.CharField(max_length=255, blank=True)),
('due_date', models.DateField(blank=True, null=True)),
('submitted_date', models.DateField(blank=True, null=True)),
('attachment', models.FileField(upload_to='projects/grants/grant_report_attachments/%Y/%m/%d', blank=True, null=True)),
('sort_order', models.IntegerField(blank=True, null=True)),
('grant', models.ForeignKey(to='projects.Grant')),
],
options={
'ordering': ['sort_order'],
},
),
]

View file

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import csv
import os
from datetime import datetime
from django.db import migrations, models
def import_grantreport(apps, schema_editor):
GrantReport = apps.get_model('projects', 'GrantReport')
Grant = apps.get_model('projects', 'Grant')
filename = 'data/tbl_LU_Grant_Reports.csv'
if os.path.exists(filename):
with open(filename) as f:
fieldnames = ['id', 'grant_id', 'title', 'report_type', 'description',
'due_date', 'submitted_date', 'attachment', 'sort_order']
reader = csv.DictReader(f, fieldnames=fieldnames)
for r in reader:
r['sort_order'] = None
r['due_date'] = datetime.strptime(' '.join(r['due_date'].split(' AKDT ')), '%a %b %d %H:%M:%S %Y')
r['submitted_date'] = None
grant_id = r.pop('grant_id')
g = Grant.objects.get(id=grant_id)
gr = GrantReport(grant=g, **r)
gr.save()
def remove_grantreport(apps, schema_editor):
GrantReport = apps.get_model('projects', 'GrantReport')
GrantReport.objects.all().delete()
class Migration(migrations.Migration):
dependencies = [
('projects', '0007_initial_grantreport'),
]
operations = [
migrations.RunPython(import_grantreport, remove_grantreport),
]

View file

@ -34,3 +34,22 @@ class Grant(models.Model):
class Meta: class Meta:
unique_together = ('title', 'code',) unique_together = ('title', 'code',)
ordering = ['sort_order'] ordering = ['sort_order']
class GrantReport(models.Model):
grant = models.ForeignKey(Grant)
title = models.CharField(max_length=200)
report_type = models.CharField(max_length=50, blank=True)
description = models.CharField(max_length=255, blank=True)
due_date = models.DateField(blank=True, null=True)
submitted_date = models.DateField(blank=True, null=True)
attachment = models.FileField(
upload_to='projects/grants/grant_report_attachments/%Y/%m/%d',
blank=True, null=True)
sort_order = models.IntegerField(blank=True, null=True)
def __str__(self):
return self.title
class Meta:
ordering = ['sort_order']

View file

@ -409,20 +409,20 @@ class TblLuExperiments(models.Model):
unique_together = (('Experiment_Name', 'Experiment_Code'),) unique_together = (('Experiment_Name', 'Experiment_Code'),)
class TblLuGrantReports(models.Model): # class TblLuGrantReports(models.Model):
grantreportid = models.AutoField(db_column='GrantReportID', primary_key=True) # Field name made lowercase. # grantreportid = models.AutoField(db_column='GrantReportID', primary_key=True) # Field name made lowercase.
grantid = models.ForeignKey('TblLuGrants', db_column='GrantID') # 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_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_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_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_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. # 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. # 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. # sort_order = models.IntegerField(db_column='Sort_Order', blank=True, null=True) # Field name made lowercase.
#
class Meta: # class Meta:
managed = False # managed = False
db_table = 'tbl_LU_Grant_Reports' # db_table = 'tbl_LU_Grant_Reports'
# class TblLuGrants(models.Model): # class TblLuGrants(models.Model):