From be26ac9493b40e87e07c773a8d7c79ef1e8b7b48 Mon Sep 17 00:00:00 2001 From: hernani Date: Tue, 25 May 2010 23:00:56 +0000 Subject: [PATCH] Retouched community wiki workflow. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@331 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/forms.py | 32 +++++++++----- forum/models/user.py | 7 ++++ forum/skins/default/media/style/style.css | 8 +++- .../default/templates/node/post_controls.html | 5 ++- forum/skins/default/templates/question.html | 1 + forum/templatetags/node_tags.py | 11 +++-- forum/views/commands.py | 19 +++++---- forum/views/writers.py | 42 ++++++++++++++----- 8 files changed, 90 insertions(+), 35 deletions(-) diff --git a/forum/forms.py b/forum/forms.py index 34fa271..f2e46b8 100644 --- a/forum/forms.py +++ b/forum/forms.py @@ -97,13 +97,15 @@ class TagNamesField(forms.CharField): 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') + if disabled: + self.widget=forms.CheckboxInput(attrs={'disabled': "disabled"}) def clean(self,value): - return value and settings.WIKI_ON + return value class EmailNotifyField(forms.BooleanField): def __init__(self, *args, **kwargs): @@ -131,8 +133,11 @@ class AskForm(forms.Form): 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() @@ -141,8 +146,11 @@ class AnswerForm(forms.Form): 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): @@ -176,7 +184,7 @@ class EditQuestionForm(forms.Form): 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: @@ -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 - - # 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() - 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: @@ -202,6 +209,9 @@ class EditAnswerForm(forms.Form): 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})) diff --git a/forum/models/user.py b/forum/models/user.py index a3714ae..6f7613a 100644 --- a/forum/models/user.py +++ b/forum/models/user.py @@ -67,6 +67,9 @@ class AnonymousUser(DjangoAnonymousUser): def can_wikify(self, post): return False + def can_cancel_wiki(self, post): + return False + def can_retag_questions(self): return False @@ -223,6 +226,10 @@ class User(BaseModel, DjangoUser): def can_wikify(self, post): return self == post.author or self.reputation >= int(settings.REP_TO_WIKIFY) + @true_if_is_super_or_staff + def can_cancel_wiki(self, post): + return self == post.author + @true_if_is_super_or_staff def can_retag_questions(self): return self.reputation >= int(settings.REP_TO_RETAG) diff --git a/forum/skins/default/media/style/style.css b/forum/skins/default/media/style/style.css index a908684..7cfa0e2 100644 --- a/forum/skins/default/media/style/style.css +++ b/forum/skins/default/media/style/style.css @@ -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; - margin: 6px 0 18px 0; + margin: 6px 0 0 0; min-height: 32px; line-height: 15px; } @@ -1303,12 +1303,16 @@ div.comment-tools a:hover { text-decoration: none; } -.action-link a { +.action-link { color: #777777; cursor: pointer; padding: 3px; } +.action-link a { + color: inherit; +} + .action-link a.ajax-command:hover { background-color: #777777; color: #FFFFFF; diff --git a/forum/skins/default/templates/node/post_controls.html b/forum/skins/default/templates/node/post_controls.html index c8808a9..c34e50f 100644 --- a/forum/skins/default/templates/node/post_controls.html +++ b/forum/skins/default/templates/node/post_controls.html @@ -9,8 +9,9 @@ {% endifnotequal %} {% endfor %} {% if menu|length %} - | - {% trans "more" %} ▼ + | + + {% trans "more" %} ▼
    {% for item in menu %}
  • {{ item.text }}
  • diff --git a/forum/skins/default/templates/question.html b/forum/skins/default/templates/question.html index 9a33846..b879874 100644 --- a/forum/skins/default/templates/question.html +++ b/forum/skins/default/templates/question.html @@ -146,6 +146,7 @@
    {% post_controls answer request.user %} + {% wiki_symbol request.user answer %}
    {% contributors_info answer %} diff --git a/forum/templatetags/node_tags.py b/forum/templatetags/node_tags.py index f124761..82f6b71 100644 --- a/forum/templatetags/node_tags.py +++ b/forum/templatetags/node_tags.py @@ -96,9 +96,14 @@ def post_controls(post, user): controls.append(post_control(_('delete'), reverse('delete_post', kwargs={'id': post.id}), command=True, confirm=True)) - if (not post.nis.wiki) and user.can_wikify(post): - menu.append(post_control(_('mark as community wiki'), reverse('wikify', kwargs={'id': post.id}), - command=True, confirm=True)) + if settings.WIKI_ON: + if (not post.nis.wiki) and user.can_wikify(post): + menu.append(post_control(_('mark as community wiki'), reverse('wikify', kwargs={'id': post.id}), + command=True, confirm=True)) + + elif post.nis.wiki and user.can_cancel_wiki(post): + menu.append(post_control(_('cancel community wiki'), reverse('wikify', kwargs={'id': post.id}), + command=True, confirm=True)) if post.node_type == "answer" and user.can_convert_to_comment(post): menu.append(post_control(_('convert to comment'), reverse('convert_to_comment', kwargs={'id': post.id}), diff --git a/forum/views/commands.py b/forum/views/commands.py index 40d61ec..456199d 100644 --- a/forum/views/commands.py +++ b/forum/views/commands.py @@ -361,19 +361,24 @@ def close(request, id, close): @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')) - 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': { diff --git a/forum/views/writers.py b/forum/views/writers.py index 5bddc60..99e9377 100644 --- a/forum/views/writers.py +++ b/forum/views/writers.py @@ -70,7 +70,12 @@ def ask(request): 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 @@ -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: - form = EditQuestionForm(question, revision) + form = EditQuestionForm(question, request.user, revision) 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(): - 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)) @@ -137,7 +148,7 @@ def _edit_question(request, 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, @@ -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: - form = EditAnswerForm(answer, revision) + form = EditAnswerForm(answer, request.user, revision) 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(): - 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)) @@ -175,7 +192,7 @@ def edit_answer(request, id): 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, @@ -189,7 +206,12 @@ def answer(request, id): 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 -- 2.39.5