From f0b567e7a747413d6f895218440355df87105015 Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Sat, 19 Sep 2009 23:14:02 +0200 Subject: [PATCH] improve Sites checks to detect SITE_ID not set or no site of that ID existing, see #30 --- pyweb/mumble/management/commands/checkenv.py | 29 ++++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/pyweb/mumble/management/commands/checkenv.py b/pyweb/mumble/management/commands/checkenv.py index c630c58..973b71b 100644 --- a/pyweb/mumble/management/commands/checkenv.py +++ b/pyweb/mumble/management/commands/checkenv.py @@ -30,7 +30,7 @@ class Command( BaseCommand ): statinfo = os.stat( settings.DATABASE_NAME ); if statinfo.st_uid == 0: - raise TestFailed( "" + raise TestFailed( "the database file belongs to root. This is most certainly not what " "you want because it will prevent your web server from being able " "to write to it. Please check." ); @@ -48,16 +48,33 @@ class Command( BaseCommand ): def check_sites( self ): print "Checking URL configuration...", - site = Site.objects.get_current(); + try: + site = Site.objects.get_current(); + + except Site.DoesNotExist: + try: + sid = settings.SITE_ID + except AttributeError: + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured( + "You're using the Django \"sites framework\" without having set the SITE_ID " + "setting. Create a site in your database and rerun this command to fix this error.") + else: + print( "none set.\n" + "Please enter the domain where Mumble-Django is reachable." ); + dom = raw_input( "> " ).strip(); + site = Site( id=sid, name=dom, domain=dom ); + site.save(); + if site.domain == 'example.com': - print( "The domain is configured as example.com, which is the default but does not make sense." + print( "still the default.\n" + "The domain is configured as example.com, which is the default but does not make sense. " "Please enter the domain where Mumble-Django is reachable." ); site.domain = raw_input( "> " ).strip(); site.save(); - else: - print site.domain, "[ OK ]"; + print site.domain, "[ OK ]"; def check_admins( self ): @@ -79,7 +96,7 @@ class Command( BaseCommand ): mm = Mumble.objects.all(); if mm.count() == 0: - raise TestFailed( "" + raise TestFailed( "no Mumble servers are configured, you might want to run " "`./manage.py syncdb` to run an auto detection." );