]> git.openstreetmap.org Git - osqa.git/commitdiff
Retouched community wiki workflow.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 25 May 2010 23:00:56 +0000 (23:00 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Tue, 25 May 2010 23:00:56 +0000 (23:00 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@331 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/forms.py
forum/models/user.py
forum/skins/default/media/style/style.css
forum/skins/default/templates/node/post_controls.html
forum/skins/default/templates/question.html
forum/templatetags/node_tags.py
forum/views/commands.py
forum/views/writers.py

index 34fa271a1282d94e3f9ce9faba086b273afc4106..f2e46b8eb4ab183d2e6c2bb2c0c057c80a4ce8b5 100644 (file)
@@ -97,13 +97,15 @@ class TagNamesField(forms.CharField):
         return u' '.join(list_temp)
 
 class WikiField(forms.BooleanField):
         return u' '.join(list_temp)
 
 class WikiField(forms.BooleanField):
-    def __init__(self, *args, **kwargs):
+    def __init__(self, disabled=False, *args, **kwargs):
         super(WikiField, self).__init__(*args, **kwargs)
         self.required = False
         self.label  = _('community wiki')
         self.help_text = _('if you choose community wiki option, the question and answer do not generate points and name of author will not be shown')
         super(WikiField, self).__init__(*args, **kwargs)
         self.required = False
         self.label  = _('community wiki')
         self.help_text = _('if you choose community wiki option, the question and answer do not generate points and name of author will not be shown')
+        if disabled:
+            self.widget=forms.CheckboxInput(attrs={'disabled': "disabled"})
     def clean(self,value):
     def clean(self,value):
-        return value and settings.WIKI_ON
+        return value
 
 class EmailNotifyField(forms.BooleanField):
     def __init__(self, *args, **kwargs):
 
 class EmailNotifyField(forms.BooleanField):
     def __init__(self, *args, **kwargs):
@@ -131,8 +133,11 @@ class AskForm(forms.Form):
     title  = TitleField()
     text   = QuestionEditorField()
     tags   = TagNamesField()
     title  = TitleField()
     text   = QuestionEditorField()
     tags   = TagNamesField()
-    wiki = WikiField()
 
 
+    def __init__(self, *args, **kwargs):
+        super(AskForm, self).__init__(*args, **kwargs)
+        if settings.WIKI_ON:
+            self.fields['wiki'] = WikiField()
 
 class AnswerForm(forms.Form):
     text   = AnswerEditorField()
 
 class AnswerForm(forms.Form):
     text   = AnswerEditorField()
@@ -141,8 +146,11 @@ class AnswerForm(forms.Form):
     def __init__(self, question, *args, **kwargs):
         super(AnswerForm, self).__init__(*args, **kwargs)
 
     def __init__(self, question, *args, **kwargs):
         super(AnswerForm, self).__init__(*args, **kwargs)
 
-        if question.nis.wiki and settings.WIKI_ON:
-            self.fields['wiki'].initial = True
+        if settings.WIKI_ON:
+            self.fields['wiki'] = WikiField()
+
+            if question.nis.wiki:
+                self.fields['wiki'].initial = True
 
 
 class RetagQuestionForm(forms.Form):
 
 
 class RetagQuestionForm(forms.Form):
@@ -176,7 +184,7 @@ class EditQuestionForm(forms.Form):
     tags   = TagNamesField()
     summary = SummaryField()
 
     tags   = TagNamesField()
     summary = SummaryField()
 
-    def __init__(self, question, revision=None, *args, **kwargs):
+    def __init__(self, question, user, revision=None, *args, **kwargs):
         super(EditQuestionForm, self).__init__(*args, **kwargs)
 
         if revision is None:
         super(EditQuestionForm, self).__init__(*args, **kwargs)
 
         if revision is None:
@@ -185,16 +193,15 @@ class EditQuestionForm(forms.Form):
         self.fields['title'].initial = revision.title
         self.fields['text'].initial = revision.body
         self.fields['tags'].initial = revision.tagnames
         self.fields['title'].initial = revision.title
         self.fields['text'].initial = revision.body
         self.fields['tags'].initial = revision.tagnames
-            
-        # Once wiki mode is enabled, it can't be disabled
-        if settings.WIKI_ON and not question.nis.wiki:
-            self.fields['wiki'] = WikiField()
+
+        if settings.WIKI_ON:
+            self.fields['wiki'] = WikiField(disabled=(question.nis.wiki and not user.can_cancel_wiki(question)), initial=question.nis.wiki)
 
 class EditAnswerForm(forms.Form):
     text = AnswerEditorField()
     summary = SummaryField()
 
 
 class EditAnswerForm(forms.Form):
     text = AnswerEditorField()
     summary = SummaryField()
 
-    def __init__(self, answer, revision=None, *args, **kwargs):
+    def __init__(self, answer, user, revision=None, *args, **kwargs):
         super(EditAnswerForm, self).__init__(*args, **kwargs)
 
         if revision is None:
         super(EditAnswerForm, self).__init__(*args, **kwargs)
 
         if revision is None:
@@ -202,6 +209,9 @@ class EditAnswerForm(forms.Form):
 
         self.fields['text'].initial = revision.body
 
 
         self.fields['text'].initial = revision.body
 
+        if settings.WIKI_ON:
+            self.fields['wiki'] = WikiField(disabled=(answer.nis.wiki and not user.can_cancel_wiki(answer)), initial=answer.nis.wiki)
+
 class EditUserForm(forms.Form):
     email = forms.EmailField(label=u'Email', help_text=_('this email does not have to be linked to gravatar'), required=True, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))
     realname = forms.CharField(label=_('Real name'), required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))
 class EditUserForm(forms.Form):
     email = forms.EmailField(label=u'Email', help_text=_('this email does not have to be linked to gravatar'), required=True, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))
     realname = forms.CharField(label=_('Real name'), required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35}))
