fixtures.py 1002 B

12345678910111213141516171819202122232425262728293031323334
  1. from django.utils.importlib import import_module
  2. def load_app_fixtures(app):
  3. """
  4. See if application has fixtures module defining load_fixtures function
  5. If it does, execute that function
  6. """
  7. app += '.fixtures'
  8. try:
  9. fixture = import_module(app)
  10. fixture.load_fixtures()
  11. return True
  12. except (ImportError, AttributeError):
  13. return False
  14. except Exception as e:
  15. print 'Could not load fixtures from %s:\n%s' % (app, e)
  16. return False
  17. def update_app_fixtures(app):
  18. """
  19. See if application has fixtures module defining update_fixtures function
  20. If it does, execute that function
  21. """
  22. app += '.fixtures'
  23. try:
  24. fixture = import_module(app)
  25. fixture.update_fixtures()
  26. return True
  27. except (ImportError, AttributeError):
  28. return False
  29. except Exception as e:
  30. print 'Could not update fixtures from %s:\n%s' % (app, e)
  31. return False