diff options
author | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2012-02-15 14:35:06 -0600 |
---|---|---|
committer | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2012-02-15 14:35:06 -0600 |
commit | 078e3001bca3aa5d99b9882fe5218825aacd788a (patch) | |
tree | 5fceaae7a54945ba084d6b09acc4c69051be566f | |
parent | 82ba05b699ce5ca6ee37da6e3258706ab32a9317 (diff) | |
parent | 6ab8f84c6801a055620ae0ba44bacf4e9aa643ed (diff) | |
download | askbot-078e3001bca3aa5d99b9882fe5218825aacd788a.tar.gz askbot-078e3001bca3aa5d99b9882fe5218825aacd788a.tar.bz2 askbot-078e3001bca3aa5d99b9882fe5218825aacd788a.zip |
Merge branch 'master' of github.com:ASKBOT/askbot-devel
30 files changed, 196 insertions, 36 deletions
diff --git a/askbot/deployment/path_utils.py b/askbot/deployment/path_utils.py index ef260f86..caefa2a9 100644 --- a/askbot/deployment/path_utils.py +++ b/askbot/deployment/path_utils.py @@ -154,7 +154,7 @@ def deploy_into(directory, new_project = False, verbosity = 1, context = None): """ assert(isinstance(new_project, bool)) if new_project: - copy_files = ('__init__.py', 'manage.py', 'urls.py') + copy_files = ('__init__.py', 'manage.py', 'urls.py', 'django.wsgi') blank_files = ('__init__.py', 'manage.py') if verbosity >= 1: print 'Copying files: ' diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index 19ecfb2d..42be87d5 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -11,7 +11,11 @@ Development version (not released yet) * Added left sidebar option (Evgeny) * Added "help" page and links to in the header and the footer (Evgeny) * Removed url parameters and the hash fragment from uploaded files - - amazon S3 for some reason adds weird expiration parameters + amazon S3 for some reason adds weird expiration parameters (Evgeny) +* Reduced memory usage in data migrations (Evgeny) +* Added progress bars to slow data migrations (Evgeny) +* Added a management command to build_thread_summary_cache (Evgeny) +* Added a management delete_contextless_badge_award_activities (Evgeny) 0.7.39 (Jan 11, 2012) --------------------- diff --git a/askbot/doc/source/management-commands.rst b/askbot/doc/source/management-commands.rst index 1e3a7ac0..b857d6f0 100644 --- a/askbot/doc/source/management-commands.rst +++ b/askbot/doc/source/management-commands.rst @@ -78,6 +78,12 @@ The bulk of the management commands fall into this group and will probably be th | | This data is used to display preferentially real faces | | | on the main page. | +---------------------------------+-------------------------------------------------------------+ +| `build_thread_summary_cache` | Rebuilds cache for the question summary snippet. | ++---------------------------------+-------------------------------------------------------------+ +| `delete_contextless_...` | `delete_contextless_badge_award_activities` | +| | Deletes Activity objects of type badge award where the | +| | related context object is lost. | ++---------------------------------+-------------------------------------------------------------+ .. _email-related-commands: diff --git a/askbot/management/commands/build_thread_summary_cache.py b/askbot/management/commands/build_thread_summary_cache.py new file mode 100644 index 00000000..854843fe --- /dev/null +++ b/askbot/management/commands/build_thread_summary_cache.py @@ -0,0 +1,10 @@ +from django.core.management.base import NoArgsCommand +from askbot.models import Thread +from askbot.utils.console import ProgressBar + +class Command(NoArgsCommand): + def handle_noargs(self, **options): + message = "Rebuilding thread summary cache" + count = Thread.objects.count() + for thread in ProgressBar(Thread.objects.iterator(), count, message): + thread.update_summary_html() diff --git a/askbot/management/commands/delete_contextless_badge_award_activities.py b/askbot/management/commands/delete_contextless_badge_award_activities.py new file mode 100644 index 00000000..8116d335 --- /dev/null +++ b/askbot/management/commands/delete_contextless_badge_award_activities.py @@ -0,0 +1,20 @@ +from django.core.management.base import NoArgsCommand +from askbot.utils.console import ProgressBar +from askbot.models import Activity +from askbot import const + +class Command(NoArgsCommand): + def handle_noargs(self, **options): + act_type = const.TYPE_ACTIVITY_PRIZE + acts = Activity.objects.filter(activity_type = act_type) + deleted_count = 0 + message = "Searching for context-less award activity objects:" + for act in ProgressBar(acts.iterator(), acts.count(), message): + if act.content_object == None: + act.delete() + deleted_count += 1 + if deleted_count: + print "%d activity objects deleted" % deleted_count + else: + print "None found" + diff --git a/askbot/migrations/0053_create_threads_for_questions.py b/askbot/migrations/0053_create_threads_for_questions.py index 56f826b9..8c734571 100644 --- a/askbot/migrations/0053_create_threads_for_questions.py +++ b/askbot/migrations/0053_create_threads_for_questions.py @@ -3,12 +3,15 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): "Write your forwards methods here." - for question in orm.Question.objects.iterator(): + print "Converting question to threads:" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions): thread = orm.Thread.objects.create(favourite_count=question.favourite_count) question.thread = thread question.save() diff --git a/askbot/migrations/0057_transplant_answer_count_data.py b/askbot/migrations/0057_transplant_answer_count_data.py index 654f9793..f83847cd 100644 --- a/askbot/migrations/0057_transplant_answer_count_data.py +++ b/askbot/migrations/0057_transplant_answer_count_data.py @@ -3,11 +3,14 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for question in orm.Question.objects.iterator(): + message = "Adding answer counts to threads" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): thread = question.thread thread.answer_count = question.answer_count thread.save() diff --git a/askbot/migrations/0060_view_count_transplant.py b/askbot/migrations/0060_view_count_transplant.py index db3ab49b..e9538655 100644 --- a/askbot/migrations/0060_view_count_transplant.py +++ b/askbot/migrations/0060_view_count_transplant.py @@ -3,11 +3,14 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for question in orm.Question.objects.iterator(): + message = "Adding view counts to threads" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): thread = question.thread thread.view_count = question.view_count thread.save() diff --git a/askbot/migrations/0063_transplant_question_closed_datas.py b/askbot/migrations/0063_transplant_question_closed_datas.py index 052dc268..15626e48 100644 --- a/askbot/migrations/0063_transplant_question_closed_datas.py +++ b/askbot/migrations/0063_transplant_question_closed_datas.py @@ -3,11 +3,14 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for question in orm.Question.objects.iterator(): + message = "Marking closed threads" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): thread = question.thread thread.closed = question.closed diff --git a/askbot/migrations/0066_transplant_accepted_answer_data.py b/askbot/migrations/0066_transplant_accepted_answer_data.py index 6f5a81a0..f9c28b94 100644 --- a/askbot/migrations/0066_transplant_accepted_answer_data.py +++ b/askbot/migrations/0066_transplant_accepted_answer_data.py @@ -5,11 +5,14 @@ from south.v2 import DataMigration from django.db import models from askbot.migrations import TERM_YELLOW, TERM_RESET +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for question in orm.Question.objects.all(): + message = "Adding accepted answers to threads" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): thread = question.thread if question.answer_accepted: @@ -27,7 +30,8 @@ class Migration(DataMigration): thread.save() # Verify data integrity - for question in orm.Question.objects.all(): + message = "Checking correctness of accepted answer data" + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): accepted_answers = question.answers.filter(accepted=True) num_accepted_answers = len(accepted_answers) diff --git a/askbot/migrations/0069_transplant_last_activity_data.py b/askbot/migrations/0069_transplant_last_activity_data.py index a0756d68..bcd83ec9 100644 --- a/askbot/migrations/0069_transplant_last_activity_data.py +++ b/askbot/migrations/0069_transplant_last_activity_data.py @@ -3,11 +3,14 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for question in orm.Question.objects.iterator(): + message = "Adding last activity data to threads" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): thread = question.thread thread.last_activity_at = question.last_activity_at thread.last_activity_by = question.last_activity_by diff --git a/askbot/migrations/0072_transplant_tagnames_data.py b/askbot/migrations/0072_transplant_tagnames_data.py index 5f95fe07..caa5e6a6 100644 --- a/askbot/migrations/0072_transplant_tagnames_data.py +++ b/askbot/migrations/0072_transplant_tagnames_data.py @@ -3,11 +3,14 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for question in orm.Question.objects.iterator(): + message = "Adding denormalized tags field to threads" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): thread = question.thread thread.tagnames = question.tagnames thread.save() diff --git a/askbot/migrations/0075_transplant_followed_by_data.py b/askbot/migrations/0075_transplant_followed_by_data.py index 19529b2f..06afd155 100644 --- a/askbot/migrations/0075_transplant_followed_by_data.py +++ b/askbot/migrations/0075_transplant_followed_by_data.py @@ -3,11 +3,14 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for question in orm.Question.objects.iterator(): + message = "Adding followers to threads" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): question.thread.followed_by.clear() # just in case someone reversed this migration question.thread.followed_by.add(*list(question.followed_by.iterator())) diff --git a/askbot/migrations/0079_transplant_favquestions_data.py b/askbot/migrations/0079_transplant_favquestions_data.py index eb776f0d..67decb07 100644 --- a/askbot/migrations/0079_transplant_favquestions_data.py +++ b/askbot/migrations/0079_transplant_favquestions_data.py @@ -3,11 +3,14 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for fav in orm.FavoriteQuestion.objects.iterator(): + message = "Connecting favorite questions to threads" + num_favs = orm.FavoriteQuestion.objects.count() + for fav in ProgressBar(orm.FavoriteQuestion.objects.iterator(), num_favs, message): fav.thread = fav.question.thread fav.save() diff --git a/askbot/migrations/0082_transplant_title_data.py b/askbot/migrations/0082_transplant_title_data.py index cb9f6c1c..ccdf1e16 100644 --- a/askbot/migrations/0082_transplant_title_data.py +++ b/askbot/migrations/0082_transplant_title_data.py @@ -3,11 +3,14 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for question in orm.Question.objects.iterator(): + message = "Adding titles to threads" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): question.thread.title = question.title question.thread.save() diff --git a/askbot/migrations/0086_transplant_question_tags_data.py b/askbot/migrations/0086_transplant_question_tags_data.py index bcb2a48f..c2d9fa76 100644 --- a/askbot/migrations/0086_transplant_question_tags_data.py +++ b/askbot/migrations/0086_transplant_question_tags_data.py @@ -3,11 +3,14 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - for question in orm.Question.objects.iterator(): + message = "Linking tag objects with threads" + num_questions = orm.Question.objects.count() + for question in ProgressBar(orm.Question.objects.iterator(), num_questions, message): question.thread.tags.add(*list(question.tags.iterator())) if orm.Question.objects.annotate(tag_num=models.Count('tags'), thread_tag_num=models.Count('thread__tags')).exclude(tag_num=models.F('thread_tag_num')).exists(): diff --git a/askbot/migrations/0090_postize_q_a_c.py b/askbot/migrations/0090_postize_q_a_c.py index 3d3a7b44..7c85ed21 100644 --- a/askbot/migrations/0090_postize_q_a_c.py +++ b/askbot/migrations/0090_postize_q_a_c.py @@ -5,6 +5,7 @@ from south.db import db from south.v2 import DataMigration from django.db import models from django.conf import settings +from askbot.utils.console import ProgressBar from askbot.migrations import TERM_RED_BOLD, TERM_GREEN, TERM_RESET @@ -26,7 +27,9 @@ class Migration(DataMigration): if 'test' not in sys.argv: # Don't confuse users print TERM_GREEN, '[DEBUG] Initial Post.id ==', post_id + 1, TERM_RESET - for q in orm.Question.objects.iterator(): + message = "Converting Questions -> Posts" + num_questions = orm.Question.objects.count() + for q in ProgressBar(orm.Question.objects.iterator(), num_questions, message): post_id += 1 orm.Post.objects.create( id=post_id, @@ -67,7 +70,9 @@ class Migration(DataMigration): is_anonymous=q.is_anonymous, ) - for ans in orm.Answer.objects.iterator(): + message = "Answers -> Posts" + num_answers = orm.Answer.objects.count() + for ans in ProgressBar(orm.Answer.objects.iterator(), num_answers, message): post_id += 1 orm.Post.objects.create( id=post_id, @@ -108,7 +113,9 @@ class Migration(DataMigration): is_anonymous=ans.is_anonymous, ) - for cm in orm.Comment.objects.iterator(): + message = "Comments -> Posts" + num_comments = orm.Comment.objects.count() + for cm in ProgressBar(orm.Comment.objects.iterator(), num_comments, message): # Workaround for a strange issue with: http://south.aeracode.org/docs/generics.html # No need to investigate that as this is as simple as the "proper" way if (cm.content_type.app_label, cm.content_type.model) == ('askbot', 'question'): diff --git a/askbot/migrations/0092_postize_vote_and_activity.py b/askbot/migrations/0092_postize_vote_and_activity.py index 45442f8f..9c77597d 100644 --- a/askbot/migrations/0092_postize_vote_and_activity.py +++ b/askbot/migrations/0092_postize_vote_and_activity.py @@ -6,13 +6,15 @@ from south.v2 import DataMigration from django.db import models from askbot.migrations import TERM_RED_BOLD, TERM_GREEN, TERM_RESET +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): - # TODO: Speed this up by prefetching all votes ? - for v in orm.Vote.objects.iterator(): + message = "Connecting votes to posts" + num_votes = orm.Vote.objects.count() + for v in ProgressBar(orm.Vote.objects.iterator(), num_votes, message): if (v.content_type.app_label, v.content_type.model) == ('askbot', 'question'): v.voted_post = orm.Post.objects.get(self_question__id=v.object_id) elif (v.content_type.app_label, v.content_type.model) == ('askbot', 'answer'): @@ -31,7 +33,9 @@ class Migration(DataMigration): abandoned_activities = [] - for a in orm.Activity.objects.iterator(): + message = "Connecting activity objects to posts" + num_activities = orm.Activity.objects.count() + for a in ProgressBar(orm.Activity.objects.iterator(), num_activities, message): # test if content_object for this activity exists - there might be a bunch of "abandoned" activities # # NOTE that if activity.content_object is gone then we cannot reliably recover it from activity.question diff --git a/askbot/migrations/0095_postize_award_and_repute.py b/askbot/migrations/0095_postize_award_and_repute.py index 801949c2..ea7e7064 100644 --- a/askbot/migrations/0095_postize_award_and_repute.py +++ b/askbot/migrations/0095_postize_award_and_repute.py @@ -4,6 +4,7 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): @@ -11,7 +12,9 @@ class Migration(DataMigration): # ContentType for Post model should be created no later than in migration 0092 ct_post = orm['contenttypes.ContentType'].objects.get(app_label='askbot', model='post') - for aw in orm.Award.objects.iterator(): + message = "Connecting award objects to posts" + num_awards = orm.Award.objects.count() + for aw in ProgressBar(orm.Award.objects.iterator(), num_awards, message): ct = aw.content_type if ct.app_label == 'askbot' and ct.model in ('question', 'answer', 'comment'): aw.content_type = ct_post @@ -23,7 +26,9 @@ class Migration(DataMigration): ### - for rp in orm.Repute.objects.iterator(): + message = "Connecting repute objects to posts" + num_reputes = orm.Repute.objects.count() + for rp in ProgressBar(orm.Repute.objects.iterator(), num_reputes, message): if rp.question: rp.question_post = orm.Post.objects.get(self_question__id=rp.question.id) rp.save() diff --git a/askbot/migrations/0098_postize_thread_anonanswer_questionview_postrevision.py b/askbot/migrations/0098_postize_thread_anonanswer_questionview_postrevision.py index 0fd73605..08e62dbb 100644 --- a/askbot/migrations/0098_postize_thread_anonanswer_questionview_postrevision.py +++ b/askbot/migrations/0098_postize_thread_anonanswer_questionview_postrevision.py @@ -3,26 +3,35 @@ import datetime from south.db import db from south.v2 import DataMigration from django.db import models +from askbot.utils.console import ProgressBar class Migration(DataMigration): def forwards(self, orm): # TODO: Speed this migration up by prefetching data ? - for thread in orm.Thread.objects.iterator(): + message = "Marking accepted answer in threads" + num_threads = orm.Thread.objects.count() + for thread in ProgressBar(orm.Thread.objects.iterator(), num_threads, message): if thread.accepted_answer: thread.accepted_answer_post = orm.Post.objects.get(self_answer__id=thread.accepted_answer.id) thread.save() - for qv in orm.QuestionView.objects.iterator(): + message = "Connecting question view objects to posts" + num_question_views = orm.QuestionView.objects.count() + for qv in ProgressBar(orm.QuestionView.objects.iterator(), num_question_views, message): qv.question_post = orm.Post.objects.get(self_question__id=qv.question.id) qv.save() - for aa in orm.AnonymousAnswer.objects.iterator(): + message = "Connecting anonymous answers to posts" + num_anon_answers = orm.AnonymousAnswer.objects.count() + for aa in ProgressBar(orm.AnonymousAnswer.objects.iterator(), num_anon_answers, message): aa.question_post = orm.Post.objects.get(self_question__id=aa.question.id) aa.save() - for rev in orm.PostRevision.objects.iterator(): + message = "Connecting post revisions to posts" + num_post_revs = orm.PostRevision.objects.count() + for rev in ProgressBar(orm.PostRevision.objects.iterator(), num_post_revs, message): if rev.question: assert not rev.answer rev.post = orm.Post.objects.get(self_question__id=rev.question.id) diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index d98d4246..db939d1a 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -36,6 +36,7 @@ from askbot import auth from askbot.utils.decorators import auto_now_timestamp from askbot.utils.slug import slugify from askbot.utils.diff import textDiff as htmldiff +from askbot.utils.url_utils import strip_path from askbot.utils import mail def get_model(model_name): @@ -2279,7 +2280,7 @@ def format_instant_notification_email( 'receiving_user_name': to_user.username, 'content_preview': content_preview,#post.get_snippet() 'update_type': update_type, - 'post_url': site_url + post.get_absolute_url(), + 'post_url': strip_path(site_url) + post.get_absolute_url(), 'origin_post_title': origin_post.thread.title, 'user_subscriptions_url': user_subscriptions_url, } diff --git a/askbot/models/question.py b/askbot/models/question.py index 6c2fa383..6daa3057 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -248,7 +248,7 @@ class ThreadManager(models.Manager): #print qs.query - return qs, meta_data + return qs.distinct(), meta_data def precache_view_data_hack(self, threads): # TODO: Re-enable this when we have a good test cases to verify that it works properly. diff --git a/askbot/skins/common/templates/authopenid/providers_javascript.html b/askbot/skins/common/templates/authopenid/providers_javascript.html index 0fe72eb3..cd9f56b6 100644 --- a/askbot/skins/common/templates/authopenid/providers_javascript.html +++ b/askbot/skins/common/templates/authopenid/providers_javascript.html @@ -43,9 +43,9 @@ <script> $(document).ready(function(){ if (typeof FB != 'undefined'){ - var ret = FB.init({appId: '{{settings.FACEBOOK_KEY}}', status: true, cookie: true, xfbml: true}); - FB.Event.subscribe('auth.sessionChange', function(response){ - if (response.session) { + var ret = FB.init({appId: '{{settings.FACEBOOK_KEY}}', status: true, cookie: true, xfbml: true, oauth: true}); + FB.Event.subscribe('auth.authResponseChange', function(response){ + if (response.authResponse) { $('#signin-form').submit(); } }); diff --git a/askbot/skins/default/templates/question.html b/askbot/skins/default/templates/question.html index 33c0e11f..b2462faf 100644 --- a/askbot/skins/default/templates/question.html +++ b/askbot/skins/default/templates/question.html @@ -6,7 +6,7 @@ {% endblock %} {% block keywords %}{{thread.tagname_meta_generator()}}{% endblock %} {% block forestyle %} - <link rel="canonical" href="{{settings.APP_URL}}{{question.get_absolute_url()}}" /> + <link rel="canonical" href="{{settings.APP_URL|strip_path}}{{question.get_absolute_url()}}" /> <link rel="stylesheet" type="text/css" href="{{'/js/wmd/wmd.css'|media}}" /> {% endblock %} {% block content %} diff --git a/askbot/skins/default/templates/question/sharing_prompt_phrase.html b/askbot/skins/default/templates/question/sharing_prompt_phrase.html index f7bd20af..2e68d1f3 100644 --- a/askbot/skins/default/templates/question/sharing_prompt_phrase.html +++ b/askbot/skins/default/templates/question/sharing_prompt_phrase.html @@ -1,4 +1,4 @@ -{% set question_url=settings.APP_URL+question.get_absolute_url()|urlencode %} +{% set question_url=(settings.APP_URL|strip_path + question.get_absolute_url())|urlencode %} <h2 class="share-question">{% trans %}Know someone who can answer? Share a <a href="{{ question_url }}">link</a> to this question via{% endtrans %} {% if settings.ENABLE_SHARING_TWITTER %}{{ macros.share(site = 'twitter', site_label = 'Twitter') }},{% endif %} {% if settings.ENABLE_SHARING_FACEBOOK %}{{ macros.share(site = 'facebook', site_label = 'Facebook') }},{% endif %} diff --git a/askbot/skins/default/templates/question_widget.html b/askbot/skins/default/templates/question_widget.html index 65ee8b64..9d32294b 100644 --- a/askbot/skins/default/templates/question_widget.html +++ b/askbot/skins/default/templates/question_widget.html @@ -11,7 +11,7 @@ <div id="container"> <ul> {% for thread in threads %} - <li><a href="{{settings.APP_URL}}{{ thread.get_absolute_url() }}"> + <li><a href="{{settings.APP_URL|strip_path}}{{ thread.get_absolute_url() }}"> {{ thread.title|escape }}</a></li> {% endfor %} </ul> diff --git a/askbot/templatetags/extra_filters_jinja.py b/askbot/templatetags/extra_filters_jinja.py index 52180da5..b7fbc5f0 100644 --- a/askbot/templatetags/extra_filters_jinja.py +++ b/askbot/templatetags/extra_filters_jinja.py @@ -14,6 +14,7 @@ from askbot.conf import settings as askbot_settings from django.conf import settings as django_settings from askbot.skins import utils as skin_utils from askbot.utils import functions +from askbot.utils import url_utils from askbot.utils.slug import slugify from askbot.shims.django_shims import ResolverMatch @@ -35,6 +36,11 @@ def absolutize_urls_func(text): absolutize_urls = register.filter(absolutize_urls_func) @register.filter +def strip_path(url): + """removes path part of the url""" + return url_utils.strip_path(url) + +@register.filter def clean_login_url(url): """pass through, unless user was originally on the logout page""" try: diff --git a/askbot/utils/console.py b/askbot/utils/console.py index 496bbd65..fe6ad29e 100644 --- a/askbot/utils/console.py +++ b/askbot/utils/console.py @@ -74,3 +74,43 @@ def print_progress(elapsed, total, nowipe = False): in-place""" output = '%6.2f%%' % (100 * float(elapsed)/float(total)) print_action(output, nowipe) + +class ProgressBar(object): + """A wrapper for an iterator, that prints + a progress bar along the way of iteration + """ + def __init__(self, iterable, length, message = ''): + self.iterable = iterable + self.length = length + self.counter = float(0) + self.barlen = 60 + self.progress = '' + if message and length > 0: + print message + + + def __iter__(self): + return self + + def next(self): + + try: + result = self.iterable.next() + except StopIteration: + if self.length > 0: + sys.stdout.write('\n') + raise + + sys.stdout.write('\b'*len(self.progress)) + + if self.length < self.barlen: + sys.stdout.write('-'*(self.barlen/self.length)) + elif int(self.counter) % (self.length / self.barlen) == 0: + sys.stdout.write('-') + + self.progress = ' %.2f%%' % (100 * (self.counter/self.length)) + sys.stdout.write(self.progress) + sys.stdout.flush() + + self.counter += 1 + return result diff --git a/askbot/utils/url_utils.py b/askbot/utils/url_utils.py index 0ebce394..6027d096 100644 --- a/askbot/utils/url_utils.py +++ b/askbot/utils/url_utils.py @@ -1,6 +1,18 @@ +import urlparse from django.core.urlresolvers import reverse from django.conf import settings +def strip_path(url): + """srips path, params and hash fragments of the url""" + purl = urlparse.urlparse(url) + return urlparse.urlunparse( + urlparse.ParseResult( + purl.scheme, + purl.netloc, + '', '', '', '' + ) + ) + def get_login_url(): """returns internal login url if django_authopenid is used, or @@ -27,6 +39,6 @@ def get_logout_redirect_url(): if 'askbot.deps.django_authopenid' in settings.INSTALLED_APPS: return reverse('logout') elif hasattr(settings, 'LOGOUT_REDIRECT_URL'): - return settigs.LOGOUT_REDIRECT_URL + return settings.LOGOUT_REDIRECT_URL else: return reverse('index') diff --git a/askbot/views/readers.py b/askbot/views/readers.py index cccfce67..fe1185e6 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -428,7 +428,9 @@ def question(request, id):#refactor - long subroutine. display question body, an # TODO: Add unit test to catch the bug where precache_comments() is called above (before) reordering the accepted answer to the top #Post.objects.precache_comments(for_posts=[question_post] + answers, visitor=request.user) - if thread.accepted_answer: # Put the accepted answer to front + if thread.accepted_answer and thread.accepted_answer.deleted == False: + #Put the accepted answer to front + #the second check is for the case when accepted answer is deleted answers.remove(thread.accepted_answer) answers.insert(0, thread.accepted_answer) |