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

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),
]