#!/usr/bin/env python
"""
Hacked version of Django's manage.py to get full test coverage (including
models and admin).
This solution found at https://github.com/django-nose/django-nose/issues/180
"""
#pylint: disable=invalid-name
import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ django_project }}.settings")
    from django.core.management import execute_from_command_line

    is_testing = 'test' in sys.argv

    if is_testing:
        import coverage
        cov = coverage.coverage()
        cov.erase()
        cov.start()

    execute_from_command_line(sys.argv)

    if is_testing:
        cov.stop()
        cov.save()
        cov.report()
        cov.html_report(directory=os.path.join(os.getcwd(), 'cover'))
