summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-06-05 02:11:45 -0400
committerEvgeny Fadeev <evgeny.fadeev@gmail.com>2011-06-05 02:11:45 -0400
commita16d90151874954a8824c1b9495392f599b70705 (patch)
tree08fc25f392518c286ff8cf3638e507de7c5f3775
parent4d6b65d3c8dfe223e3379c9851ca9f2d8356196e (diff)
downloadaskbot-a16d90151874954a8824c1b9495392f599b70705.tar.gz
askbot-a16d90151874954a8824c1b9495392f599b70705.tar.bz2
askbot-a16d90151874954a8824c1b9495392f599b70705.zip
almost finished support of other login apps to be used with askbot
-rw-r--r--askbot/conf/forum_data_rules.py19
-rw-r--r--askbot/context.py4
-rw-r--r--askbot/deps/django_authopenid/urls.py2
-rw-r--r--askbot/deps/django_authopenid/views.py6
-rw-r--r--askbot/doc/source/askbot-as-django-application.rst41
-rw-r--r--askbot/doc/source/index.rst1
-rw-r--r--askbot/management/commands/add_missing_subscriptions.py2
-rw-r--r--askbot/management/commands/post_emailed_questions.py3
-rw-r--r--askbot/management/commands/send_email_alerts.py2
-rw-r--r--askbot/models/__init__.py76
-rw-r--r--askbot/skins/default/templates/authopenid/complete.html2
-rw-r--r--askbot/skins/default/templates/authopenid/signin.html2
-rw-r--r--askbot/skins/default/templates/authopenid/signup_with_password.html4
-rw-r--r--askbot/skins/default/templates/blocks/bottom_scripts.html2
-rw-r--r--askbot/skins/default/templates/blocks/header_meta_links.html4
-rw-r--r--askbot/skins/default/templates/faq.html2
-rw-r--r--askbot/skins/default/templates/question.html4
-rw-r--r--askbot/skins/default/templates/user_profile/user_info.html2
-rw-r--r--askbot/tests/email_alert_tests.py4
-rw-r--r--askbot/tests/page_load_tests.py1
-rw-r--r--askbot/urls.py4
-rw-r--r--askbot/utils/url_utils.py32
-rw-r--r--askbot/views/commands.py3
-rw-r--r--askbot/views/writers.py9
24 files changed, 170 insertions, 61 deletions
diff --git a/askbot/conf/forum_data_rules.py b/askbot/conf/forum_data_rules.py
index afbbf027..3392278b 100644
--- a/askbot/conf/forum_data_rules.py
+++ b/askbot/conf/forum_data_rules.py
@@ -8,7 +8,7 @@ from askbot import const
FORUM_DATA_RULES = livesettings.ConfigurationGroup(
'FORUM_DATA_RULES',
- _('Settings for askbot data entry and display')
+ _('Data entry and display')
)
settings.register(
@@ -47,6 +47,23 @@ settings.register(
)
settings.register(
+ livesettings.BooleanValue(
+ FORUM_DATA_RULES,
+ 'ALLOW_POSTING_BEFORE_LOGGING_IN',
+ default = True,
+ description = _('Allow posting before logging in'),
+ help_text = _(
+ 'Check if you want to allow users start posting questions '
+ 'or answers before logging in. '
+ 'Enabling this may require adjustments in the '
+ 'user login system to check for pending posts '
+ 'every time the user logs in. The builtin Askbot login system '
+ 'supports this feature.'
+ )
+ )
+)
+
+settings.register(
livesettings.IntegerValue(
FORUM_DATA_RULES,
'MAX_TAG_LENGTH',
diff --git a/askbot/context.py b/askbot/context.py
index f3419abd..5a174585 100644
--- a/askbot/context.py
+++ b/askbot/context.py
@@ -7,6 +7,7 @@ import askbot
from askbot import api
from askbot.conf import settings as askbot_settings
from askbot.skins.loaders import get_skin
+from askbot.utils import url_utils
def application_settings(request):
"""The context processor function"""
@@ -15,6 +16,9 @@ def application_settings(request):
my_settings['ASKBOT_URL'] = settings.ASKBOT_URL
my_settings['DEBUG'] = settings.DEBUG
my_settings['ASKBOT_VERSION'] = askbot.get_version()
+ my_settings['LOGIN_URL'] = url_utils.get_login_url()
+ my_settings['LOGOUT_URL'] = url_utils.get_logout_url()
+ my_settings['LOGOUT_REDIRECT_URL'] = url_utils.get_logout_redirect_url()
return {
'settings': my_settings,
'skin': get_skin(request),
diff --git a/askbot/deps/django_authopenid/urls.py b/askbot/deps/django_authopenid/urls.py
index a533f771..f51939ab 100644
--- a/askbot/deps/django_authopenid/urls.py
+++ b/askbot/deps/django_authopenid/urls.py
@@ -7,8 +7,6 @@ urlpatterns = patterns('askbot.deps.django_authopenid.views',
url(r'^yadis.xrdf$', 'xrdf', name='yadis_xrdf'),
# manage account registration
url(r'^%s$' % _('signin/'), 'signin', name='user_signin'),
- url(r'^%s%s$' % (_('signin/'),_('newquestion/')), 'signin', kwargs = {'newquestion':True}, name='user_signin_new_question'),
- url(r'^%s%s$' % (_('signin/'),_('newanswer/')), 'signin', kwargs = {'newanswer':True}, name='user_signin_new_answer'),
url(r'^%s$' % _('signout/'), 'signout', name='user_signout'),
#this view is "complete-openid" signin
url(r'^%s%s$' % (_('signin/'), _('complete/')), 'complete_signin',
diff --git a/askbot/deps/django_authopenid/views.py b/askbot/deps/django_authopenid/views.py
index f43c2dbe..787d7e53 100644
--- a/askbot/deps/django_authopenid/views.py
+++ b/askbot/deps/django_authopenid/views.py
@@ -267,11 +267,7 @@ def complete_oauth_signin(request):
#@not_authenticated
@csrf.csrf_protect
-def signin(
- request,
- newquestion = False,#todo: not needed
- newanswer = False,#todo: not needed
- ):
+def signin(request):
"""
signin page. It manages the legacy authentification (user/password)
and openid authentification
diff --git a/askbot/doc/source/askbot-as-django-application.rst b/askbot/doc/source/askbot-as-django-application.rst
new file mode 100644
index 00000000..09c0a81e
--- /dev/null
+++ b/askbot/doc/source/askbot-as-django-application.rst
@@ -0,0 +1,41 @@
+=====================================
+Askbot as reusable django application
+=====================================
+
+Askbot can be used both as as dedicated site and as an application
+within a larger site. There are still issues to resolve to make askbot
+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.
+
+Using alternative login system
+==============================
+
+Askbot has a bundled application for user login and registration,
+but it can be replaced with any other.
+
+There are two caveats. If you want the "allow posting before logging in" feature
+(which can be enabled/disabled at
+"settings"->"data entry and display"->"allow posting before logging in"),
+you must either insure that your app calls ``user.post_anonymous_askbot_content()``
+right after the user logs in, or activate middleware
+``askbot.middleware.anon_posts.PublishAnonPostsMiddleware``.
+
+The middleware solution is not desirable, as it will cause additional
+database queries each time a logged in user loads any page on the site.
+
+Second thing to keep in mind is in askbot each user has records for
+email subscription settings, and these will be missing when user
+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 complete 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()``
diff --git a/askbot/doc/source/index.rst b/askbot/doc/source/index.rst
index fedc3913..5ab51397 100644
--- a/askbot/doc/source/index.rst
+++ b/askbot/doc/source/index.rst
@@ -23,6 +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>
Footnotes <footnotes>
Contributors <contributors>
diff --git a/askbot/management/commands/add_missing_subscriptions.py b/askbot/management/commands/add_missing_subscriptions.py
index b30822d1..70b1590e 100644
--- a/askbot/management/commands/add_missing_subscriptions.py
+++ b/askbot/management/commands/add_missing_subscriptions.py
@@ -8,5 +8,5 @@ class Command(NoArgsCommand):
@transaction.commit_manually
def handle_noargs(self, **options):
for user in User.object.all():
- user.add_missing_subscriptions()
+ user.add_missing_askbot_subscriptions()
transaction.commit()
diff --git a/askbot/management/commands/post_emailed_questions.py b/askbot/management/commands/post_emailed_questions.py
index 73b5ed3e..0a038b62 100644
--- a/askbot/management/commands/post_emailed_questions.py
+++ b/askbot/management/commands/post_emailed_questions.py
@@ -27,6 +27,7 @@ from django.utils.translation import string_concat
from django.core.urlresolvers import reverse
from askbot.conf import settings as askbot_settings
from askbot.utils import mail
+from askbot.utils import url_utils
from askbot import models
from askbot.forms import AskByEmailForm
@@ -61,7 +62,7 @@ def bounce_email(email, subject, reason = None, body_text = None):
'by email, please <a href="%(url)s">register first</a></p>'
) % {
'site': askbot_settings.APP_SHORT_NAME,
- 'url': askbot_settings.APP_URL + reverse('user_signin')
+ 'url': url_utils.get_login_url()
}
elif reason == 'permission_denied':
error_message = _(
diff --git a/askbot/management/commands/send_email_alerts.py b/askbot/management/commands/send_email_alerts.py
index 53a5db46..f92aff63 100644
--- a/askbot/management/commands/send_email_alerts.py
+++ b/askbot/management/commands/send_email_alerts.py
@@ -388,7 +388,7 @@ class Command(NoArgsCommand):
#does not change the database, only sends the email
#todo: move this to template
for user in User.objects.all():
- user.add_missing_subscriptions()
+ user.add_missing_askbot_subscriptions()
#todo: q_list is a dictionary, not a list
q_list = self.get_updated_questions_for_user(user)
if len(q_list.keys()) == 0:
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py
index e4a1280e..3afcefef 100644
--- a/askbot/models/__init__.py
+++ b/askbot/models/__init__.py
@@ -861,6 +861,37 @@ def user_post_comment(
)
return comment
+def user_post_anonymous_askbot_content(user, session_key):
+ """posts any posts added just before logging in
+ the posts are identified by the session key, thus the second argument
+
+ this function is used by the signal handler with a similar name
+ """
+ aq_list = AnonymousQuestion.objects.filter(session_key = session_key)
+ aa_list = AnonymousAnswer.objects.filter(session_key = session_key)
+ #from askbot.conf import settings as askbot_settings
+ if askbot_settings.EMAIL_VALIDATION == True:#add user to the record
+ for aq in aq_list:
+ aq.author = user
+ aq.save()
+ for aa in aa_list:
+ aa.author = user
+ aa.save()
+ #maybe add pending posts message?
+ else:
+ if user.is_blocked():
+ msg = _('blocked users cannot post')
+ user.message_set.create(message = msg)
+ elif user.is_suspended():
+ msg = _('suspended users cannot post')
+ user.message_set.create(message = msg)
+ else:
+ for aq in aq_list:
+ aq.publish(user)
+ for aa in aa_list:
+ aa.publish(user)
+
+
def user_mark_tags(
self,
tagnames = None,
@@ -1320,7 +1351,7 @@ def user_set_admin_status(self):
self.is_staff = True
self.is_superuser = True
-def user_add_missing_subscriptions(self):
+def user_add_missing_askbot_subscriptions(self):
from askbot import forms#need to avoid circular dependency
form = forms.EditUserEmailFeedsForm()
need_feed_types = form.get_db_model_subscription_type_names()
@@ -1865,7 +1896,10 @@ def user_update_wildcard_tag_selections(
return new_tags
-User.add_to_class('add_missing_subscriptions', user_add_missing_subscriptions)
+User.add_to_class(
+ 'add_missing_askbot_subscriptions',
+ user_add_missing_askbot_subscriptions
+)
User.add_to_class('is_username_taken',classmethod(user_is_username_taken))
User.add_to_class(
'get_followed_question_alert_frequency',
@@ -1885,6 +1919,10 @@ User.add_to_class('edit_question', user_edit_question)
User.add_to_class('retag_question', user_retag_question)
User.add_to_class('post_answer', user_post_answer)
User.add_to_class('edit_answer', user_edit_answer)
+User.add_to_class(
+ 'post_anonymous_askbot_content',
+ user_post_anonymous_askbot_content
+)
User.add_to_class('post_comment', user_post_comment)
User.add_to_class('edit_comment', user_edit_comment)
User.add_to_class('delete_post', user_delete_post)
@@ -2384,7 +2422,7 @@ def complete_pending_tag_subscriptions(sender, request, *args, **kwargs):
message = _('Your tag subscription was saved, thanks!')
)
-def post_stored_anonymous_content(
+def post_anonymous_askbot_content(
sender,
request,
user,
@@ -2392,30 +2430,10 @@ def post_stored_anonymous_content(
signal,
*args,
**kwargs):
-
- aq_list = AnonymousQuestion.objects.filter(session_key = session_key)
- aa_list = AnonymousAnswer.objects.filter(session_key = session_key)
- #from askbot.conf import settings as askbot_settings
- if askbot_settings.EMAIL_VALIDATION == True:#add user to the record
- for aq in aq_list:
- aq.author = user
- aq.save()
- for aa in aa_list:
- aa.author = user
- aa.save()
- #maybe add pending posts message?
- else:
- if user.is_blocked():
- msg = _('blocked users cannot post')
- user.message_set.create(message = msg)
- elif user.is_suspended():
- msg = _('suspended users cannot post')
- user.message_set.create(message = msg)
- else:
- for aq in aq_list:
- aq.publish(user)
- for aa in aa_list:
- aa.publish(user)
+ """signal handler, unfortunately extra parameters
+ are necessary for the signal machinery, even though
+ they are not used in this function"""
+ user.post_anonymous_askbot_content(session_key)
def set_user_has_custom_avatar_flag(instance, created, **kwargs):
instance.user.update_has_custom_avatar()
@@ -2453,8 +2471,8 @@ signals.flag_offensive.connect(record_flag_offensive, sender=Question)
signals.flag_offensive.connect(record_flag_offensive, sender=Answer)
signals.tags_updated.connect(record_update_tags)
signals.user_updated.connect(record_user_full_updated, sender=User)
-signals.user_logged_in.connect(post_stored_anonymous_content)
-signals.user_logged_in.connect(complete_pending_tag_subscriptions)
+signals.user_logged_in.connect(complete_pending_tag_subscriptions)#todo: add this to fake onlogin middleware
+signals.user_logged_in.connect(post_anonymous_askbot_content)
signals.post_updated.connect(
record_post_update_activity,
sender=Comment
diff --git a/askbot/skins/default/templates/authopenid/complete.html b/askbot/skins/default/templates/authopenid/complete.html
index 40ec4ccc..969a173f 100644
--- a/askbot/skins/default/templates/authopenid/complete.html
+++ b/askbot/skins/default/templates/authopenid/complete.html
@@ -52,7 +52,7 @@ parameters:
{% elif login_type=='facebook' %}
<form name="fregister" action="" method="POST">{% csrf_token %}
{% else %}
- <form name="fregister" action="{% url user_signin %}" method="POST">{% csrf_token %}
+ <form name="fregister" action="{{ settings.LOGIN_URL }}" method="POST">{% csrf_token %}
{% endif %}
{{ openid_register_form.next }}
<div class="form-row-vertical">
diff --git a/askbot/skins/default/templates/authopenid/signin.html b/askbot/skins/default/templates/authopenid/signin.html
index 4cbd905a..5cff194b 100644
--- a/askbot/skins/default/templates/authopenid/signin.html
+++ b/askbot/skins/default/templates/authopenid/signin.html
@@ -46,7 +46,7 @@
<p class="warning">{{ openid_error_message }}</p>
{% endif %}
{% if view_subtype != 'email_sent' and view_subtype != 'bad_key' %}
- <form id="signin-form" method="post" action="{% url user_signin %}">{% csrf_token %}
+ <form id="signin-form" method="post" action="{{ settings.LOGIN_URL }}">{% csrf_token %}
{# in this branch - the real signin view we display the login icons
here we hide the local login button only if admin
wants to always show the password login form - then
diff --git a/askbot/skins/default/templates/authopenid/signup_with_password.html b/askbot/skins/default/templates/authopenid/signup_with_password.html
index b5680806..047ff076 100644
--- a/askbot/skins/default/templates/authopenid/signup_with_password.html
+++ b/askbot/skins/default/templates/authopenid/signup_with_password.html
@@ -8,7 +8,7 @@
{% block content %}
{% if settings.PASSWORD_REGISTER_SHOW_PROVIDER_BUTTONS == True %}
<h1>{% trans %}Please register by clicking on any of the icons below{% endtrans %}</h1>
- <form id="signin-form" method="post" action="{% url user_signin %}">{% csrf_token %}
+ <form id="signin-form" method="post" action="{{ settings.LOGIN_URL }}">{% csrf_token %}
{# hide_local_login == True because it is password reg form #}
{{
login_macros.provider_buttons(
@@ -47,7 +47,7 @@
<div class="submit-row"><input type="submit" class="submit" value="{% trans %}Create Account{% endtrans %}" />
{% if settings.PASSWORD_REGISTER_SHOW_PROVIDER_BUTTONS == False %}
<strong>{% trans %}or{% endtrans %}
- <a href="{% url user_signin %}">{% trans %}return to OpenID login{% endtrans %}</a></strong>
+ <a href="{{ settings.LOGIN_URL }}">{% trans %}return to OpenID login{% endtrans %}</a></strong>
{% endif %}
</div>
</form>
diff --git a/askbot/skins/default/templates/blocks/bottom_scripts.html b/askbot/skins/default/templates/blocks/bottom_scripts.html
index b5b88bce..aaad70c0 100644
--- a/askbot/skins/default/templates/blocks/bottom_scripts.html
+++ b/askbot/skins/default/templates/blocks/bottom_scripts.html
@@ -22,7 +22,7 @@
askbot['urls']['get_tag_list'] = '{% url "get_tag_list" %}';
askbot['urls']['follow_user'] = scriptUrl + 'followit/follow/user/{{'{{'}}userId{{'}}'}}/';
askbot['urls']['unfollow_user'] = scriptUrl + 'followit/unfollow/user/{{'{{'}}userId{{'}}'}}/';
- askbot['urls']['user_signin'] = '{% url "user_signin" %}';
+ askbot['urls']['user_signin'] = '{{ settings.LOGIN_URL }}';
</script>
<script
type="text/javascript"
diff --git a/askbot/skins/default/templates/blocks/header_meta_links.html b/askbot/skins/default/templates/blocks/header_meta_links.html
index bbc87c0f..83a5ed55 100644
--- a/askbot/skins/default/templates/blocks/header_meta_links.html
+++ b/askbot/skins/default/templates/blocks/header_meta_links.html
@@ -5,9 +5,9 @@
{{ macros.moderation_items_link(request.user, moderation_items) }}
({{ macros.user_long_score_and_badge_summary(user) }})
</span>
- <a href="{% url user_signout %}?next={% url logout %}">{% trans %}logout{% endtrans %}</a>
+ <a href="{{ settings.LOGOUT_URL }}?next={{ settings.LOGOUT_REDIRECT_URL }}">{% trans %}logout{% endtrans %}</a>
{% else %}
- <a href="{% url user_signin %}">{% trans %}login{% endtrans %}</a>
+ <a href="{{ settings.LOGIN_URL }}">{% trans %}login{% endtrans %}</a>
{% endif %}
<a href="{% url about %}">{% trans %}about{% endtrans %}</a>
<a href="{% url faq %}">{% trans %}faq{% endtrans %}</a>
diff --git a/askbot/skins/default/templates/faq.html b/askbot/skins/default/templates/faq.html
index 74d5b0ef..0f992934 100644
--- a/askbot/skins/default/templates/faq.html
+++ b/askbot/skins/default/templates/faq.html
@@ -71,7 +71,7 @@
{% trans %}gravatar faq info{% endtrans %}
<h2>{% trans %}To register, do I need to create new password?{% endtrans %}</h2>
<p>{% trans %}No, you don't have to. You can login through any service that supports OpenID, e.g. Google, Yahoo, AOL, etc."{% endtrans %}
-<strong><a href="{% url user_signin %}">{% trans %}"Login now!"{% endtrans %}</a> »</strong>
+<strong><a href="{{ settings.LOGIN_URL }}">{% trans %}"Login now!"{% endtrans %}</a> »</strong>
</p>
<h2>{% trans %}Why other people can edit my questions/answers?{% endtrans %}</h2>
<p> {% trans %}Goal of this site is...{% endtrans %} {% trans %}So questions and answers can be edited like wiki pages by experienced users of this site and this improves the overall quality of the knowledge base content.{% endtrans %}
diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html
index 7bc31373..00481e61 100644
--- a/askbot/skins/default/templates/question.html
+++ b/askbot/skins/default/templates/question.html
@@ -432,7 +432,7 @@
askbot['urls']['deleteComment'] = '{% url delete_comment %}';
askbot['urls']['getComment'] = '{% url get_comment %}';
askbot['urls']['question_url_template'] = scriptUrl + '{% trans %}question/{% endtrans %}{{ "{{QuestionID}}/{{questionSlug}}" }}';{# yes it needs to be that whacky #}
- askbot['urls']['user_signin'] = '{% url user_signin %}';
+ askbot['urls']['user_signin'] = '{{ settings.LOGIN_URL }}';
askbot['urls']['vote_url_template'] = scriptUrl + '{% trans %}questions/{% endtrans %}{{ "{{QuestionID}}/" }}{% trans %}vote/{% endtrans %}';
askbot['messages']['addComment'] = '{% trans %}add comment{% endtrans %}';
{% if settings.SAVE_COMMENT_ON_ENTER %}
@@ -459,7 +459,7 @@
{% if not question.closed and request.user.is_authenticated %}initEditor();{% endif %}
lanai.highlightSyntax();
- $('#btLogin').bind('click', function(){window.location.href='{% url user_signin %}'; } )
+ $('#btLogin').bind('click', function(){window.location.href='{{ settings.LOGIN_URL }}'; } )
});
function initEditor(){
diff --git a/askbot/skins/default/templates/user_profile/user_info.html b/askbot/skins/default/templates/user_profile/user_info.html
index a9c50a13..36b782e5 100644
--- a/askbot/skins/default/templates/user_profile/user_info.html
+++ b/askbot/skins/default/templates/user_profile/user_info.html
@@ -36,7 +36,7 @@
{% trans %}update profile{% endtrans %}
</a>
{% if request.user == view_user and settings.ALLOW_ADD_REMOVE_LOGIN_METHODS %}
- | <a href="{% url user_signin %}?next={% url user_signin %}">
+ | <a href="{{ settings.LOGIN_URL }}?next={{ settings.LOGIN_URL }}">
{% trans %}manage login methods{% endtrans %}
</a>
{% endif %}
diff --git a/askbot/tests/email_alert_tests.py b/askbot/tests/email_alert_tests.py
index 02eaf437..10113446 100644
--- a/askbot/tests/email_alert_tests.py
+++ b/askbot/tests/email_alert_tests.py
@@ -877,7 +877,7 @@ class EmailFeedSettingTests(utils.AskbotTestCase):
def test_add_missings_subscriptions_noop(self):
data_before = TO_JSON(self.get_user_feeds())
- self.user.add_missing_subscriptions()
+ self.user.add_missing_askbot_subscriptions()
data_after = TO_JSON(self.get_user_feeds())
self.assertEquals(data_before, data_after)
@@ -885,7 +885,7 @@ class EmailFeedSettingTests(utils.AskbotTestCase):
feed = self.get_user_feeds().filter(feed_type = 'q_all')
feed.delete()
count_before = self.get_user_feeds().count()
- self.user.add_missing_subscriptions()
+ self.user.add_missing_askbot_subscriptions()
count_after = self.get_user_feeds().count()
self.assertEquals(count_after - count_before, 1)
diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py
index df0c23fa..36f65c71 100644
--- a/askbot/tests/page_load_tests.py
+++ b/askbot/tests/page_load_tests.py
@@ -75,7 +75,6 @@ class PageLoadTests(PageLoadTestCase):
self.try_url('about', template='about.html')
self.try_url('privacy', template='privacy.html')
self.try_url('logout', template='authopenid/logout.html')
- self.try_url('user_signin', template='authopenid/signin.html')
#todo: test different tabs
self.try_url('tags', template='tags.html')
self.try_url('tags', data={'sort':'name'}, template='tags.html')
diff --git a/askbot/urls.py b/askbot/urls.py
index ae6e7156..c962017e 100644
--- a/askbot/urls.py
+++ b/askbot/urls.py
@@ -2,14 +2,14 @@
askbot askbot url configuraion file
"""
import os.path
+from django.conf import settings
from django.conf.urls.defaults import url, patterns, include
from django.conf.urls.defaults import handler500, handler404
from django.contrib import admin
+from django.utils.translation import ugettext as _
from askbot import views
from askbot.feed import RssLastestQuestionsFeed
from askbot.sitemap import QuestionsSitemap
-from django.utils.translation import ugettext as _
-from django.conf import settings
admin.autodiscover()
feeds = {
diff --git a/askbot/utils/url_utils.py b/askbot/utils/url_utils.py
new file mode 100644
index 00000000..e32a26a5
--- /dev/null
+++ b/askbot/utils/url_utils.py
@@ -0,0 +1,32 @@
+from django.core.urlresolvers import reverse
+from django.conf import settings
+
+def get_login_url():
+ """returns internal login url if
+ django_authopenid is used, or
+ the corresponding django setting
+ """
+ if 'askbot.deps.django_authopenid' in settings.INSTALLED_APPS:
+ return reverse('user_signin')
+ else:
+ return settings.LOGIN_URL
+
+def get_logout_url():
+ """returns internal logout url
+ if django_authopenid is used or
+ the django setting"""
+ if 'askbot.deps.django_authopenid' in settings.INSTALLED_APPS:
+ return reverse('user_signout')
+ else:
+ return settings.LOGOUT_URL
+
+def get_logout_redirect_url():
+ """returns internal logout redirect url,
+ or settings.LOGOUT_REDIRECT_URL if it exists
+ or url to the main page"""
+ if 'askbot.deps.django_authopenid' in settings.INSTALLED_APPS:
+ return reverse('logout')
+ elif hasattr(settings, LOGOUT_REDIRECT_URL):
+ return settigs.LOGOUT_REDIRECT_URL
+ else:
+ return reverse('index')
diff --git a/askbot/views/commands.py b/askbot/views/commands.py
index a7a6de4f..9b9e7af5 100644
--- a/askbot/views/commands.py
+++ b/askbot/views/commands.py
@@ -20,6 +20,7 @@ from askbot import forms
from askbot.conf import should_show_sort_by_relevance
from askbot.conf import settings as askbot_settings
from askbot.utils import decorators
+from askbot.utils import url_utils
from askbot.skins.loaders import render_into_skin
from askbot import const
import logging
@@ -410,7 +411,7 @@ def subscribe_for_tags(request):
% {'tags': ', '.join(all_tag_names)}
request.user.message_set.create(message = message)
request.session['subscribe_for_tags'] = (pure_tag_names, wildcards)
- return HttpResponseRedirect(reverse('user_signin'))
+ return HttpResponseRedirect(url_utils.get_login_url())
@decorators.get_only
diff --git a/askbot/views/writers.py b/askbot/views/writers.py
index d1f115dc..6bc878b4 100644
--- a/askbot/views/writers.py
+++ b/askbot/views/writers.py
@@ -29,6 +29,7 @@ from askbot import models
from askbot.skins.loaders import render_into_skin
from askbot.utils.decorators import ajax_only
from askbot.utils.functions import diff_date
+from askbot.utils import url_utils
from askbot.templatetags import extra_filters_jinja as template_filters
from askbot.importers.stackexchange import management as stackexchange#todo: may change
@@ -238,7 +239,7 @@ def ask(request):#view used to ask a new question
ip_addr = request.META['REMOTE_ADDR'],
)
question.save()
- return HttpResponseRedirect(reverse('user_signin_new_question'))
+ return HttpResponseRedirect(url_utils.get_login_url())
else:
#this branch is for the initial load of ask form
form = forms.AskForm()
@@ -500,7 +501,7 @@ def answer(request, id):#process a new answer
ip_addr=request.META['REMOTE_ADDR'],
)
anon.save()
- return HttpResponseRedirect(reverse('user_signin_new_answer'))
+ return HttpResponseRedirect(url_utils.get_login_url())
return HttpResponseRedirect(question.get_absolute_url())
@@ -563,7 +564,7 @@ def post_comments(request):#non-view generic ajax handler to load comments to an
msg = _('Sorry, you appear to be logged out and '
'cannot post comments. Please '
'<a href="%(sign_in_url)s">sign in</a>.') % \
- {'sign_in_url': reverse('user_signin')}
+ {'sign_in_url': url_utils.get_login_url()}
raise exceptions.PermissionDenied(msg)
user.post_comment(
parent_post = obj,
@@ -616,7 +617,7 @@ def delete_comment(request):
msg = _('Sorry, you appear to be logged out and '
'cannot delete comments. Please '
'<a href="%(sign_in_url)s">sign in</a>.') % \
- {'sign_in_url': reverse('user_signin')}
+ {'sign_in_url': url_utils.get_login_url()}
raise exceptions.PermissionDenied(msg)
if request.is_ajax():