-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 402 - file requirements (#410)
- Loading branch information
Showing
10 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 3.2.25 on 2024-11-07 22:15 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0038_addregions'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='FileRequirements', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)), | ||
('create_user', models.CharField(default='SYSTEM', max_length=130)), | ||
('update_timestamp', models.DateTimeField(auto_now=True, null=True)), | ||
('update_user', models.CharField(max_length=130, null=True)), | ||
('sheet', models.TextField(blank=True, null=True)), | ||
('columns', models.TextField(blank=True, null=True)), | ||
('formats', models.TextField(blank=True, null=True)), | ||
('dataset', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='file_requirements', to='api.datasets')), | ||
], | ||
options={ | ||
'db_table': 'file_requirements', | ||
}, | ||
), | ||
] |
63 changes: 63 additions & 0 deletions
63
django/api/migrations/0040_add_datasets_and_file_requirements.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Generated by Django 3.2.25 on 2024-11-07 22:17 | ||
|
||
from django.db import migrations | ||
|
||
|
||
def add_datasets_and_file_requirements(apps, schema_editor): | ||
Datasets = apps.get_model("api", "Datasets") | ||
FileRequirements = apps.get_model("api", "FileRequirements") | ||
columns_default_text = "All required columns must match the column names exactly as they appear in the provided template" | ||
formats_default_text = "File format should be xlsx. xlsm. only" | ||
|
||
ger_obj, ger_created = Datasets.objects.get_or_create( | ||
name="Go Electric Rebates Program", defaults={"update_user": "SYSTEM"} | ||
) | ||
FileRequirements.objects.get_or_create( | ||
dataset=ger_obj, | ||
defaults={ | ||
"sheet": """ | ||
The sheet name must be "Distribution List - Master" | ||
""", | ||
"columns": columns_default_text, | ||
"formats": formats_default_text, | ||
}, | ||
) | ||
|
||
arc_obj, arc_created = Datasets.objects.get_or_create( | ||
name="ARC Project Tracking", defaults={"update_user": "SYSTEM"} | ||
) | ||
FileRequirements.objects.get_or_create( | ||
dataset=arc_obj, | ||
defaults={ | ||
"sheet": """ | ||
The sheet name must be "ARC Data" | ||
""", | ||
"columns": columns_default_text, | ||
"formats": formats_default_text, | ||
}, | ||
) | ||
|
||
cvp_obj, cvp_created = Datasets.objects.get_or_create( | ||
name="CVP Data", defaults={"update_user": "SYSTEM"} | ||
) | ||
FileRequirements.objects.get_or_create( | ||
dataset=cvp_obj, | ||
defaults={ | ||
"sheet": """ | ||
The sheet name must be "Data" | ||
""", | ||
"columns": columns_default_text, | ||
"formats": formats_default_text, | ||
}, | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("api", "0039_filerequirements"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(add_datasets_and_file_requirements), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ | |
from . import decoded_vin_record | ||
from . import regions | ||
from . import cvp_data | ||
from . import file_requirements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.db import models | ||
from auditable.models import Auditable | ||
from api.models.datasets import Datasets | ||
|
||
|
||
class FileRequirements(Auditable): | ||
dataset = models.OneToOneField( | ||
Datasets, | ||
related_name="file_requirements", | ||
on_delete=models.CASCADE, | ||
) | ||
|
||
sheet = models.TextField(blank=True, null=True) | ||
|
||
columns = models.TextField(blank=True, null=True) | ||
|
||
formats = models.TextField(blank=True, null=True) | ||
|
||
class Meta: | ||
db_table = "file_requirements" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from rest_framework.serializers import ModelSerializer | ||
from api.models.file_requirements import FileRequirements | ||
|
||
|
||
class FileRequirementsSerializer(ModelSerializer): | ||
|
||
class Meta: | ||
model = FileRequirements | ||
fields = ("sheet", "columns", "formats") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from api.models.file_requirements import FileRequirements | ||
|
||
|
||
def get_file_requirements(dataset_name): | ||
return FileRequirements.objects.filter(dataset__name=dataset_name).first() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import useAxios from "../../app/utilities/useAxios"; | ||
import ROUTES_UPLOAD from "../routes"; | ||
|
||
const FileRequirements = ({ datasetSelected }) => { | ||
const axios = useAxios(); | ||
const [requirements, setRequirements] = useState([]); | ||
|
||
useEffect(() => { | ||
if (datasetSelected) { | ||
axios | ||
.get( | ||
ROUTES_UPLOAD.FILE_REQUIREMENTS.replace(":dataset", datasetSelected), | ||
) | ||
.then((response) => { | ||
const list = []; | ||
for (const [key, value] of Object.entries(response.data)) { | ||
list.push(<li key={key}>{value}</li>); | ||
} | ||
setRequirements(list); | ||
}) | ||
.catch((error) => { | ||
//do something here? | ||
}); | ||
} | ||
}, [datasetSelected]); | ||
|
||
if (requirements.length > 0) { | ||
return ( | ||
<div id="file-requirements"> | ||
<h3>File Requirements</h3> | ||
<div> | ||
Ensure your file meets the following conditions before uploading: | ||
</div> | ||
<ul>{requirements}</ul> | ||
</div> | ||
); | ||
} | ||
return null; | ||
}; | ||
|
||
export default FileRequirements; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters