diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-08-21 11:43:09 +0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-08-21 11:43:09 +0400 |
commit | 8f7f9c537865875390c574363b4e1826d10b987c (patch) | |
tree | 32b1c4d2636ad2cf982963af417b6136b80e94ae | |
parent | 0add9603665dc865e8cb8beed7c8b03f73958579 (diff) | |
download | askbot-8f7f9c537865875390c574363b4e1826d10b987c.tar.gz askbot-8f7f9c537865875390c574363b4e1826d10b987c.tar.bz2 askbot-8f7f9c537865875390c574363b4e1826d10b987c.zip |
fixed revealing of author identity upon editing a post
-rw-r--r-- | askbot/management/commands/rename_tags_id.py | 2 | ||||
-rw-r--r-- | askbot/migrations/0172_sync_thread_deleted.py | 2 | ||||
-rw-r--r-- | askbot/models/post.py | 17 | ||||
-rw-r--r-- | askbot/models/question.py | 7 | ||||
-rw-r--r-- | askbot/templates/macros.html | 123 | ||||
-rw-r--r-- | askbot/templates/question/answer_author_info.html | 9 | ||||
-rw-r--r-- | askbot/templates/question/question_author_info.html | 9 | ||||
-rw-r--r-- | askbot/templates/revisions.html | 7 | ||||
-rw-r--r-- | askbot/views/readers.py | 1 |
9 files changed, 77 insertions, 100 deletions
diff --git a/askbot/management/commands/rename_tags_id.py b/askbot/management/commands/rename_tags_id.py index 7926d28d..2f6e666f 100644 --- a/askbot/management/commands/rename_tags_id.py +++ b/askbot/management/commands/rename_tags_id.py @@ -106,7 +106,7 @@ rename_tags, but using tag id's to_tags = get_tags_by_ids(to_tag_ids) #all tags must belong to the same language - lang_codes = {tag.language_code for tag in (from_tags + to_tags)} + lang_codes = set(tag.language_code for tag in (from_tags + to_tags)) if len(lang_codes) != 1: langs = ', '.join(lang_codes) raise CommandError('all tags must belong to the same language, have: %s' % langs) diff --git a/askbot/migrations/0172_sync_thread_deleted.py b/askbot/migrations/0172_sync_thread_deleted.py index 961df840..222d2d77 100644 --- a/askbot/migrations/0172_sync_thread_deleted.py +++ b/askbot/migrations/0172_sync_thread_deleted.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from south.utils import datetime_utils as datetime +#from south.utils import datetime_utils as datetime from south.db import db from south.v2 import DataMigration from django.db import models diff --git a/askbot/models/post.py b/askbot/models/post.py index 7721b37b..fac0daf5 100644 --- a/askbot/models/post.py +++ b/askbot/models/post.py @@ -1489,9 +1489,22 @@ class Post(models.Model): ) return result + def cache_latest_revision(self, rev): + setattr(self, '_last_rev_cache', rev) def get_latest_revision(self): - return self.revisions.order_by('-revision')[0] + if hasattr(self, '_last_rev_cache'): + return self._last_rev_cache + rev = self.revisions.order_by('-revision')[0] + self.cache_latest_revision(rev) + return rev + + def get_earliest_revision(self): + if hasattr(self, '_first_rev_cache'): + return self._first_rev_cache + rev = self.revisions.order_by('revision')[0] + setattr(self, '_first_rev_cache', rev) + return rev def get_latest_revision_number(self): try: @@ -2223,6 +2236,8 @@ class PostRevisionManager(models.Manager): if needs_moderation: revision.place_on_moderation_queue() + revision.post.cache_latest_revision(revision) + return revision class PostRevision(models.Model): diff --git a/askbot/models/question.py b/askbot/models/question.py index 2ce7d124..05085959 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -1209,6 +1209,13 @@ class Thread(models.Model): post_to_author = dict() question_post = None for post in thread_posts: + + #precache some revision data + first_rev = post.get_earliest_revision() + last_rev = post.get_latest_revision() + first_rev.post = post + last_rev.post = post + #pass through only deleted question posts if post.deleted and post.post_type != 'question': continue diff --git a/askbot/templates/macros.html b/askbot/templates/macros.html index 942d150f..19aab815 100644 --- a/askbot/templates/macros.html +++ b/askbot/templates/macros.html @@ -52,42 +52,21 @@ </script> {%- endmacro -%} -{%- macro post_contributor_avatar_and_credentials(post, user, karma_mode = None, badges_mode = None) -%} - {% if post.is_anonymous %} +{%- macro post_contributor_avatar_and_credentials(revision) -%} + {% if revision.is_anonymous %} <img alt="{% trans %}anonymous user{% endtrans %}" src="{{ '/images/anon.png'|media }} " class="gravatar" width="32" height="32" /> - <p>{{ user.get_anonymous_name() }}</p> + <p>{{ revision.author.get_anonymous_name() }}</p> {% else %} - {{ user_card(user, karma_mode=karma_mode, badges_mode=badges_mode) }} + {{ user_card(revision.author, karma_mode=karma_mode, badges_mode=badges_mode) }} {% endif %} {% if settings.GROUPS_ENABLED %} - {{ user_primary_group(user) }} + {{ user_primary_group(revision.author) }} {% endif %} {%- endmacro -%} -{%- macro post_last_updater_and_creator_info( - post, min_rep_to_edit_wiki, karma_mode = None, badges_mode = None - ) -%} - {{ post_contributor_info( - post, "original_author", post.wiki, min_rep_to_edit_wiki, - karma_mode = karma_mode, badges_mode = badges_mode - ) - }} - {{ post_contributor_info( - post, "last_updater", post.wiki, min_rep_to_edit_wiki, - karma_mode = karma_mode, badges_mode = badges_mode - ) - }} -{%- endmacro -%} - -{%- macro post_contributor_info( - post, contributor_type, is_wiki, wiki_min_rep, - karma_mode = None, badges_mode = None - ) -%} -{# there is a whole bunch of trickery here, probably indicative of -poor design of the data or methods on data objects #} -{% if contributor_type=="original_author" %} +{%- macro post_last_updater_and_creator_info(post) -%} + {% if post.wiki %} <div class='post-update-info'> - {% if is_wiki %} <p> {%- if post.post_type == 'question' -%} {{ settings.WORDS_ASKED|escape }} @@ -103,61 +82,55 @@ poor design of the data or methods on data objects #} alt="{% trans %}this post is marked as community wiki{% endtrans %}" style="float:left" /> + {% set wiki_min_rep = settings.MIN_REP_TO_EDIT_WIKI %} <p class="tip">{% trans %}This post is a wiki. Anyone with karma >{{wiki_min_rep}} is welcome to improve it.{% endtrans %}</p> + </div> {% else %} - <p style="line-height:12px;"> - {# todo: access to class names needs to be removed here #} - {% if post.post_type == 'question' %} - {{ settings.WORDS_ASKED|escape }} - {% elif post.post_type == 'answer' %} - {{ settings.WORDS_ANSWERED|escape }} - {% else %} - {% trans %}posted{% endtrans %} - {% endif %} - {% if post.__class__.__name__ == 'PostRevision' %} - <strong>{{ timeago(post.revised_at) }}</strong> - {% else %} - <strong>{{ timeago(post.added_at) }}</strong> - {% endif %} - </p> - {{ post_contributor_avatar_and_credentials( - post, post.author, karma_mode = karma_mode, badges_mode = badges_mode - ) }} + {% set first_rev = post.get_earliest_revision() %} + {% set last_rev = post.get_latest_revision() %} + {{ post_contributor_info(first_rev, "original_author") }} + {% if first_rev != last_rev %} + {{ post_contributor_info(last_rev, "last_updater") }} + {% endif %} {% endif %} - </div> -{% elif contributor_type=="last_updater" %} - {% if post.post_type in ('question', 'answer') %} - {% set last_edited_at = post.last_edited_at %} - {% set original_author = post.author %} - {% set update_author = post.last_edited_by %} - {% elif post.__class__.__name__ == 'PostRevision' %} - {% set last_edited_at = post.revised_at %} - {% set original_author = None %}{# fake value to force display widget in the revision views #} - {% set update_author = post.author %} +{%- endmacro -%} + +{%- macro post_contributor_info(revision, contributor_type) -%} +<div class='post-update-info'> +{% if contributor_type=="original_author" %} + {% if revision.post.post_type == 'question' %} + {% set action_label = settings.WORDS_ASKED|escape %} + {% elif revision.post.post_type == 'answer' %} + {% set action_label = settings.WORDS_ANSWERED|escape %} + {% else %} + {% set action_label = gettext('posted') %} {% endif %} - {% if last_edited_at %} - <div class='post-update-info'> - <p style="line-height:12px;"> - <a - {% if post.post_type == 'question' %} - href="{% url question_revisions post.id %}" +{% else %} + {% set action_label = gettext('updated') %} +{% endif %} + {% if revision.post.post_type in ('question', 'answer') %} + {% set original_author = revision.post.author %} + {% else %} + {% set original_author = None %} + {% endif %} + <p style="line-height:12px;"> + <a + {% if revision.post.post_type == 'question' %} + href="{% url question_revisions revision.post.id %}" {% else %} - href="{% url answer_revisions post.id %}" - {% endif %} - >{% trans %}updated{% endtrans %} <strong>{{ timeago(last_edited_at) }}</strong></a> - </p> - {% if original_author != update_author or is_wiki %} - {{ - post_contributor_avatar_and_credentials( - post, update_author, - karma_mode = karma_mode, badges_mode = badges_mode - ) - }} + href="{% url answer_revisions revision.post.id %}" {% endif %} - </div> + >{{ action_label }} <strong>{{ timeago(revision.revised_at) }}</strong></a> + </p> + {% set show_user_info = (contributor_type == 'original_author' or + (contributor_type == 'last_updater' and + original_author != revision.author )) + %} + {% if show_user_info %} + {{ post_contributor_avatar_and_credentials(revision) }} {% endif %} -{% endif %} +</div> {%- endmacro -%} {%- macro if_else(condition, if_true, if_false) -%} diff --git a/askbot/templates/question/answer_author_info.html b/askbot/templates/question/answer_author_info.html index 1c729b51..54b36b28 100644 --- a/askbot/templates/question/answer_author_info.html +++ b/askbot/templates/question/answer_author_info.html @@ -1,8 +1 @@ -{{ - macros.post_last_updater_and_creator_info( - answer, - settings.MIN_REP_TO_EDIT_WIKI, - karma_mode = settings.KARMA_MODE, - badges_mode = settings.BADGES_MODE - ) -}} +{{ macros.post_last_updater_and_creator_info(answer) }} diff --git a/askbot/templates/question/question_author_info.html b/askbot/templates/question/question_author_info.html index c25b7d84..368344a5 100644 --- a/askbot/templates/question/question_author_info.html +++ b/askbot/templates/question/question_author_info.html @@ -1,8 +1 @@ -{{ - macros.post_last_updater_and_creator_info( - question, - settings.MIN_REP_TO_EDIT_WIKI, - karma_mode = settings.KARMA_MODE, - badges_mode = settings.BADGES_MODE - ) -}} +{{ macros.post_last_updater_and_creator_info(question) }} diff --git a/askbot/templates/revisions.html b/askbot/templates/revisions.html index 1617ff25..24038b20 100644 --- a/askbot/templates/revisions.html +++ b/askbot/templates/revisions.html @@ -49,12 +49,7 @@ {% else %} {% set contributor_type = "last_updater" %} {% endif %} - {{ macros.post_contributor_info( - revision, - contributor_type, - False, - 0, - ) + {{ macros.post_contributor_info(revision, contributor_type) }} </div> </td> diff --git a/askbot/views/readers.py b/askbot/views/readers.py index 79db9a12..2e3c8249 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -673,6 +673,7 @@ def question(request, id):#refactor - long subroutine. display question body, an extra = context.get_extra('ASKBOT_QUESTION_PAGE_EXTRA_CONTEXT', request, data) data.update(extra) + #print 'generated in ', datetime.datetime.now() - before return render(request, 'question.html', data) def revisions(request, id, post_type = None): |