-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use setting to determine if null dates should be replaced (#591)
* Use setting to determine if null dates should be replaced with current time upon import * Maintain same scan decision `created` text between imports and exports * Use dateparser and remove print statements * Fix import order for isort * Include installation of types-dateparser
- Loading branch information
Showing
5 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
miqa/core/migrations/0035_allow_null_decision_creation_times.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,19 @@ | ||
# Generated by Django 3.2.13 on 2022-09-16 13:55 | ||
|
||
from django.db import migrations, models | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('core', '0034_CT_scan_type'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='scandecision', | ||
name='created', | ||
field=models.DateTimeField(default=django.utils.timezone.now, null=True), | ||
), | ||
] |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import datetime | ||
from datetime import datetime | ||
from io import BytesIO, StringIO | ||
import json | ||
from pathlib import Path | ||
|
@@ -9,9 +9,9 @@ | |
from botocore import UNSIGNED | ||
from botocore.client import Config | ||
from celery import shared_task | ||
import dateparser | ||
from django.conf import settings | ||
from django.contrib.auth.models import User | ||
from django.utils import timezone | ||
import pandas | ||
from rest_framework.exceptions import APIException | ||
|
||
|
@@ -213,19 +213,16 @@ def perform_import(import_dict): | |
except User.DoesNotExist: | ||
creator = None | ||
note = '' | ||
created = timezone.now() | ||
created = ( | ||
datetime.now() if settings.REPLACE_NULL_CREATION_DATETIMES else None | ||
) | ||
location = {} | ||
if last_decision_dict['note']: | ||
note = last_decision_dict['note'].replace(';', ',') | ||
if last_decision_dict['created']: | ||
try: | ||
datetime.datetime.strptime( | ||
last_decision_dict['created'], '%Y-%m-%d' | ||
) | ||
except ValueError: | ||
created = timezone.now() | ||
else: | ||
created = last_decision_dict['created'] | ||
valid_dt = dateparser.parse(last_decision_dict['created']) | ||
if valid_dt: | ||
created = valid_dt.strftime('%Y-%m-%d %H:$M') | ||
if last_decision_dict['location'] and last_decision_dict['location'] != '': | ||
slices = [ | ||
axis.split('=')[1] | ||
|
@@ -347,7 +344,11 @@ def perform_export(project_id: Optional[str]): | |
] | ||
# if a last decision exists for the scan, encode that decision on this row | ||
# ... U, [email protected], note; with; commas; replaced, artifact_1;artifact_2 | ||
last_decision = frame_object.scan.decisions.order_by('created').last() | ||
last_decision = ( | ||
frame_object.scan.decisions.filter(created__isnull=False) | ||
.order_by('created') | ||
.last() | ||
) | ||
if last_decision: | ||
location = '' | ||
if last_decision.location: | ||
|
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