summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdolfo Fitoria <adolfo.fitoria@gmail.com>2011-08-22 18:38:01 -0300
committerAdolfo Fitoria <adolfo.fitoria@gmail.com>2011-08-22 18:38:01 -0300
commit86378be6af86139bf19ba6275724e5593444f71e (patch)
treef1d1b8934334e6329ced7ad599c5948171b6f557
parent972394faf7422db35b30b09a73fcd41a1af080e9 (diff)
downloadaskbot-86378be6af86139bf19ba6275724e5593444f71e.tar.gz
askbot-86378be6af86139bf19ba6275724e5593444f71e.tar.bz2
askbot-86378be6af86139bf19ba6275724e5593444f71e.zip
fixing bug 66, make admin first user
-rw-r--r--askbot/doc/source/initialize-database-tables.rst8
-rw-r--r--askbot/models/__init__.py6
2 files changed, 12 insertions, 2 deletions
diff --git a/askbot/doc/source/initialize-database-tables.rst b/askbot/doc/source/initialize-database-tables.rst
index 26993985..f1281816 100644
--- a/askbot/doc/source/initialize-database-tables.rst
+++ b/askbot/doc/source/initialize-database-tables.rst
@@ -38,9 +38,13 @@ 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.
-Finally, turn the newly added user into a superuser by running::
+.. deprecated:: 0.7.20.
+ Finally, turn the newly added user into a superuser by running::
- python manage.py add_admin 1
+ python manage.py add_admin 1
+
+.. 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/models/__init__.py b/askbot/models/__init__.py
index 098cfa1f..a7d7f619 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -2555,7 +2555,13 @@ def set_user_has_custom_avatar_flag(instance, created, **kwargs):
def update_user_has_custom_avatar_flag(instance, **kwargs):
instance.user.update_has_custom_avatar()
+def make_admin_if_first_user(instance, **kwargs):
+ user_count = User.objects.all().count()
+ if user_count == 0:
+ instance.set_admin_status()
+
#signal for User model save changes
+django_signals.pre_save.connect(make_admin_if_first_user, sender=User)
django_signals.pre_save.connect(calculate_gravatar_hash, sender=User)
django_signals.post_save.connect(add_missing_subscriptions, sender=User)
django_signals.post_save.connect(record_award_event, sender=Award)