summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdolfo Fitoria <adolfo.fitoria@gmail.com>2013-04-29 09:26:22 -0600
committerAdolfo Fitoria <adolfo.fitoria@gmail.com>2013-04-29 09:26:22 -0600
commit20ad12f13506435175ee55afa43181be55dfa93b (patch)
tree0e8777279a985e1751e7ce9a17e8a2b14501ba0a
parent9f986b792878bdb56108d07cd93d41bc6c85aab1 (diff)
parentdb853927d7c6adf8f89e1b0ac7d6c9f9691e0592 (diff)
downloadaskbot-20ad12f13506435175ee55afa43181be55dfa93b.tar.gz
askbot-20ad12f13506435175ee55afa43181be55dfa93b.tar.bz2
askbot-20ad12f13506435175ee55afa43181be55dfa93b.zip
Merge branch 'master' of github.com:ASKBOT/askbot-devel
-rw-r--r--askbot/conf/flatpages.py2
-rw-r--r--askbot/conf/forum_data_rules.py20
-rw-r--r--askbot/deps/django_authopenid/views.py4
-rw-r--r--askbot/deps/livesettings/templates/livesettings/group_settings.html9
-rw-r--r--askbot/deps/livesettings/templates/livesettings/site_settings.html13
-rw-r--r--askbot/doc/source/changelog.rst1
-rw-r--r--askbot/forms.py2
-rw-r--r--askbot/media/js/post.js20
-rw-r--r--askbot/media/style/style.css15
-rw-r--r--askbot/media/style/style.less15
-rw-r--r--askbot/models/post.py5
-rw-r--r--askbot/setup_templates/settings.py1
-rw-r--r--askbot/setup_templates/settings.py.mustache1
-rw-r--r--askbot/startup_procedures.py3
-rw-r--r--askbot/templates/ask.html8
-rw-r--r--askbot/templates/ask_by_widget.html14
-rw-r--r--askbot/templates/email/notify_author_about_approved_post.html1
-rw-r--r--askbot/templates/widgets/ask_form.html38
-rw-r--r--askbot/templates/widgets/edit_post.html2
-rw-r--r--askbot/templatetags/extra_filters_jinja.py13
-rw-r--r--askbot/tests/page_load_tests.py44
-rw-r--r--askbot/utils/forms.py4
-rw-r--r--askbot/utils/functions.py28
-rw-r--r--askbot/utils/html.py5
-rw-r--r--askbot/views/meta.py7
-rw-r--r--askbot/views/readers.py23
-rw-r--r--askbot/views/users.py7
27 files changed, 204 insertions, 101 deletions
diff --git a/askbot/conf/flatpages.py b/askbot/conf/flatpages.py
index 60106f6f..9a705b5a 100644
--- a/askbot/conf/flatpages.py
+++ b/askbot/conf/flatpages.py
@@ -71,7 +71,7 @@ settings.register(#this field is not editable manually
FLATPAGES,
'CATEGORY_TREE',
description = 'Category tree',#no need to translate
- default = '',#empty array of arrays in json
+ default = '[["dummy",[]]]',#empty array of arrays in json
help_text=_('Do not edit this field manually!!!')
#hidden = True
)
diff --git a/askbot/conf/forum_data_rules.py b/askbot/conf/forum_data_rules.py
index 96cb0ea0..421bbad7 100644
--- a/askbot/conf/forum_data_rules.py
+++ b/askbot/conf/forum_data_rules.py
@@ -110,6 +110,26 @@ settings.register(
)
)
+QUESTION_BODY_EDITOR_MODE_CHOICES = (
+ ('open', _('Fully open by default')),
+ ('folded', _('Folded by default'))
+)
+
+settings.register(
+ livesettings.StringValue(
+ FORUM_DATA_RULES,
+ 'QUESTION_BODY_EDITOR_MODE',
+ choices=QUESTION_BODY_EDITOR_MODE_CHOICES,
+ default='open',
+ description=_('Question details/body editor should be'),
+ help_text =_(
+ 'To use folded mode, please first set minimum '
+ 'question body length to 0. Also - please make tags '
+ 'optional.'
+ )
+ )
+)
+
settings.register(
livesettings.BooleanValue(
FORUM_DATA_RULES,
diff --git a/askbot/deps/django_authopenid/views.py b/askbot/deps/django_authopenid/views.py
index a3762dbb..df6347f0 100644
--- a/askbot/deps/django_authopenid/views.py
+++ b/askbot/deps/django_authopenid/views.py
@@ -31,7 +31,7 @@
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import datetime
-from django.http import HttpResponseRedirect, get_host, Http404
+from django.http import HttpResponseRedirect, Http404
from django.http import HttpResponse
from django.http import HttpResponseBadRequest
from django.template import RequestContext, Context
@@ -180,7 +180,7 @@ def get_url_host(request):
protocol = 'https'
else:
protocol = 'http'
- host = escape(get_host(request))
+ host = escape(request.get_host())
return '%s://%s' % (protocol, host)
def get_full_url(request):
diff --git a/askbot/deps/livesettings/templates/livesettings/group_settings.html b/askbot/deps/livesettings/templates/livesettings/group_settings.html
index 8c13a48d..924f9309 100644
--- a/askbot/deps/livesettings/templates/livesettings/group_settings.html
+++ b/askbot/deps/livesettings/templates/livesettings/group_settings.html
@@ -1,11 +1,12 @@
{% extends "admin/base_site.html" %}
-{% load i18n admin_modify config_tags %}
+{% load i18n admin_modify config_tags static %}
+{% load url from future %}
{% block extrastyle %}
{{ block.super }}
-<link rel="stylesheet" type="text/css" href="{% load adminmedia %}{% admin_media_prefix %}css/base.css" />
+<link rel="stylesheet" type="text/css" href="{% static "admin/css/base.css" %}" />
{% endblock %}
-{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/forms.css{% endblock %}
+{% block stylesheet %}{% static "admin/css/forms.css" %}{% endblock %}
{% block coltype %}colMS{% endblock %}
{% block bodyclass %}dashboard{% endblock %}
{% block userlinks %}<a href="/admin/doc/">{% trans 'Documentation' %}</a> / <a href="/admin/password_change/">{% trans 'Change password' %}</a> / <a href="/admin/logout/">{% trans 'Log out' %}</a>{% endblock %}
@@ -73,7 +74,7 @@
{% ifequal g.key group.key %}
<li><b>{{g.name}}</b></li>
{% else %}
- <li><a href="{% url group_settings g.key %}">{{g.name}}</a></li>
+ <li><a href="{% url "group_settings" g.key %}">{{g.name}}</a></li>
{% endifequal %}
{% endif %}
{% endfor %}
diff --git a/askbot/deps/livesettings/templates/livesettings/site_settings.html b/askbot/deps/livesettings/templates/livesettings/site_settings.html
index 35333778..13d8ea40 100644
--- a/askbot/deps/livesettings/templates/livesettings/site_settings.html
+++ b/askbot/deps/livesettings/templates/livesettings/site_settings.html
@@ -1,15 +1,16 @@
{% extends "admin/base_site.html" %}
-{% load i18n admin_modify config_tags %}
+{% load i18n admin_modify config_tags static %}
+{% load url from future %}
-{% block stylesheet %}{% load adminmedia %}{% admin_media_prefix %}css/forms.css{% endblock %}
+{% block stylesheet %}{% static "admin/css/forms.css" %}{% endblock %}
{% block extrahead %}
-<script type="text/javascript" src="{% url admin:jsi18n %}"></script>
-<script type="text/javascript" src="{% admin_media_prefix %}js/core.js"></script>
-<script type="text/javascript" src="{% admin_media_prefix %}js/admin/CollapsedFieldsets.js"></script>
+<script type="text/javascript" src="{% url "admin:jsi18n" %}"></script>
+<script type="text/javascript" src="{% static "admin/js/core.js" %}"></script>
+<script type="text/javascript" src="{% static "admin/js/CollapsedFieldsets.js" %}"></script>
{% endblock %}
{% block extrastyle %}
{{ block.super }}
-<link rel="stylesheet" type="text/css" href="{% load adminmedia %}{% admin_media_prefix %}css/base.css" />
+<link rel="stylesheet" type="text/css" href="{% static "admin/css/base.css" %}" />
<style type="text/css">
ul.fieldref { margin: 0; padding: 0; font-size: 9px; }
ul.fieldref li { float: left; margin: 0 10px 0 0; list-style: none; }
diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst
index faedeebf..38153404 100644
--- a/askbot/doc/source/changelog.rst
+++ b/askbot/doc/source/changelog.rst
@@ -3,6 +3,7 @@ Changes in Askbot
Development version
-------------------
+* Support for Django 1.5
* Auto-tweet option for questions and answers
* Added Chech and Croatian translations
* Disable/enable best answer feature
diff --git a/askbot/forms.py b/askbot/forms.py
index 1eaf3cbe..39a390be 100644
--- a/askbot/forms.py
+++ b/askbot/forms.py
@@ -1134,7 +1134,7 @@ class AnswerForm(PostAsSomeoneForm, PostPrivatelyForm):
#People can override this function to save their additional fields to db
def save(self, question, user):
- wiki = self.cleaned_data['wiki'],
+ wiki = self.cleaned_data['wiki']
text = self.cleaned_data['text']
follow = self.cleaned_data['email_notify']
is_private = self.cleaned_data['post_privately']
diff --git a/askbot/media/js/post.js b/askbot/media/js/post.js
index c8f802a7..7b18e7f1 100644
--- a/askbot/media/js/post.js
+++ b/askbot/media/js/post.js
@@ -2569,6 +2569,10 @@ FoldedEditor.prototype.getEditor = function() {
return this._editor;
};
+FoldedEditor.prototype.getEditorInputId = function() {
+ return this._element.find('textarea').attr('id');
+};
+
FoldedEditor.prototype.onAfterOpenHandler = function() {
var editor = this.getEditor();
if (editor) {
@@ -2579,15 +2583,28 @@ FoldedEditor.prototype.onAfterOpenHandler = function() {
FoldedEditor.prototype.getOpenHandler = function() {
var editorBox = this._editorBox;
var promptBox = this._prompt;
+ var externalTrigger = this._externalTrigger;
var me = this;
return function() {
promptBox.hide();
editorBox.show();
me.getElement().addClass('unfolded');
me.onAfterOpenHandler();
+
+ if (externalTrigger) {
+ var label = me.makeElement('label');
+ label.html(externalTrigger.html());
+ //set what the label is for
+ label.attr('for', me.getEditorInputId());
+ externalTrigger.replaceWith(label);
+ }
};
};
+FoldedEditor.prototype.setExternalTrigger = function(element) {
+ this._externalTrigger = element;
+};
+
FoldedEditor.prototype.decorate = function(element) {
this._element = element;
this._prompt = element.find('.prompt');
@@ -2607,6 +2624,9 @@ FoldedEditor.prototype.decorate = function(element) {
var openHandler = this.getOpenHandler();
element.click(openHandler);
element.focus(openHandler);
+ if (this._externalTrigger) {
+ this._externalTrigger.click(openHandler);
+ }
};
/**
diff --git a/askbot/media/style/style.css b/askbot/media/style/style.css
index 5610ed0e..c98e6e36 100644
--- a/askbot/media/style/style.css
+++ b/askbot/media/style/style.css
@@ -839,7 +839,7 @@ body.anon.ask-page .search-drop-menu {
/* ----- Sidebar Widgets Box, check main_page/sidebar.html or question/sidebar.html ----- */
.box {
background: #fff;
- padding: 4px 0px 10px 1px;
+ padding: 4px 0px 10px 0px;
width: 100%;
overflow: hidden;
box-sizing: border-box;
@@ -1634,7 +1634,10 @@ ul#related-tags li {
-webkit-box-sizing: border-box;
}
.ask-page #askFormBar {
- padding: 0 0 10px 0;
+ padding: 0 0 6px 0;
+}
+.ask-page .checkbox {
+ margin: 0;
}
.ask-page div#question-list,
.edit-question-page div#question-list {
@@ -1831,8 +1834,16 @@ ul#related-tags li {
margin: 5px 8px;
display: block;
}
+.ask-page .folded-editor {
+ border: none;
+ height: 0;
+}
.folded-editor.unfolded {
border: none;
+ height: auto;
+}
+.folded-editor.unfolded .editor-proper {
+ display: block;
}
.wmd-container {
border: #cce6ec 3px solid;
diff --git a/askbot/media/style/style.less b/askbot/media/style/style.less
index 0293d12f..03205f4e 100644
--- a/askbot/media/style/style.less
+++ b/askbot/media/style/style.less
@@ -870,7 +870,7 @@ body.anon.ask-page .search-drop-menu {
.box {
background: #fff;
- padding: 4px 0px 10px 1px;
+ padding: 4px 0px 10px 0px;
width: 100%;
overflow: hidden;
box-sizing: border-box;
@@ -1736,7 +1736,10 @@ ul#related-tags li {
.ask-page {
#askFormBar {
- padding: 0 0 10px 0;
+ padding: 0 0 6px 0;
+ }
+ .checkbox {
+ margin: 0;
}
}
@@ -1936,8 +1939,16 @@ ul#related-tags li {
display: block;
}
}
+.ask-page .folded-editor {
+ border: none;
+ height: 0;
+}
.folded-editor.unfolded {
border: none;
+ height: auto;
+ .editor-proper {
+ display: block;
+ }
}
.wmd-container {
diff --git a/askbot/models/post.py b/askbot/models/post.py
index 2f410b27..6b5055de 100644
--- a/askbot/models/post.py
+++ b/askbot/models/post.py
@@ -866,11 +866,8 @@ class Post(models.Model):
def __unicode__(self):
if self.is_question():
return self.thread.title
- elif self.is_answer() or self.is_reject_reason():
+ else:
return self.html
- elif self.is_comment():
- return self.text
- raise NotImplementedError
def save(self, *args, **kwargs):
if self.is_answer() and self.is_anonymous:
diff --git a/askbot/setup_templates/settings.py b/askbot/setup_templates/settings.py
index 0dcaa23f..258a5989 100644
--- a/askbot/setup_templates/settings.py
+++ b/askbot/setup_templates/settings.py
@@ -307,4 +307,5 @@ if 'ASKBOT_CSS_DEVEL' in locals() and ASKBOT_CSS_DEVEL == True:
)
COMPRESS_JS_FILTERS = []
+COMPRESS_PARSER = 'compressor.parser.HtmlParser'
JINJA2_EXTENSIONS = ('compressor.contrib.jinja2ext.CompressorExtension',)
diff --git a/askbot/setup_templates/settings.py.mustache b/askbot/setup_templates/settings.py.mustache
index afd752fa..f3c0a35b 100644
--- a/askbot/setup_templates/settings.py.mustache
+++ b/askbot/setup_templates/settings.py.mustache
@@ -303,4 +303,5 @@ if 'ASKBOT_CSS_DEVEL' in locals() and ASKBOT_CSS_DEVEL == True:
)
COMPRESS_JS_FILTERS = []
+COMPRESS_PARSER = 'compressor.parser.HtmlParser'
JINJA2_EXTENSIONS = ('compressor.contrib.jinja2ext.CompressorExtension',)
diff --git a/askbot/startup_procedures.py b/askbot/startup_procedures.py
index 2c8b1eb4..621c9e8b 100644
--- a/askbot/startup_procedures.py
+++ b/askbot/startup_procedures.py
@@ -356,7 +356,8 @@ class SettingsTester(object):
* required_value (optional)
* error_message
"""
- self.settings = load_module(os.environ['DJANGO_SETTINGS_MODULE'])
+ settings_module = os.environ['DJANGO_SETTINGS_MODULE']
+ self.settings = load_module(settings_module.encode('utf-8'))
self.messages = list()
self.requirements = requirements
diff --git a/askbot/templates/ask.html b/askbot/templates/ask.html
index 030780f6..4a20d864 100644
--- a/askbot/templates/ask.html
+++ b/askbot/templates/ask.html
@@ -61,6 +61,14 @@
{% else %}
var codeFriendlyMarkdown = false;
{% endif %}
+ (function() {
+ var bodyTriggerLink = $('.question-body-trigger');
+ if (bodyTriggerLink.length === 1) {
+ var foldedEditor = new FoldedEditor();
+ foldedEditor.setExternalTrigger(bodyTriggerLink);
+ foldedEditor.decorate($('.folded-editor'));
+ }
+ })();
$().ready(function(){
//set current module button style
$('#editor').TextAreaResizer();
diff --git a/askbot/templates/ask_by_widget.html b/askbot/templates/ask_by_widget.html
index f700f83a..0eacd0cd 100644
--- a/askbot/templates/ask_by_widget.html
+++ b/askbot/templates/ask_by_widget.html
@@ -1,16 +1,16 @@
{% extends "widget_base.html" %}
{% block forestyle %}
-{%endblock%}
+{% endblock %}
-{%block body%}
+{% block body %}
Enter your question
<form action="." method="POST" accept-charset="utf-8">
{% csrf_token %}
- {{form.title}}
+ {{ form.title }}
{% if form.ask_anonymously %}
- {{form.ask_anonymously}}
- {%endif%}
+ {{ form.ask_anonymously }}
+ {% endif %}
<input type="submit" value="Ask your question" />
</form>
-{{form.errors}}
-{%endblock%}
+{{ form.errors }}
+{% endblock %}
diff --git a/askbot/templates/email/notify_author_about_approved_post.html b/askbot/templates/email/notify_author_about_approved_post.html
index 24601775..6007f06e 100644
--- a/askbot/templates/email/notify_author_about_approved_post.html
+++ b/askbot/templates/email/notify_author_about_approved_post.html
@@ -1,4 +1,5 @@
{% extends "email/base_mail.html"%}
+{% import "email/macros.html" as macros %}
{#
parameters:
diff --git a/askbot/templates/widgets/ask_form.html b/askbot/templates/widgets/ask_form.html
index e26ec771..3ddb07dd 100644
--- a/askbot/templates/widgets/ask_form.html
+++ b/askbot/templates/widgets/ask_form.html
@@ -12,21 +12,33 @@
value="{% if form.initial.title %}{{form.initial.title|escape}}{% endif %}"/>
</div>
</div>
- {% if settings.MIN_QUESTION_BODY_LENGTH == 0 %}
- <label for="editor">{% trans %}Add details{% endtrans %}</label>
+ {% set editor_is_folded = (
+ settings.MIN_QUESTION_BODY_LENGTH == 0 and
+ form.text.value()|is_empty_editor_value()
+ )
+ %}
+ {% if editor_is_folded %}
+ <a class="question-body-trigger">{% trans %}Add details (optional){% endtrans %}</a>
+ {% elif settings.MIN_QUESTION_BODY_LENGTH == 0 %}
+ <label for="editor">{% trans %}Add details (optional){% endtrans %}</label>
{% else %}
- <label for="editor">{% trans %}Add details, if necessary{% endtrans %}</label>
+ <label for="editor">{% trans %}Add details{% endtrans %}</label>
{% endif %}
- {{
- macros.edit_post(
- form,
- post_type = 'question',
- mandatory_tags = mandatory_tags,
- use_category_selector = (settings.TAG_SOURCE == 'category-tree'),
- editor_type = settings.EDITOR_TYPE,
- user = request.user
- )
- }}
+
+ <div class="folded-editor{% if editor_is_folded == False %} unfolded{% endif %}">
+ <div class="editor-proper">
+ {{
+ macros.edit_post(
+ form,
+ post_type = 'question',
+ mandatory_tags = mandatory_tags,
+ use_category_selector = (settings.TAG_SOURCE == 'category-tree'),
+ editor_type = settings.EDITOR_TYPE,
+ user = request.user
+ )
+ }}
+ </div>
+ </div>
{{ form.group_id }}
<div class="question-options">
{% if settings.WIKI_ON %}
diff --git a/askbot/templates/widgets/edit_post.html b/askbot/templates/widgets/edit_post.html
index b3c231cc..810fdfb5 100644
--- a/askbot/templates/widgets/edit_post.html
+++ b/askbot/templates/widgets/edit_post.html
@@ -20,7 +20,7 @@
</div>
{# need label element for resizable input, b/c form validation won't find span #}
{% if post_type == 'question' %}
- <div class="form-item">
+ <div class="form-item question-tags">
{% if use_category_selector %}
{% include "widgets/three_column_category_selector.html" %}
<div class="tags-desc">{% trans %}Tags{% endtrans %}</div>
diff --git a/askbot/templatetags/extra_filters_jinja.py b/askbot/templatetags/extra_filters_jinja.py
index a8681f5c..19c216d4 100644
--- a/askbot/templatetags/extra_filters_jinja.py
+++ b/askbot/templatetags/extra_filters_jinja.py
@@ -4,6 +4,7 @@ import re
import time
import urllib
from coffin import template as coffin_template
+from bs4 import BeautifulSoup
from django.core import exceptions as django_exceptions
from django.utils.translation import ugettext as _
from django.utils.translation import get_language as django_get_language
@@ -54,6 +55,18 @@ def is_current_language(lang):
return lang == django_get_language()
@register.filter
+def is_empty_editor_value(value):
+ if value == None:
+ return True
+ if str(value).strip() == '':
+ return True
+ #tinymce uses a weird sentinel placeholder
+ if askbot_settings.EDITOR_TYPE == 'tinymce':
+ soup = BeautifulSoup(value)
+ return soup.getText().strip() == ''
+ return False
+
+@register.filter
def to_int(value):
return int(value)
diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py
index f76d94a2..2620d6b8 100644
--- a/askbot/tests/page_load_tests.py
+++ b/askbot/tests/page_load_tests.py
@@ -111,25 +111,23 @@ class PageLoadTestCase(AskbotTestCase):
self.assertEqual(r.status_code, status_code)
if template and status_code != 302:
- if isinstance(r.template, coffin.template.Template):
- self.assertEqual(r.template.name, template)
- elif isinstance(r.template, list):
+ if hasattr(r, 'template'):
+ if isinstance(r.template, coffin.template.Template):
+ self.assertEqual(r.template.name, template)
+ return
+
+ if hasattr(r, 'template'):
+ templates = r.template
+ elif hasattr(r, 'templates'):
+ templates = r.templates
+ else:
+ raise NotImplementedError()
+
+ if isinstance(templates, list):
#asuming that there is more than one template
- template_names = ','.join([t.name for t in r.template])
- print 'templates are %s' % template_names
- # The following code is no longer relevant because we're using
- # additional templates for cached fragments [e.g. thread.get_summary_html()]
-# if follow == False:
-# self.fail(
-# ('Have issue accessing %s. '
-# 'This should not have happened, '
-# 'since you are not expecting a redirect '
-# 'i.e. follow == False, there should be only '
-# 'one template') % url
-# )
-#
-# self.assertEqual(r.template[0].name, template)
- self.assertIn(template, [t.name for t in r.template])
+ template_names = [t.name for t in templates]
+ print 'templates are %s' % ','.join(template_names)
+ self.assertIn(template, template_names)
else:
raise Exception('unexpected error while runnig test')
@@ -141,8 +139,14 @@ class PageLoadTestCase(AskbotTestCase):
self.failUnless(len(response.redirect_chain) == 1)
redirect_url = response.redirect_chain[0][0]
self.failUnless(unicode(redirect_url).endswith('/questions/'))
- self.assertTrue(isinstance(response.template, list))
- self.assertIn('main_page.html', [t.name for t in response.template])
+ if hasattr(response, 'template'):
+ templates = response.template
+ elif hasattr(response, 'templates'):
+ templates = response.templates
+ else:
+ raise NotImplementedError()
+ self.assertTrue(isinstance(templates, list))
+ self.assertIn('main_page.html', [t.name for t in templates])
def proto_test_ask_page(self, allow_anonymous, status_code):
prev_setting = askbot_settings.ALLOW_POSTING_BEFORE_LOGGING_IN
diff --git a/askbot/utils/forms.py b/askbot/utils/forms.py
index 4d33fd75..4dfc8b4f 100644
--- a/askbot/utils/forms.py
+++ b/askbot/utils/forms.py
@@ -1,6 +1,5 @@
import re
from django import forms
-from django.http import str_to_unicode
from django.contrib.auth.models import User
from django.conf import settings
from django.http import Http404
@@ -22,7 +21,8 @@ def clean_next(next, default = None):
return default
else:
return DEFAULT_NEXT
- next = str_to_unicode(urllib.unquote(next), 'utf-8')
+ if isinstance(next, str):
+ next = unicode(urllib.unquote(next), 'utf-8', 'replace')
next = next.strip()
logging.debug('next url is %s' % next)
return next
diff --git a/askbot/utils/functions.py b/askbot/utils/functions.py
index 2579728b..592dcf43 100644
--- a/askbot/utils/functions.py
+++ b/askbot/utils/functions.py
@@ -132,27 +132,39 @@ def setup_paginator(context):
if (context["pages"] <= LEADING_PAGE_RANGE_DISPLAYED):
in_leading_range = in_trailing_range = True
page_numbers = [n for n in range(1, context["pages"] + 1) if n > 0 and n <= context["pages"]]
- elif (context["page"] <= LEADING_PAGE_RANGE):
+ elif (context["current_page_number"] <= LEADING_PAGE_RANGE):
in_leading_range = True
page_numbers = [n for n in range(1, LEADING_PAGE_RANGE_DISPLAYED + 1) if n > 0 and n <= context["pages"]]
pages_outside_leading_range = [n + context["pages"] for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)]
- elif (context["page"] > context["pages"] - TRAILING_PAGE_RANGE):
+ elif (context["current_page_number"] > context["pages"] - TRAILING_PAGE_RANGE):
in_trailing_range = True
page_numbers = [n for n in range(context["pages"] - TRAILING_PAGE_RANGE_DISPLAYED + 1, context["pages"] + 1) if n > 0 and n <= context["pages"]]
pages_outside_trailing_range = [n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)]
else:
- page_numbers = [n for n in range(context["page"] - ADJACENT_PAGES, context["page"] + ADJACENT_PAGES + 1) if n > 0 and n <= context["pages"]]
+ page_numbers = [n for n in range(context["current_page_number"] - ADJACENT_PAGES, context["current_page_number"] + ADJACENT_PAGES + 1) if n > 0 and n <= context["pages"]]
pages_outside_leading_range = [n + context["pages"] for n in range(0, -NUM_PAGES_OUTSIDE_RANGE, -1)]
pages_outside_trailing_range = [n + 1 for n in range(0, NUM_PAGES_OUTSIDE_RANGE)]
+ page_object = context['page_object']
+ #patch for change in django 1.5
+ if page_object.has_previous():
+ previous_page_number = page_object.previous_page_number()
+ else:
+ previous_page_number = None
+
+ if page_object.has_next():
+ next_page_number = page_object.next_page_number()
+ else:
+ next_page_number = None
+
return {
"base_url": context["base_url"],
"is_paginated": context["is_paginated"],
- "previous": context["previous"],
- "has_previous": context["has_previous"],
- "next": context["next"],
- "has_next": context["has_next"],
- "page": context["page"],
+ "previous": previous_page_number,
+ "has_previous": page_object.has_previous(),
+ "next": next_page_number,
+ "has_next": page_object.has_next(),
+ "page": context["current_page_number"],
"pages": context["pages"],
"page_numbers": page_numbers,
"in_leading_range" : in_leading_range,
diff --git a/askbot/utils/html.py b/askbot/utils/html.py
index 549f22bf..9fb46337 100644
--- a/askbot/utils/html.py
+++ b/askbot/utils/html.py
@@ -97,7 +97,12 @@ def replace_links_with_text(html):
def strip_tags(html, tags=None):
"""strips tags from given html output"""
+ #a corner case
+ if html.strip() == '':
+ return html
+
assert(tags != None)
+
soup = BeautifulSoup(html)
for tag in tags:
tag_matches = soup.find_all(tag)
diff --git a/askbot/views/meta.py b/askbot/views/meta.py
index 6714f61e..692216da 100644
--- a/askbot/views/meta.py
+++ b/askbot/views/meta.py
@@ -203,11 +203,8 @@ def list_suggested_tags(request):
paginator_context = functions.setup_paginator({
'is_paginated' : True,
'pages': paginator.num_pages,
- 'page': page_no,
- 'has_previous': page.has_previous(),
- 'has_next': page.has_next(),
- 'previous': page.previous_page_number(),
- 'next': page.next_page_number(),
+ 'current_page_number': page_no,
+ 'page_object': page,
'base_url' : request.path
})
diff --git a/askbot/views/readers.py b/askbot/views/readers.py
index 1f19c1e6..f738da25 100644
--- a/askbot/views/readers.py
+++ b/askbot/views/readers.py
@@ -115,14 +115,9 @@ def questions(request, **kwargs):
paginator_context = {
'is_paginated' : (paginator.count > page_size),
-
'pages': paginator.num_pages,
- 'page': search_state.page,
- 'has_previous': page.has_previous(),
- 'has_next': page.has_next(),
- 'previous': page.previous_page_number(),
- 'next': page.next_page_number(),
-
+ 'current_page_number': search_state.page,
+ 'page_object': page,
'base_url' : search_state.query_string(),
'page_size' : page_size,
}
@@ -297,11 +292,8 @@ def tags(request):#view showing a listing of available tags - plain list
paginator_data = {
'is_paginated' : (objects_list.num_pages > 1),
'pages': objects_list.num_pages,
- 'page': page,
- 'has_previous': tags.has_previous(),
- 'has_next': tags.has_next(),
- 'previous': tags.previous_page_number(),
- 'next': tags.next_page_number(),
+ 'current_page_number': page,
+ 'page_object': tags,
'base_url' : reverse('tags') + '?sort=%s&amp;' % sortby
}
paginator_context = functions.setup_paginator(paginator_data)
@@ -524,11 +516,8 @@ def question(request, id):#refactor - long subroutine. display question body, an
paginator_data = {
'is_paginated' : (objects_list.count > const.ANSWERS_PAGE_SIZE),
'pages': objects_list.num_pages,
- 'page': show_page,
- 'has_previous': page_objects.has_previous(),
- 'has_next': page_objects.has_next(),
- 'previous': page_objects.previous_page_number(),
- 'next': page_objects.next_page_number(),
+ 'current_page_number': show_page,
+ 'page_object': page_objects,
'base_url' : request.path + '?sort=%s&amp;' % answer_sort_method,
}
paginator_context = functions.setup_paginator(paginator_data)
diff --git a/askbot/views/users.py b/askbot/views/users.py
index 0842074a..179392d2 100644
--- a/askbot/views/users.py
+++ b/askbot/views/users.py
@@ -163,11 +163,8 @@ def show_users(request, by_group=False, group_id=None, group_slug=None):
paginator_data = {
'is_paginated' : is_paginated,
'pages': objects_list.num_pages,
- 'page': page,
- 'has_previous': users_page.has_previous(),
- 'has_next': users_page.has_next(),
- 'previous': users_page.previous_page_number(),
- 'next': users_page.next_page_number(),
+ 'current_page_number': page,
+ 'page_object': users_page,
'base_url' : base_url
}
paginator_context = functions.setup_paginator(paginator_data) #