diff options
-rw-r--r-- | askbot/models/__init__.py | 23 | ||||
-rw-r--r-- | askbot/skins/common/media/js/post.js | 80 | ||||
-rw-r--r-- | askbot/skins/common/templates/question/answer_controls.html | 16 | ||||
-rw-r--r-- | askbot/skins/common/templates/question/question_controls.html | 20 | ||||
-rw-r--r-- | askbot/views/commands.py | 17 |
5 files changed, 135 insertions, 21 deletions
diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index 9f5e8999..05cc44aa 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -1977,8 +1977,26 @@ def downvote(self, post, timestamp=None, cancel=False, force = False): ) @auto_now_timestamp -def flag_post(user, post, timestamp=None, cancel=False, force = False): - if cancel:#todo: can't unflag? +def flag_post(user, post, timestamp=None, cancel=False, cancel_all = False, force = False): + if cancel_all: + # remove all flags + if force == False: + user.assert_can_remove_all_flags_offensive(post = post) + post_content_type = ContentType.objects.get_for_model(post) + all_flags = Activity.objects.filter( + activity_type = const.TYPE_ACTIVITY_MARK_OFFENSIVE, + content_type = post_content_type, object_id=post.id + ) + for flag in all_flags: + auth.onUnFlaggedItem(post, flag.user, timestamp=timestamp) + award_badges_signal.send(None, + event = 'flag_post', + actor = flag.user, + context_object = post, + timestamp = timestamp + ) + + elif cancel:#todo: can't unflag? if force == False: user.assert_can_remove_flag_offensive(post = post) auth.onUnFlaggedItem(post, user, timestamp=timestamp) @@ -1988,6 +2006,7 @@ def flag_post(user, post, timestamp=None, cancel=False, force = False): context_object = post, timestamp = timestamp ) + else: if force == False: user.assert_can_flag_offensive(post = post) diff --git a/askbot/skins/common/media/js/post.js b/askbot/skins/common/media/js/post.js index 59ba4fff..22e2b6c4 100644 --- a/askbot/skins/common/media/js/post.js +++ b/askbot/skins/common/media/js/post.js @@ -271,11 +271,11 @@ var Vote = function(){ var commentLinkIdPrefix = 'comment-'; var voteNumberClass = "vote-number"; var offensiveIdPrefixQuestionFlag = 'question-offensive-flag-'; - var removeOffensiveIdPrefixQuestionFlag = 'question-offensive-flag-remove-'; - var removeAllOffensiveIdPrefixQuestionFlag = 'question-offensive-flag-remove-all-'; + var removeOffensiveIdPrefixQuestionFlag = 'question-offensive-remove-flag-'; + var removeAllOffensiveIdPrefixQuestionFlag = 'question-offensive-remove-all-flag-'; var offensiveIdPrefixAnswerFlag = 'answer-offensive-flag-'; - var removeOffensiveIdPrefixAnswerFlag = 'answer-offensive-flag-remove-'; - var removeAllOffensiveIdPrefixAnswerFlag = 'answer-offensive-flag-remove-all'; + var removeOffensiveIdPrefixAnswerFlag = 'answer-offensive-remove-flag-'; + var removeAllOffensiveIdPrefixAnswerFlag = 'answer-offensive-remove-all-flag-'; var offensiveClassFlag = 'offensive-flag'; var questionControlsId = 'question-controls'; var removeQuestionLinkIdPrefix = 'question-delete-link-'; @@ -472,7 +472,7 @@ var Vote = function(){ }); getRemoveAllOffensiveQuestionFlag().unbind('click').click(function(event){ - Vote.remove_offensive(this, VoteType.removeAllOffensiveQuestion); + Vote.remove_all_offensive(this, VoteType.removeAllOffensiveQuestion); }); getOffensiveAnswerFlags().unbind('click').click(function(event){ @@ -484,7 +484,7 @@ var Vote = function(){ }); getRemoveAllOffensiveAnswerFlag().unbind('click').click(function(event){ - Vote.remove_offensive(this, VoteType.removeAllOffensiveAnswer); + Vote.remove_all_offensive(this, VoteType.removeAllOffensiveAnswer); }); getremoveQuestionLink().unbind('click').click(function(event){ @@ -651,7 +651,7 @@ var Vote = function(){ // Change the link text and rebind events $(object).find("a.question-flag").html(gettext("remove flag")); var obj_id = $(object).attr("id"); - $(object).attr("id", obj_id.replace("flag-", "flag-remove-")); + $(object).attr("id", obj_id.replace("flag-", "remove-flag-")); getRemoveOffensiveQuestionFlag().unbind('click').click(function(event){ Vote.remove_offensive(this, VoteType.removeOffensiveQuestion); @@ -672,14 +672,53 @@ var Vote = function(){ //to django.po files //_('anonymous users cannot flag offensive posts') + pleaseLogin; if (data.success == "1"){ - if(data.count > 0) - $(object).children('span[class=darkred]').text("("+ data.count +")"); - else + if(data.count > 0){ + $(object).children('span[class=darkred]').text("("+ data.count +")"); + } + else{ $(object).children('span[class=darkred]').text(""); + // Remove "remove all flags link" since there are no more flags to remove + var remove_all = $(object).siblings("span.offensive-flag[id*=-offensive-remove-all-flag-]"); + $(remove_all).next("span.sep").remove(); + $(remove_all).remove(); + } // Change the link text and rebind events $(object).find("a.question-flag").html(gettext("flag offensive")); var obj_id = $(object).attr("id"); - $(object).attr("id", obj_id.replace("flag-remove-", "flag-")); + $(object).attr("id", obj_id.replace("remove-flag-", "flag-")); + + getOffensiveQuestionFlag().unbind('click').click(function(event){ + Vote.offensive(this, VoteType.offensiveQuestion); + }); + + getOffensiveAnswerFlags().unbind('click').click(function(event){ + Vote.offensive(this, VoteType.offensiveAnswer); + }); + } + else { + object = $(object); + showMessage(object, data.message) + } + }; + + var callback_remove_all_offensive = function(object, voteType, data){ + //todo: transfer proper translations of these from i18n.js + //to django.po files + //_('anonymous users cannot flag offensive posts') + pleaseLogin; + if (data.success == "1"){ + if(data.count > 0) + $(object).children('span[class=darkred]').text("("+ data.count +")"); + else + $(object).children('span[class=darkred]').text(""); + // remove the link. All flags are gone + var remove_own = $(object).siblings("span.offensive-flag[id*=-offensive-remove-flag-]") + $(remove_own).find("a.question-flag").html(gettext("flag offensive")); + $(remove_own).attr("id", $(remove_own).attr("id").replace("remove-flag-", "flag-")); + + $(object).next("span.sep").remove(); + $(object).remove(); + + getOffensiveQuestionFlag().unbind('click').click(function(event){ Vote.offensive(this, VoteType.offensiveQuestion); @@ -815,6 +854,25 @@ var Vote = function(){ submit(object, voteType, callback_remove_offensive); } }, + remove_all_offensive: function(object, voteType){ + if (!currentUserId || currentUserId.toUpperCase() == "NONE"){ + showMessage( + $(object), + offensiveAnonymousMessage.replace( + "{{QuestionID}}", + questionId + ).replace( + '{{questionSlug}}', + questionSlug + ) + ); + return false; + } + if (confirm(removeOffensiveConfirmation)){ + postId = object.id.substr(object.id.lastIndexOf('-') + 1); + submit(object, voteType, callback_remove_all_offensive); + } + }, //delete question or answer (comments are deleted separately) remove: function(object, voteType){ if (!currentUserId || currentUserId.toUpperCase() == "NONE"){ diff --git a/askbot/skins/common/templates/question/answer_controls.html b/askbot/skins/common/templates/question/answer_controls.html index 9ae6e8dd..562aa9d1 100644 --- a/askbot/skins/common/templates/question/answer_controls.html +++ b/askbot/skins/common/templates/question/answer_controls.html @@ -9,6 +9,14 @@ {% if request.user|can_edit_post(answer) %}{{ pipe() }} <span class="action-link"><a class="question-edit" href="{% url edit_answer answer.id %}">{% trans %}edit{% endtrans %}</a></span> {% endif %} + +{% if request.user|can_remove_all_flags_offensive(answer)%}{{ pipe() }} +<span id="answer-offensive-remove-all-flag-{{ answer.id }}" class="offensive-flag" + title="{% trans %}remove all flags{% endtrans %}"> + <a class="question-flag">{% trans %}remove all flags{% endtrans %}</a> +</span> +{%endif%} + {% if request.user|can_flag_offensive(answer) %}{{ pipe() }} <span id="answer-offensive-flag-{{ answer.id }}" class="offensive-flag" title="{% trans %}report as offensive (i.e containing spam, advertising, malicious text, etc.){% endtrans %}"> @@ -18,15 +26,17 @@ {% endif %} </a> </span> + {% elif request.user|can_remove_flag_offensive(answer)%}{{ pipe() }} -<span id="answer-offensive-flag-remove-{{ answer.id }}" class="offensive-flag" +<span id="answer-offensive-remove-flag-{{ answer.id }}" class="offensive-flag" title="{% trans %}report as offensive (i.e containing spam, advertising, malicious text, etc.){% endtrans %}"> - <a class="question-flag">{% trans %}remove flag{% endtrans %}</a> + <a class="question-flag">{% trans %}remove flag{% endtrans %} {% if request.user|can_see_offensive_flags(answer) %} <span class="darkred">{% if answer.offensive_flag_count > 0 %}({{ answer.offensive_flag_count }}){% endif %}</span> - {% endif %} + {% endif %}</a> </span> {% endif %} + {% if request.user|can_delete_post(answer) %}{{ pipe() }} {% spaceless %} <span class="action-link"> diff --git a/askbot/skins/common/templates/question/question_controls.html b/askbot/skins/common/templates/question/question_controls.html index ab41f769..54e70d11 100644 --- a/askbot/skins/common/templates/question/question_controls.html +++ b/askbot/skins/common/templates/question/question_controls.html @@ -17,24 +17,34 @@ <a class="question-close" href="{% url close question.id %}">{% trans %}close{% endtrans %}</a> {% endif %} {% endif %} + +{% if request.user|can_remove_all_flags_offensive(question)%}{{ pipe() }} +<span id="question-offensive-remove-all-flag-{{ question.id }}" class="offensive-flag" + title="{% trans %}remove all flags{% endtrans %}"> + <a class="question-flag">{% trans %}remove all flags{% endtrans %}</a> +</span> +{%endif%} + {% if request.user|can_flag_offensive(question) %}{{ pipe() }} <span id="question-offensive-flag-{{ question.id }}" class="offensive-flag" title="{% trans %}report as offensive (i.e containing spam, advertising, malicious text, etc.){% endtrans %}"> <a class="question-flag">{% trans %}flag offensive{% endtrans %} {% if request.user|can_see_offensive_flags(question) %} <span class="darkred">{% if question.offensive_flag_count > 0 %}({{ question.offensive_flag_count }}){% endif %}</span> - {% endif %} - </a> + {% endif %}</a> </span> + {% elif request.user|can_remove_flag_offensive(question)%}{{ pipe() }} -<span id="question-offensive-flag-remove-{{ question.id }}" class="offensive-flag" +<span id="question-offensive-remove-flag-{{ question.id }}" class="offensive-flag" title="{% trans %}report as offensive (i.e containing spam, advertising, malicious text, etc.){% endtrans %}"> - <a class="question-flag">{% trans %}remove flag{% endtrans %}</a> + <a class="question-flag">{% trans %}remove flag{% endtrans %} {% if request.user|can_see_offensive_flags(question) %} <span class="darkred">{% if question.offensive_flag_count > 0 %}({{ question.offensive_flag_count }}){% endif %}</span> - {% endif %} + {% endif %}</a> </span> + {% endif %} + {% if request.user|can_delete_post(question) %}{{ pipe() }} <a id="question-delete-link-{{question.id}}" class="question-delete">{% if question.deleted %}{% trans %}undelete{% endtrans %}{% else %}{% trans %}delete{% endtrans %}{% endif %}</a> {% endif %} diff --git a/askbot/views/commands.py b/askbot/views/commands.py index 2eb562ed..2022b148 100644 --- a/askbot/views/commands.py +++ b/askbot/views/commands.py @@ -148,7 +148,11 @@ def vote(request, id): answerUpVote: 5, answerDownVote:6, offensiveQuestion : 7, + remove offensiveQuestion flag : 7.5, + remove all offensiveQuestion flag : 7.6, offensiveAnswer:8, + remove offensiveAnswer flag : 8.5, + remove all offensiveAnswer flag : 8.6, removeQuestion: 9, removeAnswer:10 questionSubscribeUpdates:11 @@ -257,6 +261,19 @@ def vote(request, id): response_data['count'] = post.offensive_flag_count response_data['success'] = 1 + + elif vote_type in ['7.6', '8.6']: + #flag question or answer + if vote_type == '7.6': + post = get_object_or_404(models.Question, id=id) + if vote_type == '8.6': + id = request.POST.get('postId') + post = get_object_or_404(models.Answer, id=id) + + request.user.flag_post(post, cancel_all = True) + + response_data['count'] = post.offensive_flag_count + response_data['success'] = 1 elif vote_type in ['9', '10']: #delete question or answer |