diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-06-05 15:57:35 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-06-05 15:57:35 -0400 |
commit | 29c9b69c2e032245a4c21b795581035bb5746323 (patch) | |
tree | acdae7842a5524abef9c665a7367c9f62cec2374 | |
parent | a16d90151874954a8824c1b9495392f599b70705 (diff) | |
download | askbot-29c9b69c2e032245a4c21b795581035bb5746323.tar.gz askbot-29c9b69c2e032245a4c21b795581035bb5746323.tar.bz2 askbot-29c9b69c2e032245a4c21b795581035bb5746323.zip |
support for alternative login apps finished
-rw-r--r-- | askbot/__init__.py | 2 | ||||
-rw-r--r-- | askbot/conf/user_settings.py | 2 | ||||
-rw-r--r-- | askbot/doc/source/askbot-as-django-application.rst | 42 | ||||
-rwxr-xr-x | askbot/skins/default/media/style/style.css | 29 | ||||
-rw-r--r-- | askbot/skins/default/templates/macros.html | 4 | ||||
-rw-r--r-- | askbot/skins/default/templates/question.html | 84 | ||||
-rw-r--r-- | askbot/urls.py | 6 | ||||
-rw-r--r-- | askbot/utils/decorators.py | 30 | ||||
-rw-r--r-- | askbot/utils/url_utils.py | 2 | ||||
-rw-r--r-- | askbot/views/users.py | 2 | ||||
-rw-r--r-- | askbot/views/writers.py | 7 |
11 files changed, 145 insertions, 65 deletions
diff --git a/askbot/__init__.py b/askbot/__init__.py index b9d00956..faf86796 100644 --- a/askbot/__init__.py +++ b/askbot/__init__.py @@ -9,7 +9,7 @@ import smtplib import sys import logging -VERSION = (0, 6, 92) +VERSION = (0, 6, 93) #necessary for interoperability of django and coffin try: diff --git a/askbot/conf/user_settings.py b/askbot/conf/user_settings.py index 77afa23b..73141ee4 100644 --- a/askbot/conf/user_settings.py +++ b/askbot/conf/user_settings.py @@ -7,7 +7,7 @@ from django.utils.translation import ugettext as _ USER_SETTINGS = livesettings.ConfigurationGroup( 'USER_SETTINGS', - _('User policy settings') + _('User settings') ) settings.register( diff --git a/askbot/doc/source/askbot-as-django-application.rst b/askbot/doc/source/askbot-as-django-application.rst index 09c0a81e..d4072628 100644 --- a/askbot/doc/source/askbot-as-django-application.rst +++ b/askbot/doc/source/askbot-as-django-application.rst @@ -14,24 +14,34 @@ 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 +Just remove ``'askbot.deps.django_authopenid'`` +from the ``INSTALLED_APPS``, +remove ``'askbot.deps.django_authopenid.backends.AuthBackend'`` +from the ``AUTHENTICATION_BACKENDS``, +install another registration app +and modify ``LOGIN_URL`` accordingly. + +There are three caveats. + +Firstly, if you are using some other login/registration app, +please disable feature +"settings"->"data entry and display"->"allow posting before logging in". + +This may be fixed in the future by adding a snippet of code to run +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 complete automatically when certain pages +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:: diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css index 24b01672..a3a4f079 100755 --- a/askbot/skins/default/media/style/style.css +++ b/askbot/skins/default/media/style/style.css @@ -48,6 +48,25 @@ a { cursor: pointer; } +/* http://pathfindersoftware.com/2007/09/developers-note-2/ */ +* html .clearfix, +* html .paginator { + height: 1; + overflow: visible; +} ++ html .clearfix, ++ html .paginator { + min-height: 1%; +} +.clearfix:after, +.paginator:after { + clear: both; + content:"."; + display:block; + height: 0; + visibility: hidden; +} + .badges a { color: #763333; text-decoration: underline; @@ -1625,10 +1644,9 @@ button::-moz-focus-inner { .submit { cursor: pointer; /*letter-spacing:1px;*/ background-color: #D4D0C8; - height: 40px; + height: 30px; border: 1px solid #777777; /* width:100px; */ font-weight: bold; - padding-bottom: 4px; font-size: 120%; } @@ -1646,6 +1664,13 @@ button::-moz-focus-inner { .submit.small:hover { text-decoration:none; } +.question-page a.submit { + display: -moz-inline-stack; + display: inline-block; + line-height: 30px; + padding: 0 5px; + *display: inline; +} .ask-body { padding-right: 10px; diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html index fb3e3898..58fd986c 100644 --- a/askbot/skins/default/templates/macros.html +++ b/askbot/skins/default/templates/macros.html @@ -129,7 +129,8 @@ {%- macro paginator(p, position='left') -%}{# p is paginator context dictionary #} {% spaceless %} {% if p.is_paginated %} - <div class="paginator" style="float:{{position}}"> + <div class="paginator"> + <div style="float:{{position}}"> {% if p.has_previous %} <span class="prev"><a href="{{p.base_url}}page={{ p.previous }}{{ p.extend_url }}" title="{% trans %}previous{% endtrans %}"> « {% trans %}previous{% endtrans %}</a></span> @@ -158,6 +159,7 @@ {% if p.has_next %} <span class="next"><a href="{{p.base_url}}page={{ p.next }}{{ p.extend_url }}" title="{% trans %}next page{% endtrans %}">{% trans %}next page{% endtrans %} »</a></span> {% endif %} + </div> </div> {% endif %} {% endspaceless %} diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html index 00481e61..6b51c756 100644 --- a/askbot/skins/default/templates/question.html +++ b/askbot/skins/default/templates/question.html @@ -299,9 +299,7 @@ </table> </div> {% endfor %} - <div class="paginator-container-left"> - {{ macros.paginator(paginator_context) }} - </div><br/> + {{ macros.paginator(paginator_context) }} {% endif %} <form id="fmanswer" action="{% url answer question.id %}" method="post">{% csrf_token %} {% if request.user.is_authenticated() %} @@ -329,44 +327,53 @@ {% endif %} <div style="clear:both"> </div> - {% if not question.closed %} - <div style="padding:10px 0 0 0;"> - {% spaceless %} - <h2> - {% if answers %} - {% trans %}Your answer{% endtrans %} - {% else %} - {% trans %}Be the first one to answer this question!{% endtrans %} - {% endif %} - </h2> - {% endspaceless %} - </div> - {% if not request.user.is_authenticated() %} - <div class="message">{% trans %}you can answer anonymously and then login{% endtrans %}</div> - {% else %} - <p class="message"> - {% if request.user==question.author %} - {% trans %}answer your own question only to give an answer{% endtrans %} - {% else %} - {% trans %}please only give an answer, no discussions{% endtrans %} - {% endif %} - </p> + {% if request.user.is_anonymous() and settings.ALLOW_POSTING_BEFORE_LOGGING_IN == False %} + {% if not question.closed %} + <a + class="submit" + href="{{settings.LOGIN_URL}}?next={% url question question.id %}" + >{% trans %}Login/Signup to Answer{% endtrans %}</a> {% endif %} - {{ macros.edit_post(answer) }} - <input type="submit" - {% if user.is_anonymous() %} - value="{% trans %}Login/Signup to Post Your Answer{% endtrans %}" + {% else %} + {% if not question.closed %} + <div style="padding:10px 0 0 0;"> + {% spaceless %} + <h2> + {% if answers %} + {% trans %}Your answer{% endtrans %} + {% else %} + {% trans %}Be the first one to answer this question!{% endtrans %} + {% endif %} + </h2> + {% endspaceless %} + </div> + {% if request.user.is_anonymous() %} + <div class="message">{% trans %}you can answer anonymously and then login{% endtrans %}</div> {% else %} - {% if user == question.author %} - value="{% trans %}Answer Your Own Question{% endtrans %}" + <p class="message"> + {% if request.user==question.author %} + {% trans %}answer your own question only to give an answer{% endtrans %} + {% else %} + {% trans %}please only give an answer, no discussions{% endtrans %} + {% endif %} + </p> + {% endif %} + {{ macros.edit_post(answer) }} + <input type="submit" + {% if user.is_anonymous() %} + value="{% trans %}Login/Signup to Post Your Answer{% endtrans %}" {% else %} - value="{% trans %}Answer the question{% endtrans %}" + {% if user == question.author %} + value="{% trans %}Answer Your Own Question{% endtrans %}" + {% else %} + value="{% trans %}Answer the question{% endtrans %}" + {% endif %} {% endif %} - {% endif %} - class="submit after-editor" style="float:left"/> - {% if settings.WIKI_ON %} - {{ macros.checkbox_in_div(answer.wiki) }} - {% endif %} + class="submit after-editor" style="float:left"/> + {% if settings.WIKI_ON %} + {{ macros.checkbox_in_div(answer.wiki) }} + {% endif %} + {% endif %} {% endif %} </form> {% endblock %} @@ -460,6 +467,9 @@ lanai.highlightSyntax(); $('#btLogin').bind('click', function(){window.location.href='{{ settings.LOGIN_URL }}'; } ) + if (window.location.hash === 'fmanswer'){ + $('#fmanswer textarea').focus(); + } }); function initEditor(){ diff --git a/askbot/urls.py b/askbot/urls.py index c962017e..99ff6300 100644 --- a/askbot/urls.py +++ b/askbot/urls.py @@ -220,7 +220,6 @@ urlpatterns = patterns('', #upload url is ajax only url( r'^%s$' % _('upload/'), views.writers.upload, name='upload'), url(r'^%s$' % _('feedback/'), views.meta.feedback, name='feedback'), - (r'^%s' % _('account/'), include('askbot.deps.django_authopenid.urls')), #url(r'^feeds/rss/$', RssLastestQuestionsFeed, name="latest_questions_feed"), url( r'^doc/(?P<path>.*)$', @@ -254,6 +253,11 @@ urlpatterns = patterns('', ), ) +if 'askbot.deps.django_authopenid' in settings.INSTALLED_APPS: + urlpatterns += ( + url(r'^%s' % _('account/'), include('askbot.deps.django_authopenid.urls')), + ) + if 'avatar' in settings.INSTALLED_APPS: #unforturately we have to wire avatar urls here, #because views add and change are adapted to diff --git a/askbot/utils/decorators.py b/askbot/utils/decorators.py index 8a8d2fcf..fb093421 100644 --- a/askbot/utils/decorators.py +++ b/askbot/utils/decorators.py @@ -3,12 +3,18 @@ import time import os import datetime import functools +import inspect import logging from django.conf import settings +from django.core import exceptions as django_exceptions +from django.core import urlresolvers from django.http import HttpResponse, HttpResponseForbidden, Http404 +from django.http import HttpResponseRedirect from django.utils import simplejson +from django.utils.translation import ugettext as _ from askbot import exceptions as askbot_exceptions -from django.core import exceptions as django_exceptions +from askbot.conf import settings as askbot_settings +from askbot.utils import url_utils def auto_now_timestamp(func): """decorator that will automatically set @@ -91,6 +97,28 @@ def ajax_only(view_func): return HttpResponse(json,mimetype='application/json') return wrapper +def check_authorization_to_post(func_or_message): + + message = _('Please login to post') + if not inspect.isfunction(func_or_message): + message = unicode(func_or_message) + + def decorator(view_func): + @functools.wraps(view_func) + def wrapper(request, *args, **kwargs): + if request.user.is_anonymous(): + #todo: expand for handling ajax responses + if askbot_settings.ALLOW_POSTING_BEFORE_LOGGING_IN == False: + request.user.message_set.create(message = message) + params = 'next=%s' % request.path + return HttpResponseRedirect(url_utils.get_login_url() + '?' + params) + return view_func(request, *args, **kwargs) + return wrapper + + if inspect.isfunction(func_or_message): + return decorator(func_or_message) + else: + return decorator try: PROFILE_LOG_BASE = settings.PROFILE_LOG_BASE diff --git a/askbot/utils/url_utils.py b/askbot/utils/url_utils.py index e32a26a5..0ebce394 100644 --- a/askbot/utils/url_utils.py +++ b/askbot/utils/url_utils.py @@ -26,7 +26,7 @@ def get_logout_redirect_url(): or url to the main page""" if 'askbot.deps.django_authopenid' in settings.INSTALLED_APPS: return reverse('logout') - elif hasattr(settings, LOGOUT_REDIRECT_URL): + elif hasattr(settings, 'LOGOUT_REDIRECT_URL'): return settigs.LOGOUT_REDIRECT_URL else: return reverse('index') diff --git a/askbot/views/users.py b/askbot/views/users.py index eb478254..94b3e997 100644 --- a/askbot/views/users.py +++ b/askbot/views/users.py @@ -904,7 +904,7 @@ def user_email_subscriptions(request, user, context): #about the email subscriptions, in that case the call below #will add any subscription settings that are missing #using the default frequencies - user.add_missing_subsciptions() + user.add_missing_askbot_subscriptions() #initialize the form email_feeds_form = forms.EditUserEmailFeedsForm() diff --git a/askbot/views/writers.py b/askbot/views/writers.py index 6bc878b4..bd65fbcd 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -27,7 +27,7 @@ from django.views.decorators import csrf from askbot import forms from askbot import models from askbot.skins.loaders import render_into_skin -from askbot.utils.decorators import ajax_only +from askbot.utils import decorators from askbot.utils.functions import diff_date from askbot.utils import url_utils from askbot.templatetags import extra_filters_jinja as template_filters @@ -188,6 +188,7 @@ def import_data(request): #@login_required #actually you can post anonymously, but then must register @csrf.csrf_protect +@decorators.check_authorization_to_post(_('Please log in to ask questions')) def ask(request):#view used to ask a new question """a view to ask a new question gives space for q title, body, tags and checkbox for to post as wiki @@ -195,7 +196,6 @@ def ask(request):#view used to ask a new question user can start posting a question anonymously but then must login/register in order for the question go be shown """ - if request.method == "POST": form = forms.AskForm(request.POST) if form.is_valid(): @@ -461,6 +461,7 @@ def edit_answer(request, id): return HttpResponseRedirect(answer.get_absolute_url()) #todo: rename this function to post_new_answer +@decorators.check_authorization_to_post(_('Please log in to answer questions')) def answer(request, id):#process a new answer """view that posts new answer @@ -580,7 +581,7 @@ def post_comments(request):#non-view generic ajax handler to load comments to an else: raise Http404 -@ajax_only +@decorators.ajax_only def edit_comment(request): if request.user.is_authenticated(): comment_id = int(request.POST['comment_id']) |