Browse files

merged vlads caching of the question page fix

  • Loading branch information...
2 parents 3ade726 + f692b08 commit 2db55bf3d2a9d8c0a834cda46fe237139874d2bf @evgenyfadeev evgenyfadeev committed Nov 6, 2011
View
1 askbot/conf/spam_and_moderation.py
@@ -31,4 +31,3 @@
description=_('Akismet key for spam detection')
)
)
-
View
10 askbot/conf/vote_rules.py
@@ -78,3 +78,13 @@
description=_('Number of flags required to automatically delete posts')
)
)
+
+settings.register(
+ IntegerValue(
+ VOTE_RULES,
+ 'MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER',
+ default=7,
+ description=_('Minimum days to accept an answer, '
+ 'if it has not been accepted by the question poster')
+ )
+)
View
15 askbot/models/__init__.py
@@ -342,9 +342,22 @@ def user_assert_can_unaccept_best_answer(self, answer = None):
low_rep_error_message = low_rep_error_message
)
return # success
+
+ elif self.is_administrator() or self.is_moderator():
+ will_be_able_at = (answer.added_at +
+ datetime.timedelta(days=askbot_settings.MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER))
+
+ if datetime.datetime.now() < will_be_able_at:
+ error_message = _(
+ 'Sorry, you will be able to accept this answer '
+ 'only after %(will_be_able_at)s'
+ ) % {'will_be_able_at': will_be_able_at.strftime('%d/%m/%Y')}
+ else:
+ return
+
else:
error_message = _(
- 'Sorry, only original author of the question '
+ 'Sorry, only moderators or original author of the question '
' - %(username)s - can accept or unaccept the best answer'
) % {'username': answer.get_owner().username}
View
1 askbot/setup_templates/settings.py
@@ -176,6 +176,7 @@
#needed for django-keyedcache
CACHE_TIMEOUT = 6000
CACHE_PREFIX = 'askbot' #make this unique
+CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
#If you use memcache you may want to uncomment the following line to enable memcached based sessions
#SESSION_ENGINE = 'django.contrib.sessions.backends.cache_db'
View
10 askbot/skins/common/media/js/post.js
@@ -389,12 +389,10 @@ var Vote = function(){
var bindEvents = function(){
// accept answers
- if(questionAuthorId == currentUserId){
- var acceptedButtons = 'div.'+ voteContainerId +' img[id^='+ imgIdPrefixAccept +']';
- $(acceptedButtons).unbind('click').click(function(event){
- Vote.accept($(event.target));
- });
- }
+ var acceptedButtons = 'div.'+ voteContainerId +' img[id^='+ imgIdPrefixAccept +']';
+ $(acceptedButtons).unbind('click').click(function(event){
+ Vote.accept($(event.target));
+ });
// set favorite question
var favoriteButton = getFavoriteButton();
favoriteButton.unbind('click').click(function(event){
View
2 askbot/skins/common/templates/question/answer_vote_buttons.html
@@ -3,7 +3,7 @@
visitor_vote = user_answer_votes[answer.id]
)
}}
-{% if request.user == question.author %}
+{% if request.user == question.author or request.user.is_authenticated() and (request.user.is_moderator() or request.user.is_superuser()) %}
<img id="answer-img-accept-{{ answer.id }}" class="answer-img-accept"
{% if answer.accepted %}
src="{{'/images/vote-accepted-on.png'|media}}"
View
35 askbot/tests/db_api_tests.py
@@ -4,6 +4,10 @@
e.g. ``some_user.do_something(...)``
"""
from django.core import exceptions
+from django.core.urlresolvers import reverse
+from django.db import connection
+from django.test.client import Client
+from django.conf import settings
from askbot.tests.utils import AskbotTestCase
from askbot import models
from askbot import const
@@ -39,6 +43,37 @@ def assert_post_is_not_deleted(self, post):
self.assertTrue(post.deleted_by == None)
self.assertTrue(post.deleted_at == None)
+ def test_anonymous_question_cache(self):
+ question = self.post_question()
+ settings.DEBUG = True # because it's forsed to False
+ url = reverse('question', kwargs={'id': question.id})
+
+ client = Client()
+ client.get(url, follow=True)
+ counter = len(connection.queries)
+ client.get(url, follow=True)
+
+ self.assertTrue(counter > len(connection.queries))
+ self.assertEqual(3, len(connection.queries)) # session-related only
+ settings.DEBUG = False
+
+ def test_authentificated_no_question_cache(self):
+ question = self.post_question()
+ settings.DEBUG = True # because it's forsed to False
+ url = reverse('question', kwargs={'id': question.id})
+
+ password = '123'
+ client = Client()
+ self.other_user.set_password(password)
+ client.login(username=self.other_user.username, password=password)
+
+ client.get(url, follow=True)
+ counter = len(connection.queries)
+ client.get(url, follow=True)
+
+ self.assertEqual(counter, len(connection.queries))
+ settings.DEBUG = False
+
def test_flag_question(self):
self.user.set_status('m')
self.user.flag_post(self.question)
View
38 askbot/tests/permission_assertion_tests.py
@@ -1368,30 +1368,52 @@ def test_high_rep_other_user_cannot_accept_answer(self):
self.third_user.reputation = 1000000
self.assert_user_cannot(user = self.third_user)
- def test_moderator_cannot_accept_others_answer(self):
- self.other_post_answer()
- self.create_user(username = 'third_user')
- self.third_user.set_status('m')
- self.assert_user_cannot(user = self.third_user)
-
def test_moderator_cannot_accept_own_answer(self):
self.other_post_answer()
self.other_user.set_status('m')
self.assert_user_cannot(user = self.other_user)
- def test_admin_cannot_accept_others_answer(self):
+ def test_moderator_cannot_accept_others_answer_today(self):
+ self.other_post_answer()
+ self.create_user(username = 'third_user')
+ self.third_user.set_status('m')
+ self.assert_user_cannot(user = self.third_user)
+
+ def test_moderator_can_accept_others_old_answer(self):
self.other_post_answer()
+ self.answer.added_at -= datetime.timedelta(
+ days = askbot_settings.MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER + 1
+ )
+ self.answer.save()
self.create_user(username = 'third_user')
self.third_user.set_admin_status()
self.third_user.save()
- self.assert_user_cannot(user = self.third_user)
+ self.assert_user_can(user = self.third_user)
def test_admin_cannot_accept_own_answer(self):
self.other_post_answer()
self.other_user.set_admin_status()
self.other_user.save()
self.assert_user_cannot(user = self.other_user)
+ def test_admin_cannot_accept_others_answer_today(self):
+ self.other_post_answer()
+ self.create_user(username = 'third_user')
+ self.third_user.set_admin_status()
+ self.third_user.save()
+ self.assert_user_cannot(user = self.third_user)
+
+ def test_admin_can_accept_others_old_answer(self):
+ self.other_post_answer()
+ self.answer.added_at -= datetime.timedelta(
+ days = askbot_settings.MIN_DAYS_FOR_STAFF_TO_ACCEPT_ANSWER + 1
+ )
+ self.answer.save()
+ self.create_user(username = 'third_user')
+ self.third_user.set_admin_status()
+ self.third_user.save()
+ self.assert_user_can(user = self.third_user)
+
class VotePermissionAssertionTests(PermissionAssertionTestCase):
"""Tests permission for voting
"""
View
2 askbot/views/readers.py
@@ -23,6 +23,7 @@
from django.core.urlresolvers import reverse
from django.core import exceptions as django_exceptions
from django.contrib.humanize.templatetags import humanize
+from django.views.decorators.cache import cache_page
import askbot
from askbot import exceptions
@@ -349,6 +350,7 @@ def tags(request):#view showing a listing of available tags - plain list
return render_into_skin('tags.html', data, request)
@csrf.csrf_protect
+@cache_page(60 * 5)
def question(request, id):#refactor - long subroutine. display question body, answers and comments
"""view that displays body of the question and
all answers to it

0 comments on commit 2db55bf

Please sign in to comment.