summaryrefslogtreecommitdiffstats
path: root/core/module/web/createsuperuser.py
diff options
context:
space:
mode:
authorGravatar mkaay <mkaay@mkaay.de> 2010-08-25 16:48:55 +0200
committerGravatar mkaay <mkaay@mkaay.de> 2010-08-25 16:48:55 +0200
commit3c9f55270a83b0e88ec0dc516f9d9921e4d7b6ea (patch)
treec5b2b1bfeb7eb8df2b97be118f6cbcec4e29cb3b /core/module/web/createsuperuser.py
parentul.to fetching, so.biz expire (diff)
downloadpyload-3c9f55270a83b0e88ec0dc516f9d9921e4d7b6ea.tar.xz
merged gui
Diffstat (limited to 'core/module/web/createsuperuser.py')
-rw-r--r--core/module/web/createsuperuser.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/core/module/web/createsuperuser.py b/core/module/web/createsuperuser.py
new file mode 100644
index 000000000..0ff1d15b8
--- /dev/null
+++ b/core/module/web/createsuperuser.py
@@ -0,0 +1,43 @@
+"""
+Management utility to create superusers.
+"""
+
+import os
+import sys
+
+os.environ["DJANGO_SETTINGS_MODULE"] = 'settings'
+sys.path.append(os.path.join(pypath, "module", "web"))
+
+import getpass
+import re
+from optparse import make_option
+from django.contrib.auth.models import User
+from django.core import exceptions
+from django.core.management.base import BaseCommand, CommandError
+from django.utils.translation import ugettext as _
+
+RE_VALID_USERNAME = re.compile('[\w.@+-]+$')
+
+
+def handle(username, email):
+ #username = options.get('username', None)
+ #email = options.get('email', None)
+ interactive = False
+
+ # Do quick and dirty validation if --noinput
+ if not interactive:
+ if not username or not email:
+ raise CommandError("You must use --username and --email with --noinput.")
+ if not RE_VALID_USERNAME.match(username):
+ raise CommandError("Invalid username. Use only letters, digits, and underscores")
+
+ password = ''
+ default_username = ''
+
+ User.objects.create_superuser(username, email, password)
+ print "Superuser created successfully."
+
+if __name__ == "__main__":
+ username = sys.argv[1]
+ email = sys.argv[2]
+ handle(username, email) \ No newline at end of file