diff options
-rw-r--r-- | askbot/models/__init__.py | 5 | ||||
-rw-r--r-- | askbot/models/badges.py | 23 | ||||
-rw-r--r-- | askbot/skins/default/templates/base.html | 8 | ||||
-rw-r--r-- | askbot/skins/default/templates/user_recent.html | 2 | ||||
-rw-r--r-- | askbot/skins/default/templates/user_stats.html | 2 | ||||
-rw-r--r-- | askbot/startup_procedures.py | 8 | ||||
-rw-r--r-- | askbot/tests/page_load_tests.py | 2 | ||||
-rw-r--r-- | askbot/views/meta.py | 1 | ||||
-rw-r--r-- | askbot/views/users.py | 61 |
9 files changed, 46 insertions, 66 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 93a8790d..722b4164 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -742,7 +742,10 @@ def user_retag_question( ) @auto_now_timestamp -def user_accept_best_answer(self, answer = None, timestamp = None): +def user_accept_best_answer(self, answer = None, + timestamp = None, cancel = False): + if cancel: + return self.unaccept_best_answer(answer = answer, timestamp = timestamp) self.assert_can_accept_best_answer(answer) if answer.accepted == True: return diff --git a/askbot/models/badges.py b/askbot/models/badges.py index 791dbd10..8cee2d6c 100644 --- a/askbot/models/badges.py +++ b/askbot/models/badges.py @@ -700,11 +700,20 @@ class FavoriteQuestion(FavoriteTypeBadge): return self ORIGINAL_DATA = """ - (_('Generalist'), 2, _('generalist'), _('Active in many different tags'), False, 0), - (_('Expert'), 2, _('expert'), _('Very active in one tag'), False, 0), + +extra badges from stackexchange +* commentator - left n comments (single) +* enthusiast, fanatic - visited site n days in a row (s) +* epic, legendary - hit daily reputation cap on n days (s) +* mortarboard - hit the daily reputation cap for the first time (s) +* populist - provided an answer that outscored an accepted answer two-fold or by n points, whichever is higher (m) +* reversal - provided an answer with +n points to a question of -m points (_('Taxonomist'), 2, _('taxonomist'), _('Created a tag used by 50 questions'), True, 0) - (_('Yearling'), 2, _('yearling'), _('Active member for a year'), False, 0), + + + (_('Generalist'), 2, _('generalist'), _('Active in many different tags'), False, 0), + (_('Expert'), 2, _('expert'), _('Very active in one tag'), False, 0), (_('Beta'), 2, _('beta'), _('Actively participated in the private beta'), False, 0), (_('Alpha'), 2, _('alpha'), _('Actively participated in the private alpha'), False, 0), """ @@ -712,10 +721,10 @@ ORIGINAL_DATA = """ BADGES = { 'strunk-and-white': AssociateEditor,#legacy slug name 'autobiographer': Autobiographer, - 'critic': Critic, + 'cleanup': Cleanup, 'citizen-patrol': CitizenPatrol, 'civic-duty': CivicDuty, - 'cleanup': Cleanup, + 'critic': Critic, 'disciplined': Disciplined, 'editor': Editor, 'enlightened': Enlightened, @@ -735,10 +744,10 @@ BADGES = { 'popular-question': PopularQuestion, 'pundit': Pundit, 'scholar': Scholar, - 'student': Student, - 'supporter': Supporter, 'self-learner': SelfLearner, 'stellar-question': StellarQuestion, + 'student': Student, + 'supporter': Supporter, 'teacher': Teacher, } diff --git a/askbot/skins/default/templates/base.html b/askbot/skins/default/templates/base.html index 1bf3e572..90ea1568 100644 --- a/askbot/skins/default/templates/base.html +++ b/askbot/skins/default/templates/base.html @@ -100,12 +100,12 @@ {% else %} $('#id_title').focus(); {% endif %} - {% if user_messages %} - $('#validate_email_alert').click(function(){notify.close(true)}) - notify.show(); - {% endif %} }); {% endif %} + {% if user_messages %} + $('#validate_email_alert').click(function(){notify.close(true)}) + notify.show(); + {% endif %} </script> {% if settings.GOOGLE_ANALYTICS_KEY %} <script type="text/javascript"> diff --git a/askbot/skins/default/templates/user_recent.html b/askbot/skins/default/templates/user_recent.html index 82565c4a..39dc4bea 100644 --- a/askbot/skins/default/templates/user_recent.html +++ b/askbot/skins/default/templates/user_recent.html @@ -10,7 +10,7 @@ </div> <div style="float:left;overflow:hidden;"> {% if act.type_id==7 %} - <a href="{{act.badge.get_absolute_url()}}" title="{{ act.badge.get_type_display() }} : {% trans description=act.badge.description %}{{description}}{% endtrans %}" class="medal"><span class="badge{{ act.badge.type }}">●</span> {% trans name=act.badge.name %}{{name}}{% endtrans %}</a> + <a href="{{act.badge.get_absolute_url()}}" title="{{ act.badge.get_type_display() }} : {% trans description=act.badge.description %}{{description}}{% endtrans %}" class="medal"><span class="{{ act.badge.css_class }}">●</span> {% trans name=act.badge.name %}{{name}}{% endtrans %}</a> {% else %} <span class="post-type-{{ act.type_id }}"><a href="{{ act.title_link }}">{{ act.title|escape }}</a></span> {% if act.summary %}<span class="revision-summary">{{ act.summary|escape }}</span>{% endif %} diff --git a/askbot/skins/default/templates/user_stats.html b/askbot/skins/default/templates/user_stats.html index 73026ce2..36bb1d43 100644 --- a/askbot/skins/default/templates/user_stats.html +++ b/askbot/skins/default/templates/user_stats.html @@ -85,7 +85,7 @@ <tr> <td width="180" style="line-height:35px"> {% for award in awards %}{# todo: translate badge name properly #} - <a href="{% url badge award.id %}{{award.name}}" title="{% trans description=award.description %}{{description}}{% endtrans %}" class="medal"><span class="{{ award.css_class }}">●</span> {% trans name=award.name %}{{name}}{% endtrans %}</a><span class="tag-number"> × {{ award.count|intcomma }}</span><br/> + <a href="{{award.badge.get_absolute_url()}}" title="{% trans description=award.badge.description %}{{description}}{% endtrans %}" class="medal"><span class="{{ award.badge.css_class }}">●</span> {% trans name=award.badge.name %}{{name}}{% endtrans %}</a><span class="tag-number"> × {{ award.count|intcomma }}</span><br/> {% if loop.index is divisibleby 3 %} </td> <td width="180" style="line-height:35px"> diff --git a/askbot/startup_procedures.py b/askbot/startup_procedures.py index c7f794fa..0857da38 100644 --- a/askbot/startup_procedures.py +++ b/askbot/startup_procedures.py @@ -5,6 +5,7 @@ the purpose of this module is to validate deployment of askbot the main function is run_startup_tests """ +from django.db import transaction from django.conf import settings from django.core.exceptions import ImproperlyConfigured from askbot.models import badges @@ -47,7 +48,12 @@ def run_startup_tests(): msg = 'if ASKBOT_URL setting is not empty, ' + \ 'it must not start with /' +@transaction.commit_manually def run(): """runs all the startup procedures""" run_startup_tests() - badges.init_badges() + try: + badges.init_badges() + transaction.commit() + except: + transaction.rollback() diff --git a/askbot/tests/page_load_tests.py b/askbot/tests/page_load_tests.py index 64f03207..2d73b9ea 100644 --- a/askbot/tests/page_load_tests.py +++ b/askbot/tests/page_load_tests.py @@ -49,7 +49,7 @@ class PageLoadTestCase(TestCase): self.assertEqual(r.template[0].name, template) class PageLoadTests(PageLoadTestCase): - fixtures = ['tmp/fixture1.json', ] + fixtures = ['tmp/fixture2.json', ] def test_index(self): #todo: merge this with all reader url tests diff --git a/askbot/views/meta.py b/askbot/views/meta.py index 2497cd38..07ac213b 100644 --- a/askbot/views/meta.py +++ b/askbot/views/meta.py @@ -20,7 +20,6 @@ from askbot import skins import askbot def generic_view(request, template = None): - print 'in generic view' template = ENV.get_template(template) context = RequestContext(request) return HttpResponse(template.render(context)) diff --git a/askbot/views/users.py b/askbot/views/users.py index fd1836f4..0c92b579 100644 --- a/askbot/views/users.py +++ b/askbot/views/users.py @@ -10,7 +10,7 @@ import calendar import functools import datetime import logging -from django.db.models import Sum +from django.db.models import Sum, Count from django.contrib.auth.decorators import login_required from django.core.paginator import Paginator, EmptyPage, InvalidPage from django.contrib.contenttypes.models import ContentType @@ -336,51 +336,14 @@ def user_stats(request, user): question_id_set.update([q.id for q in questions]) question_id_set.update([q['id'] for q in answered_questions]) user_tags = models.Tag.objects.filter(questions__id__in = question_id_set) - try: - from django.db.models import Count - #todo - rewrite template to do the table joins within standard ORM - #awards = models.Award.objects.filter(user=user).order_by('-awarded_at') - awards = models.Award.objects.extra( - select={'id': 'badge.id', - 'name':'badge.name', - 'description': 'badge.description', - 'type': 'badge.type'}, - tables=['award', 'badge'], - order_by=['-awarded_at'], - where=['user_id=%s AND badge_id=badge.id'], - params=[user.id] - ).values('id', 'name', 'description', 'type') - - total_awards = awards.count() - awards = awards.annotate(count = Count('badge__id')) - user_tags = user_tags.annotate( - user_tag_usage_count=Count('name') - ).order_by( - '-user_tag_usage_count' - ) - - except ImportError: - #todo: remove all old django stuff, e.g. with '.group_by = ' pattern - awards = models.Award.objects.extra( - select={'id': 'badge.id', - 'count': 'count(badge_id)', - 'name':'badge.name', - 'description': 'badge.description', - 'type': 'badge.type'}, - tables=['award', 'badge'], - order_by=['-awarded_at'], - where=['user_id=%s AND badge_id=badge.id'], - params=[user.id] - ).values('id', 'count', 'name', 'description', 'type') - - total_awards = awards.count() - awards.query.group_by = ['badge_id'] - - user_tags = user_tags.extra( - select={'user_tag_usage_count': 'COUNT(1)',}, - order_by=['-user_tag_usage_count'], - ) - user_tags.query.group_by = ['name'] + awards = models.Award.objects.filter(user=user).order_by('-awarded_at') + total_awards = awards.count() + awards = awards.annotate(count = Count('badge__id')) + user_tags = user_tags.annotate( + user_tag_usage_count=Count('name') + ).order_by( + '-user_tag_usage_count' + ) if user.is_administrator(): user_status = _('Site Adminstrator') @@ -657,13 +620,13 @@ def user_recent(request, user): #award history awards = models.Activity.objects.extra( select={ - 'badge_id' : 'badge.id', + 'badge_id' : 'askbot_badgedata.id', 'awarded_at': 'award.awarded_at', 'activity_type' : 'activity.activity_type' }, - tables=['activity', 'award', 'badge'], + tables=['activity', 'award', 'askbot_badgedata'], where=['activity.user_id = award.user_id AND activity.user_id = %s AND '+ - 'award.badge_id=badge.id AND activity.object_id=award.id AND activity.activity_type=%s'], + 'award.badge_id=askbot_badgedata.id AND activity.object_id=award.id AND activity.activity_type=%s'], params=[user.id, const.TYPE_ACTIVITY_PRIZE], order_by=['-activity.active_at'] ).values( |