From 86378be6af86139bf19ba6275724e5593444f71e Mon Sep 17 00:00:00 2001 From: Adolfo Fitoria Date: Mon, 22 Aug 2011 18:38:01 -0300 Subject: fixing bug 66, make admin first user --- askbot/doc/source/initialize-database-tables.rst | 8 ++++++-- askbot/models/__init__.py | 6 ++++++ 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) -- cgit v1.2.3-1-g7c22