index a3714ae9c4212135b9bc871be6ebd7b2a7441f48..6f7613a31cc4239bb00e99f7b56016e862819b7b 100644 (file)
@@ -67,6 +67,9 @@ class AnonymousUser(DjangoAnonymousUser):
     def can_wikify(self, post):\r
         return False\r
 \r
     def can_wikify(self, post):\r
         return False\r
 \r
+    def can_cancel_wiki(self, post):\r
+        return False\r
+\r
     def can_retag_questions(self):\r
         return False\r
 \r
     def can_retag_questions(self):\r
         return False\r
 \r
@@ -223,6 +226,10 @@ class User(BaseModel, DjangoUser):
     def can_wikify(self, post):\r
         return self == post.author or self.reputation >= int(settings.REP_TO_WIKIFY)\r
 \r
     def can_wikify(self, post):\r
         return self == post.author or self.reputation >= int(settings.REP_TO_WIKIFY)\r
 \r
+    @true_if_is_super_or_staff\r
+    def can_cancel_wiki(self, post):\r
+        return self == post.author\r
+\r
     @true_if_is_super_or_staff\r
     def can_retag_questions(self):\r
         return self.reputation >= int(settings.REP_TO_RETAG)\r
     @true_if_is_super_or_staff\r
     def can_retag_questions(self):\r
         return self.reputation >= int(settings.REP_TO_RETAG)\r
index a90868448d7449f28ad16bc4210cfdaf70fab568..7cfa0e2f9bb7f14416e522666bb7c46008d51cf9 100644 (file)
@@ -1173,7 +1173,7 @@ a.accept-answer.on,a.accept-answer:hover { background: url("../images/vote-accep
     color: #333;
     background: url("../images/wiki.png") no-repeat left center;
     padding-left: 36px;
     color: #333;
     background: url("../images/wiki.png") no-repeat left center;
     padding-left: 36px;
-    margin: 6px 0 18px 0;
+    margin: 6px 0 0 0;
     min-height: 32px;
     line-height: 15px;
 }
     min-height: 32px;
     line-height: 15px;
 }
