Grant Reports
This commit is contained in:
		
							parent
							
								
									52a38951a3
								
							
						
					
					
						commit
						9161fa34ea
					
				
					 6 changed files with 110 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -1,7 +1,8 @@
 | 
			
		|||
from django.contrib import admin
 | 
			
		||||
 | 
			
		||||
from .models import Project, Grant
 | 
			
		||||
from .models import Project, Grant, GrantReport
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
admin.site.register(Project)
 | 
			
		||||
admin.site.register(Grant)
 | 
			
		||||
admin.site.register(GrantReport)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										31
									
								
								ccdb/projects/migrations/0007_initial_grantreport.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								ccdb/projects/migrations/0007_initial_grantreport.py
									
										
									
									
									
										Normal 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'],
 | 
			
		||||
            },
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										43
									
								
								ccdb/projects/migrations/0008_grantreport_data.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								ccdb/projects/migrations/0008_grantreport_data.py
									
										
									
									
									
										Normal 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),
 | 
			
		||||
    ]
 | 
			
		||||
| 
						 | 
				
			
			@ -34,3 +34,22 @@ class Grant(models.Model):
 | 
			
		|||
    class Meta:
 | 
			
		||||
        unique_together = ('title', 'code',)
 | 
			
		||||
        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']
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue