summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-08-30 19:26:03 -0300
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-08-30 19:26:03 -0300
commitae0bc84d12f9ee22d88caf71e1a2ce915d2dd3e7 (patch)
tree3add6c2ffa42fa1c427d78e6e14a9c88c0e3c7fc
parentafc6213cf40fa3bfda5cb19028d4e034d8af170a (diff)
parent62446c99d1bb3453f1d84fa7a5eda8ad1e44a102 (diff)
downloadaskbot-ae0bc84d12f9ee22d88caf71e1a2ce915d2dd3e7.tar.gz
askbot-ae0bc84d12f9ee22d88caf71e1a2ce915d2dd3e7.tar.bz2
askbot-ae0bc84d12f9ee22d88caf71e1a2ce915d2dd3e7.zip
merged with Adolfo's solution of issue-66
-rw-r--r--askbot/doc/source/changelog.rst1
-rw-r--r--askbot/doc/source/initialize-database-tables.rst10
-rw-r--r--askbot/management/commands/createsuperuser.py112
-rw-r--r--askbot/utils/hasher.py40
4 files changed, 160 insertions, 3 deletions
diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst
index 907c1b4a..b1c4c1f8 100644
--- a/askbot/doc/source/changelog.rst
+++ b/askbot/doc/source/changelog.rst
@@ -6,6 +6,7 @@ Development version (not yet on pypi)
* First user automatically becomes site administrator (Adolfo Fitoria)
* Avatar displayed on the sidebar can be controlled with livesettings.(Adolfo Fitoria, Evgeny Fadeev)
* Avatar box in the sidebar is ordered with priority for real faces.(Adolfo Fitoria)
+* Django's createsuperuser now works with askbot (Adolfo Fitoria)
0.7.20 (Current Version)
------------------------
diff --git a/askbot/doc/source/initialize-database-tables.rst b/askbot/doc/source/initialize-database-tables.rst
index f1281816..a296de3e 100644
--- a/askbot/doc/source/initialize-database-tables.rst
+++ b/askbot/doc/source/initialize-database-tables.rst
@@ -8,7 +8,11 @@ When you install Askbot the first time and any time you upgrade the software, ru
python manage.py syncdb
-When the script asks you if you want to create a superuser, answer **no**.
+.. versionchanged:: 0.7.21
+ When the script asks you if you want to create a superuser, answer yes if you want to create one. By default Askbot sets admin status(superuser) for the first user created automatically but also supports this form.
+
+.. deprecated:: 0.7.21
+ When the script asks you if you want to create a superuser, answer **no**.
Then run::
@@ -38,12 +42,12 @@ Connect to the Django development server with your Web browser. The address is t
Once the fresh copy of Askbot appears in your browser, create a new account at the site.
This will be your administrator account.
-.. deprecated:: 0.7.20.
+.. deprecated:: 0.7.20
Finally, turn the newly added user into a superuser by running::
python manage.py add_admin 1
-.. versionadded:: 0.7.20.
+.. versionadded:: 0.7.20
In the new version of Askbot the first user you create on the site will be added as administrator.
Here number 1 is the numeric id of the first user, enter a different number, if it is indeed different.
diff --git a/askbot/management/commands/createsuperuser.py b/askbot/management/commands/createsuperuser.py
new file mode 100644
index 00000000..eb363bbd
--- /dev/null
+++ b/askbot/management/commands/createsuperuser.py
@@ -0,0 +1,112 @@
+from django.contrib.auth.management.commands.createsuperuser import *
+from django.db.models.signals import pre_save, post_save
+
+class Command(Command):
+
+ def handle(self, *args, **options):
+ username = options.get('username', None)
+ email = options.get('email', None)
+ interactive = options.get('interactive')
+ verbosity = int(options.get('verbosity', 1))
+
+ # 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")
+ try:
+ is_valid_email(email)
+ except exceptions.ValidationError:
+ raise CommandError("Invalid email address.")
+
+ # If not provided, create the user with an unusable password
+ password = None
+
+ # Try to determine the current system user's username to use as a default.
+ try:
+ default_username = getpass.getuser().replace(' ', '').lower()
+ except (ImportError, KeyError):
+ # KeyError will be raised by os.getpwuid() (called by getuser())
+ # if there is no corresponding entry in the /etc/passwd file
+ # (a very restricted chroot environment, for example).
+ default_username = ''
+
+ # Determine whether the default username is taken, so we don't display
+ # it as an option.
+ if default_username:
+ try:
+ User.objects.get(username=default_username)
+ except User.DoesNotExist:
+ pass
+ else:
+ default_username = ''
+
+ # Prompt for username/email/password. Enclose this whole thing in a
+ # try/except to trap for a keyboard interrupt and exit gracefully.
+ if interactive:
+ try:
+
+ # Get a username
+ while 1:
+ if not username:
+ input_msg = 'Username'
+ if default_username:
+ input_msg += ' (Leave blank to use %r)' % default_username
+ username = raw_input(input_msg + ': ')
+ if default_username and username == '':
+ username = default_username
+ if not RE_VALID_USERNAME.match(username):
+ sys.stderr.write("Error: That username is invalid. Use only letters, digits and underscores.\n")
+ username = None
+ continue
+ try:
+ User.objects.get(username=username)
+ except User.DoesNotExist:
+ break
+ else:
+ sys.stderr.write("Error: That username is already taken.\n")
+ username = None
+
+ # Get an email
+ while 1:
+ if not email:
+ email = raw_input('E-mail address: ')
+ try:
+ is_valid_email(email)
+ except exceptions.ValidationError:
+ sys.stderr.write("Error: That e-mail address is invalid.\n")
+ email = None
+ else:
+ break
+
+ # Get a password
+ while 1:
+ if not password:
+ password = getpass.getpass()
+ password2 = getpass.getpass('Password (again): ')
+ if password != password2:
+ sys.stderr.write("Error: Your passwords didn't match.\n")
+ password = None
+ continue
+ if password.strip() == '':
+ sys.stderr.write("Error: Blank passwords aren't allowed.\n")
+ password = None
+ continue
+ break
+ except KeyboardInterrupt:
+ sys.stderr.write("\nOperation cancelled.\n")
+ sys.exit(1)
+
+ self.remove_signals()
+ u = User.objects.create_superuser(username, email, password)
+ u.set_admin_status()
+ u.save()
+
+ if verbosity >= 1:
+ self.stdout.write("Askbot Superuser created successfully.\n")
+
+
+ def remove_signals(self):
+ pre_save.receivers = []
+ post_save.receivers = []
diff --git a/askbot/utils/hasher.py b/askbot/utils/hasher.py
new file mode 100644
index 00000000..4c68ed79
--- /dev/null
+++ b/askbot/utils/hasher.py
@@ -0,0 +1,40 @@
+import hashlib, os
+from askbot.conf import settings as askbot_settings
+use_skin = askbot_settings.ASKBOT_DEFAULT_SKIN
+resource_revision = askbot_settings.MEDIA_RESOURCE_REVISION
+
+def GetHashofDirs(directory, verbose=0):
+ SHAhash = hashlib.sha1()
+ if not os.path.exists (directory):
+ return -1
+
+ try:
+ for root, dirs, files in os.walk(directory):
+ for names in files:
+ filepath = os.path.join(root,names)
+ try:
+ f1 = open(filepath, 'rb')
+ except:
+ # You can't open the file for some reason
+ f1.close()
+ continue
+
+ while 1:
+ # Read file in as little chunks
+ buf = f1.read(4096)
+ if not buf : break
+ SHAhash.update(hashlib.sha1(buf).hexdigest())
+ f1.close()
+
+ except:
+ import traceback
+ # Print the stack traceback
+ traceback.print_exc()
+ return -2
+
+ return SHAhash.hexdigest()
+
+if __name__ == '__main__':
+ #directory = raw_input('directory:')
+ #print GetHashofDirs(directory, 0)
+ print GetHashofDirs('skins/default/media', 0)