@@ -1303,12 +1303,16 @@ div.comment-tools a:hover {
        text-decoration: none;
 }
 
        text-decoration: none;
 }
 
-.action-link {
+.action-link {
        color: #777777;
        cursor: pointer;
        padding: 3px;
 }
 
        color: #777777;
        cursor: pointer;
        padding: 3px;
 }
 
+.action-link a {
+    color: inherit;
+}
+
 .action-link a.ajax-command:hover {
        background-color: #777777;
        color: #FFFFFF;
 .action-link a.ajax-command:hover {
        background-color: #777777;
        color: #FFFFFF;
index c8808a9c63e2c7a6d28a57c6eb32e115547f80ad..c34e50fff1cf6af442fb9304953770e085b13c6f 100644 (file)
@@ -9,8 +9,9 @@
     {% endifnotequal %}\r
 {% endfor %}\r
 {% if menu|length %}\r
     {% endifnotequal %}\r
 {% endfor %}\r
 {% if menu|length %}\r
-    | <span id="node-{{ node.id }}-menu" class="context-menu">\r
-        <span id="node-{{ node.id }}-menu-trigger" class="context-menu-trigger">{% trans "more" %} &#9660;</span>\r
+    <span class="action-link-separator">|</span>\r
+    <span id="node-{{ node.id }}-menu" class="context-menu">\r
+        <span id="node-{{ node.id }}-menu-trigger" class="action-link context-menu-trigger">{% trans "more" %} &#9660;</span>\r
         <ul id="node-{{ node.id }}-menu-dropdown" class="context-menu-dropdown">\r
             {% for item in menu %}\r
             <li class="item"><a class="{{ item.classes }}" href="{{ item.url }}" title="{{ item.title }}" >{{ item.text }}</a></li>\r
         <ul id="node-{{ node.id }}-menu-dropdown" class="context-menu-dropdown">\r
             {% for item in menu %}\r
             <li class="item"><a class="{{ item.classes }}" href="{{ item.url }}" title="{{ item.title }}" >{{ item.text }}</a></li>\r
index 9a3384621d281d72f5f9f001a8737f3f507646f6..b8798742ac5d298709d1b15271ea7779a5d8c36c 100644 (file)
                                         </div>\r
                                         <div class="answer-controls post-controls">\r
                                             {% post_controls answer request.user %}\r
                                         </div>\r
                                         <div class="answer-controls post-controls">\r
                                             {% post_controls answer request.user %}\r
+                                            {% wiki_symbol request.user answer %}\r
                                         </div>\r
                                         <div class="post-update-info-container">\r
                                             {% contributors_info answer %}\r
                                         </div>\r
                                         <div class="post-update-info-container">\r
                                             {% contributors_info answer %}\r
index f12476162022c0e7011b6d66759e68f95c827e29..82f6b71e259564d37bdcd4e87de1bbbae58f7c71 100644 (file)
@@ -96,9 +96,14 @@ def post_controls(post, user):
                 controls.append(post_control(_('delete'), reverse('delete_post', kwargs={'id': post.id}),\r
                         command=True, confirm=True))\r
 \r
                 controls.append(post_control(_('delete'), reverse('delete_post', kwargs={'id': post.id}),\r
                         command=True, confirm=True))\r
 \r
-        if (not post.nis.wiki) and user.can_wikify(post):\r
-            menu.append(post_control(_('mark as community wiki'), reverse('wikify', kwargs={'id': post.id}),\r
-                        command=True, confirm=True))\r
+        if settings.WIKI_ON:\r
+            if (not post.nis.wiki) and user.can_wikify(post):\r
+                menu.append(post_control(_('mark as community wiki'), reverse('wikify', kwargs={'id': post.id}),\r
+                            command=True, confirm=True))\r
+\r
+            elif post.nis.wiki and user.can_cancel_wiki(post):\r
+                menu.append(post_control(_('cancel community wiki'), reverse('wikify', kwargs={'id': post.id}),\r
+                            command=True, confirm=True))\r
 \r
         if post.node_type == "answer" and user.can_convert_to_comment(post):\r
             menu.append(post_control(_('convert to comment'), reverse('convert_to_comment', kwargs={'id': post.id}),\r
 \r
         if post.node_type == "answer" and user.can_convert_to_comment(post):\r
             menu.append(post_control(_('convert to comment'), reverse('convert_to_comment', kwargs={'id': post.id}),\r
index 40d61ec07959a32544b724e582d44659c229aad4..456199d8c1c05d75e996c20e42df288796631e46 100644 (file)
@@ -361,19 +361,24 @@ def close(request, id, close):
 @command
 def wikify(request, id):
     node = get_object_or_404(Node, id=id)
 @command
 def wikify(request, id):
     node = get_object_or_404(Node, id=id)
-
-    if node.nis.wiki:
-        raise CommandException(_("This post is already marked as community wiky."))
-
     user = request.user
 
     if not user.is_authenticated():
         raise AnonymousNotAllowedException(_('mark posts as community wiki'))
 
     user = request.user
 
     if not user.is_authenticated():
         raise AnonymousNotAllowedException(_('mark posts as community wiki'))
 
-    if not user.can_wikify(node):
-        raise NotEnoughRepPointsException(_('mark posts as community wiki'))
+    if node.nis.wiki:
+        if not user.can_cancel_wiki(node):
+            raise NotEnoughRepPointsException(_('cancel a community wiki post'))
+
+        if node.nstate.wiki.action_type == "wikify":
+            node.nstate.wiki.cancel()
+        else:
+            node.nstate.wiki = None
+    else:
+        if not user.can_wikify(node):
+            raise NotEnoughRepPointsException(_('mark posts as community wiki'))
 
 
-    WikifyAction(node=node, user=user, ip=request.META['REMOTE_ADDR']).save()
+        WikifyAction(node=node, user=user, ip=request.META['REMOTE_ADDR']).save()
 
     return {
         'commands': {
 
     return {
         'commands': {
index 5bddc6040b070c692cf8e21bdf98bf40e9d737a8..99e93775015f28b84b9902ee2c441d3effd9726a 100644 (file)
@@ -70,7 +70,12 @@ def ask(request):
         form = AskForm(request.POST)
         if form.is_valid():
             if request.user.is_authenticated():
         form = AskForm(request.POST)
         if form.is_valid():
             if request.user.is_authenticated():
-                question = AskAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data).node
+                ask_action = AskAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
+                question = ask_action.node
+
+                if settings.WIKI_ON and request.POST.get('wiki', False):
+                    question.nstate.wiki = ask_action
+
                 return HttpResponseRedirect(question.get_absolute_url())
             else:
                 request.session['temp_node_data'] = request.POST
                 return HttpResponseRedirect(question.get_absolute_url())
             else:
                 request.session['temp_node_data'] = request.POST
@@ -123,13 +128,19 @@ def _edit_question(request, question):
         revision = question.revisions.get(revision=revision_form.cleaned_data['revision'])
 
         if 'select_revision' in request.POST:
         revision = question.revisions.get(revision=revision_form.cleaned_data['revision'])
 
         if 'select_revision' in request.POST:
-            form = EditQuestionForm(question, revision)
+            form = EditQuestionForm(question, request.user, revision)
         else:
         else:
-            form = EditQuestionForm(question, revision, data=request.POST)
+            form = EditQuestionForm(question, request.user, revision, data=request.POST)
 
         if not 'select_revision' in request.POST and form.is_valid():
             if form.has_changed():
 
         if not 'select_revision' in request.POST and form.is_valid():
             if form.has_changed():
-                ReviseAction(user=request.user, node=question, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
+                action = ReviseAction(user=request.user, node=question, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
+
+                if settings.WIKI_ON:
+                    if request.POST.get('wiki', False) and not question.nis.wiki:
+                        question.nstate.wiki = action
+                    elif question.nis.wiki and (not request.POST.get('wiki', False)) and request.user.can_cancel_wiki(question):
+                        question.nstate.wiki = None
             else:
                 if not revision == question.active_revision:
                     RollbackAction(user=request.user, node=question).save(data=dict(activate=revision))
             else:
                 if not revision == question.active_revision:
                     RollbackAction(user=request.user, node=question).save(data=dict(activate=revision))
@@ -137,7 +148,7 @@ def _edit_question(request, question):
             return HttpResponseRedirect(question.get_absolute_url())
     else:
         revision_form = RevisionForm(question)
             return HttpResponseRedirect(question.get_absolute_url())
     else:
         revision_form = RevisionForm(question)
-        form = EditQuestionForm(question)
+        form = EditQuestionForm(question, request.user)
 
     return render_to_response('question_edit.html', {
         'question': question,
 
     return render_to_response('question_edit.html', {
         'question': question,
@@ -160,13 +171,19 @@ def edit_answer(request, id):
         revision = answer.revisions.get(revision=revision_form.cleaned_data['revision'])
 
         if 'select_revision' in request.POST:
         revision = answer.revisions.get(revision=revision_form.cleaned_data['revision'])
 
         if 'select_revision' in request.POST:
-            form = EditAnswerForm(answer, revision)
+            form = EditAnswerForm(answer, request.user, revision)
         else:
         else:
-            form = EditAnswerForm(answer, revision, data=request.POST)
+            form = EditAnswerForm(answer, request.user, revision, data=request.POST)
 
         if not 'select_revision' in request.POST and form.is_valid():
             if form.has_changed():
 
         if not 'select_revision' in request.POST and form.is_valid():
             if form.has_changed():
-                ReviseAction(user=request.user, node=answer, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
+                action = ReviseAction(user=request.user, node=answer, ip=request.META['REMOTE_ADDR']).save(data=form.cleaned_data)
+
+                if settings.WIKI_ON:
+                    if request.POST.get('wiki', False) and not answer.nis.wiki:
+                        answer.nstate.wiki = action
+                    elif answer.nis.wiki and (not request.POST.get('wiki', False)) and request.user.can_cancel_wiki(answer):
+                        answer.nstate.wiki = None
             else:
                 if not revision == answer.active_revision:
                     RollbackAction(user=request.user, node=answer, ip=request.META['REMOTE_ADDR']).save(data=dict(activate=revision))
             else:
                 if not revision == answer.active_revision:
                     RollbackAction(user=request.user, node=answer, ip=request.META['REMOTE_ADDR']).save(data=dict(activate=revision))
@@ -175,7 +192,7 @@ def edit_answer(request, id):
 
     else:
         revision_form = RevisionForm(answer)
 
     else:
         revision_form = RevisionForm(answer)
-        form = EditAnswerForm(answer)
+        form = EditAnswerForm(answer, request.user)
     return render_to_response('answer_edit.html', {
                               'answer': answer,
                               'revision_form': revision_form,
     return render_to_response('answer_edit.html', {
                               'answer': answer,
                               'revision_form': revision_form,
@@ -189,7 +206,12 @@ def answer(request, id):
         form = AnswerForm(question, request.POST)
         if form.is_valid():
             if request.user.is_authenticated():
         form = AnswerForm(question, request.POST)
         if form.is_valid():
             if request.user.is_authenticated():
-                answer = AnswerAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(dict(question=question, **form.cleaned_data)).node
+                answer_action = AnswerAction(user=request.user, ip=request.META['REMOTE_ADDR']).save(dict(question=question, **form.cleaned_data))
+                answer = answer_action.node
+
+                if settings.WIKI_ON and request.POST.get('wiki', False):
+                    answer.nstate.wiki = answer_action
+
                 return HttpResponseRedirect(answer.get_absolute_url())
             else:
                 request.session['temp_node_data'] = request.POST
                 return HttpResponseRedirect(answer.get_absolute_url())
             else:
                 request.session['temp_node_data'] = request.POST