diff options
Diffstat (limited to 'askbot')
-rw-r--r-- | askbot/doc/source/askbot-as-reusable-django-application.rst (renamed from askbot/doc/source/askbot-as-django-application.rst) | 46 | ||||
-rw-r--r-- | askbot/doc/source/index.rst | 2 | ||||
-rw-r--r-- | askbot/models/__init__.py | 8 | ||||
-rw-r--r-- | askbot/tests/email_alert_tests.py | 13 | ||||
-rw-r--r-- | askbot/tests/utils.py | 5 |
5 files changed, 54 insertions, 20 deletions
diff --git a/askbot/doc/source/askbot-as-django-application.rst b/askbot/doc/source/askbot-as-reusable-django-application.rst index d4072628..b37a1bc6 100644 --- a/askbot/doc/source/askbot-as-django-application.rst +++ b/askbot/doc/source/askbot-as-reusable-django-application.rst @@ -9,6 +9,26 @@ a truly reusable app, but some are already solved. This page is a guide for using askbot as an independent app and it is somewhat technical. +.. _adding-askbot-to-pre-existing-site: +Adding askbot to a pre-existing site +==================================== + +If you already have a django site with users, after adding askbot +to your project, run a management command just once:: + + python manage.py add_missing_subscriptions + +.. note:: + This only applies to users registered before the installation of Askbot. + Newer users will have default subscription records + created automatically, by the Django's ``post_save`` signal. + + The email subscription settings are also created automatically + when certain pages are visited and when ``send_email_alerts`` + command is run, so it is not mandatory to run + ``add_missing_subscriptions``. + +.. _askbot-with-alternative-login-system: Using alternative login system ============================== @@ -19,9 +39,12 @@ from the ``INSTALLED_APPS``, remove ``'askbot.deps.django_authopenid.backends.AuthBackend'`` from the ``AUTHENTICATION_BACKENDS``, install another registration app -and modify ``LOGIN_URL`` accordingly. +and modify ``LOGIN_URL`` and ``LOGOUT_URL`` accordingly. + +If you are adding Askbot to a django site that already has +registered users, please see :ref:`this section <adding-askbot-to-pre-existing-site>`. -There are three caveats. +There are two caveats. Firstly, if you are using some other login/registration app, please disable feature @@ -32,20 +55,5 @@ right after the user logs in - please ask at askbot forum if you are interested. Secondly, disable setting "settings"->"user settings"->"allow add and remove login methods". -This one is specific to the builtin login application. - -One more thing to keep in mind is in askbot each user has records for -email subscription settings, and these will be missing when he/she -registers via some alternative login application. -This is not a big problem and should not lead to errors, -however some users may miss email notifications -until their records complete. - -The email subscription settings are created automatically when certain pages -are visited, but there is a way to accelerate this process by calling -management command:: - - python manage.py add_missing_subscriptions - -Alternatively, you can insert the following call just after the new user -account is created ``user.add_missing_askbot_subscriptions()`` +This one is specific to the builtin login application which allows more than one login +method per user account. diff --git a/askbot/doc/source/index.rst b/askbot/doc/source/index.rst index 5ab51397..b46d10dd 100644 --- a/askbot/doc/source/index.rst +++ b/askbot/doc/source/index.rst @@ -23,7 +23,7 @@ at the forum_ or by email at admin@askbot.org Appendix A: Maintenance procedures <management-commands> Appendix B: Sending email to askbot <sending-email-to-askbot> Appendix C: Optional modules <optional-modules> - Appendix D: Askbot as Django application <askbot-as-django-application> + Appendix D: Askbot as reusable Django application <askbot-as-reusable-django-application> Footnotes <footnotes> Contributors <contributors> diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 3afcefef..1a5295b3 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -2422,6 +2422,13 @@ def complete_pending_tag_subscriptions(sender, request, *args, **kwargs): message = _('Your tag subscription was saved, thanks!') ) +def add_missing_subscriptions(sender, instance, created, **kwargs): + """``sender`` is instance of ``User``. When the ``User`` + is created, any required email subscription settings will be + added by this handler""" + if created: + instance.add_missing_askbot_subscriptions() + def post_anonymous_askbot_content( sender, request, @@ -2443,6 +2450,7 @@ def update_user_has_custom_avatar_flag(instance, **kwargs): #signal for User model save changes 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) django_signals.post_save.connect(notify_award_message, sender=Award) django_signals.post_save.connect(record_answer_accepted, sender=Answer) diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py index 10113446..1fbe3bf5 100644 --- a/askbot/tests/email_alert_tests.py +++ b/askbot/tests/email_alert_tests.py @@ -895,3 +895,16 @@ class EmailFeedSettingTests(utils.AskbotTestCase): feed.frequency, askbot_settings.DEFAULT_NOTIFICATION_DELIVERY_SCHEDULE ) + + def test_missing_subscriptions_added_automatically(self): + new_user = models.User.objects.create_user('new', 'new@example.com') + feeds_before = self.get_user_feeds() + + #verify that feed settigs are created automatically + #when user is just created + self.assertTrue(feeds_before.count() != 0) + + data_before = TO_JSON(feeds_before) + new_user.add_missing_askbot_subscriptions() + data_after = TO_JSON(self.get_user_feeds()) + self.assertEquals(data_before, data_after) diff --git a/askbot/tests/utils.py b/askbot/tests/utils.py index 0c18e661..03478419 100644 --- a/askbot/tests/utils.py +++ b/askbot/tests/utils.py @@ -33,6 +33,7 @@ def create_user( * 'n' - never """ user = models.User.objects.create_user(username, email) + user.reputation = reputation if date_joined is not None: user.date_joined = date_joined @@ -41,6 +42,10 @@ def create_user( if notification_schedule == None: notification_schedule = models.EmailFeedSetting.NO_EMAIL_SCHEDULE + #a hack, we need to delete these, that will be created automatically + #because just below we will be replacing them with the new values + user.notification_subscriptions.all().delete() + for feed_type, frequency in notification_schedule.items(): feed = models.EmailFeedSetting( feed_type = feed_type, |