Skip to content

Commit

Permalink
Merge pull request #114 from paulocheque/check
Browse files Browse the repository at this point in the history
Fixed ddf_check_models import and added CSV report
  • Loading branch information
paulocheque committed Jan 7, 2020
2 parents 7bd33d8 + ac4aa1c commit e4eeb07
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ deps:
env/bin/pip install -r requirements-dev.txt

shell:
# clear ; env/bin/python -i -c "from ddf import *"
#clear ; env/bin/python -i -c "from ddf import *"
clear ; env/bin/python manage.py shell
# from ddf import *

# Python code tasks

Expand Down
1 change: 1 addition & 0 deletions ddf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from django_dynamic_fixture import new, get, fixture, teach, look_up_alias
from django_dynamic_fixture.decorators import skip_for_database, only_for_database
from django_dynamic_fixture.fdf import FileSystemDjangoTestCase
from django_dynamic_fixture.script_ddf_checkings import ddf_check_models
25 changes: 21 additions & 4 deletions django_dynamic_fixture/script_ddf_checkings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import csv

from django.db import transaction

from django_dynamic_fixture.django_helper import get_apps, get_models_of_an_app
Expand All @@ -16,7 +18,7 @@ def green(string):
return color('92', string)


def ddf_check_models(application_labels=[], exclude_application_labels=[]):
def ddf_check_models(application_labels=[], exclude_application_labels=[], csv_filename='ddf_compatibility_report.csv'):
from django_dynamic_fixture import get

succeeded = {}
Expand All @@ -32,9 +34,15 @@ def ddf_check_models(application_labels=[], exclude_application_labels=[]):
except Exception as e:
errors[ref] = '[{}] {}'.format(type(e), str(e))

# Print report
console_report(succeeded, errors)
if csv_filename:
csv_report(succeeded, errors, filename=csv_filename)
return succeeded, errors


def console_report(succeeded, errors):
print(green('\nModels that DDF can create using the default settings.\n'))
for i, (ref, _) in enumerate(succeeded.items()):
for i, (ref, _) in enumerate(succeeded.items(), start=1):
i = str(i).zfill(3)
print(white('{}. {}: '.format(i, ref)) + green('succeeded'))

Expand All @@ -43,4 +51,13 @@ def ddf_check_models(application_labels=[], exclude_application_labels=[]):
i = str(i).zfill(3)
print(white('{}. {}: '.format(i, ref)) + red(error))

return succeeded, errors

def csv_report(succeeded, errors, filename):
with open(filename, 'w') as f:
f.write(','.join(['#', 'Model', 'Succeeded', '\n']))
for i, (ref, _) in enumerate(succeeded.items(), start=1):
f.write(','.join([str(i), ref, 'succeeded', '\n']))

f.write(','.join(['#', 'Model', 'Error', '\n']))
for i, (ref, error) in enumerate(errors.items(), start=1):
f.write(','.join([str(i), ref, error, '\n']))
2 changes: 2 additions & 0 deletions docs/source/more.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ DDF has a simple script that will look for all Django models of all installed Dj
from ddf import ddf_check_models
succeeded, errors = ddf_check_models()

It will also generate a **ddf_compatibility_report.csv** file so you can use it better in a CSV editor.


Debug Mode (New in 1.6.2)
-------------------------------------------------------------------------------
Expand Down

0 comments on commit e4eeb07

Please sign in to comment.