Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

management.py 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. Creates the default Site object.
  3. """
  4. from django.apps import apps as global_apps
  5. from django.conf import settings
  6. from django.core.management.color import no_style
  7. from django.db import DEFAULT_DB_ALIAS, connections, router
  8. def create_default_site(
  9. app_config,
  10. verbosity=2,
  11. interactive=True,
  12. using=DEFAULT_DB_ALIAS,
  13. apps=global_apps,
  14. **kwargs,
  15. ):
  16. try:
  17. Site = apps.get_model("sites", "Site")
  18. except LookupError:
  19. return
  20. if not router.allow_migrate_model(using, Site):
  21. return
  22. if not Site.objects.using(using).exists():
  23. # The default settings set SITE_ID = 1, and some tests in Django's test
  24. # suite rely on this value. However, if database sequences are reused
  25. # (e.g. in the test suite after flush/syncdb), it isn't guaranteed that
  26. # the next id will be 1, so we coerce it. See #15573 and #16353. This
  27. # can also crop up outside of tests - see #15346.
  28. if verbosity >= 2:
  29. print("Creating example.com Site object")
  30. Site(
  31. pk=getattr(settings, "SITE_ID", 1), domain="example.com", name="example.com"
  32. ).save(using=using)
  33. # We set an explicit pk instead of relying on auto-incrementation,
  34. # so we need to reset the database sequence. See #17415.
  35. sequence_sql = connections[using].ops.sequence_reset_sql(no_style(), [Site])
  36. if sequence_sql:
  37. if verbosity >= 2:
  38. print("Resetting sequence")
  39. with connections[using].cursor() as cursor:
  40. for command in sequence_sql:
  41. cursor.execute(command)